From bf1138b98f692e1ff6761ba71809e2dcfe3c62e9 Mon Sep 17 00:00:00 2001 From: Tony Parker Date: Mon, 18 Mar 2024 16:13:01 -0700 Subject: [PATCH] Use a CShim to avoid an unescapable warning about using mktemp --- .../Data/Data+Writing.swift | 2 +- Sources/_CShims/data_shims.c | 21 +++++++++++++++++++ Sources/_CShims/include/data_shims.h | 20 ++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Sources/_CShims/data_shims.c create mode 100644 Sources/_CShims/include/data_shims.h diff --git a/Sources/FoundationEssentials/Data/Data+Writing.swift b/Sources/FoundationEssentials/Data/Data+Writing.swift index 28857b068..c8847f9fd 100644 --- a/Sources/FoundationEssentials/Data/Data+Writing.swift +++ b/Sources/FoundationEssentials/Data/Data+Writing.swift @@ -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 diff --git a/Sources/_CShims/data_shims.c b/Sources/_CShims/data_shims.c new file mode 100644 index 000000000..b1ea205ab --- /dev/null +++ b/Sources/_CShims/data_shims.c @@ -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 +#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 +} diff --git a/Sources/_CShims/include/data_shims.h b/Sources/_CShims/include/data_shims.h new file mode 100644 index 000000000..881f1892a --- /dev/null +++ b/Sources/_CShims/include/data_shims.h @@ -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