From b6148ed72cfdc6a2acf584631472cd1257ed1bb6 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Fri, 11 May 2012 00:07:44 +0000 Subject: [PATCH] Allow unique_file to take a mode for file permissions, but default to user only read/write. Part of rdar://11325849 llvm-svn: 156591 --- llvm/include/llvm/Support/FileSystem.h | 4 ++-- llvm/lib/Support/Unix/PathV2.inc | 7 ++++--- llvm/lib/Support/Windows/PathV2.inc | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h index 3fd5301d0324..55565cd639a1 100644 --- a/llvm/include/llvm/Support/FileSystem.h +++ b/llvm/include/llvm/Support/FileSystem.h @@ -422,8 +422,8 @@ error_code status_known(const Twine &path, bool &result); /// @results errc::success if result_{fd,path} have been successfully set, /// otherwise a platform specific error_code. error_code unique_file(const Twine &model, int &result_fd, - SmallVectorImpl &result_path, - bool makeAbsolute = true); + SmallVectorImpl &result_path, + bool makeAbsolute = true, unsigned mode = 0600); /// @brief Canonicalize path. /// diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc index 3446c28e06d4..a7007cd6974b 100644 --- a/llvm/lib/Support/Unix/PathV2.inc +++ b/llvm/lib/Support/Unix/PathV2.inc @@ -347,9 +347,10 @@ error_code status(const Twine &path, file_status &result) { return error_code::success(); } +// Since this is most often used for temporary files, mode defaults to 0600. error_code unique_file(const Twine &model, int &result_fd, - SmallVectorImpl &result_path, - bool makeAbsolute) { + SmallVectorImpl &result_path, + bool makeAbsolute, unsigned mode) { SmallString<128> Model; model.toVector(Model); // Null terminate. @@ -379,7 +380,7 @@ retry_random_path: // Try to open + create the file. rety_open_create: - int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); + int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode); if (RandomFD == -1) { // If the file existed, try again, otherwise, error. if (errno == errc::file_exists) diff --git a/llvm/lib/Support/Windows/PathV2.inc b/llvm/lib/Support/Windows/PathV2.inc index 66b8d84f852e..4868b184b8f9 100644 --- a/llvm/lib/Support/Windows/PathV2.inc +++ b/llvm/lib/Support/Windows/PathV2.inc @@ -497,9 +497,11 @@ handle_status_error: return error_code::success(); } +// FIXME: mode should be used here and default to user r/w only, +// it currently comes in as a UNIX mode. error_code unique_file(const Twine &model, int &result_fd, - SmallVectorImpl &result_path, - bool makeAbsolute) { + SmallVectorImpl &result_path, + bool makeAbsolute, unsigned mode) { // Use result_path as temp storage. result_path.set_size(0); StringRef m = model.toStringRef(result_path);