Skip to content

Commit 5aedca6

Browse files
committed
Use a CShim to avoid an unescapable warning about using mktemp
1 parent a04d992 commit 5aedca6

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Sources/FoundationEssentials/Data/Data+Writing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private func createTemporaryFile(at destinationPath: String, inPath: PathOrURL,
158158

159159
// The warning diligently tells us we shouldn't be using mktemp() because blindly opening the returned path opens us up to a TOCTOU race. However, in this case, we're being careful by doing O_CREAT|O_EXCL and repeating, just like the implementation of mkstemp.
160160
// Furthermore, we can't compatibly switch to mkstemp() until we have the ability to set fchmod correctly, which requires the ability to query the current umask, which we don't have. (22033100)
161-
guard mktemp(templateFileSystemRep) != nil else {
161+
guard _datashims_mktemp(templateFileSystemRep) != nil else {
162162
throw CocoaError.errorWithFilePath(inPath, errno: errno, reading: false)
163163
}
164164

Sources/_CShims/data_shims.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <stdlib.h>
14+
#include "data_shims.h"
15+
16+
INTERNAL char *_datashims_mktemp(char *arg) {
17+
#pragma GCC diagnostic push
18+
#pragma GCC diagnostic ignored "-Wdeprecated"
19+
return mktemp(arg);
20+
#pragma GCC diagnostic pop
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef CSHIMS_DATA_H
14+
#define CSHIMS_DATA_H
15+
16+
#include "_CShimsMacros.h"
17+
18+
INTERNAL char *_datashims_mktemp(char *arg);
19+
20+
#endif

0 commit comments

Comments
 (0)