Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a CShim to avoid an unescapable warning about using mktemp #495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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