Skip to content

Commit

Permalink
Use a CShim to avoid an unescapable warning about using mktemp
Browse files Browse the repository at this point in the history
  • Loading branch information
parkera committed Jun 13, 2024
1 parent 142f409 commit bf1138b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/Data/Data+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private func createTemporaryFile(at destinationPath: String, inPath: PathOrURL,
}
let flags: CInt = _O_BINARY | _O_CREAT | _O_EXCL | _O_RDWR
#else
guard mktemp(templateFileSystemRep) != nil else {
guard _datashims_mktemp(templateFileSystemRep) != nil else {
throw CocoaError.errorWithFilePath(inPath, errno: errno, reading: false)
}
let flags: CInt = O_CREAT | O_EXCL | O_RDWR
Expand Down
21 changes: 21 additions & 0 deletions Sources/_CShims/data_shims.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include <stdlib.h>
#include "data_shims.h"

INTERNAL char *_datashims_mktemp(char *arg) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
return mktemp(arg);
#pragma GCC diagnostic pop
}
20 changes: 20 additions & 0 deletions Sources/_CShims/include/data_shims.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef CSHIMS_DATA_H
#define CSHIMS_DATA_H

#include "_CShimsMacros.h"

INTERNAL char *_datashims_mktemp(char *arg);

#endif

0 comments on commit bf1138b

Please sign in to comment.