llvm.org GIT mirror llvm / 61aef8b
Allow unique_file to take a mode for file permissions, but default to user only read/write. Part of rdar://11325849 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156591 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 8 years ago
3 changed file(s) with 10 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
421421 /// @results errc::success if result_{fd,path} have been successfully set,
422422 /// otherwise a platform specific error_code.
423423 error_code unique_file(const Twine &model, int &result_fd,
424 SmallVectorImpl &result_path,
425 bool makeAbsolute = true);
424 SmallVectorImpl &result_path,
425 bool makeAbsolute = true, unsigned mode = 0600);
426426
427427 /// @brief Canonicalize path.
428428 ///
346346 return error_code::success();
347347 }
348348
349 // Since this is most often used for temporary files, mode defaults to 0600.
349350 error_code unique_file(const Twine &model, int &result_fd,
350 SmallVectorImpl &result_path,
351 bool makeAbsolute) {
351 SmallVectorImpl &result_path,
352 bool makeAbsolute, unsigned mode) {
352353 SmallString<128> Model;
353354 model.toVector(Model);
354355 // Null terminate.
378379
379380 // Try to open + create the file.
380381 rety_open_create:
381 int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
382 int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode);
382383 if (RandomFD == -1) {
383384 // If the file existed, try again, otherwise, error.
384385 if (errno == errc::file_exists)
496496 return error_code::success();
497497 }
498498
499 // FIXME: mode should be used here and default to user r/w only,
500 // it currently comes in as a UNIX mode.
499501 error_code unique_file(const Twine &model, int &result_fd,
500 SmallVectorImpl &result_path,
501 bool makeAbsolute) {
502 SmallVectorImpl &result_path,
503 bool makeAbsolute, unsigned mode) {
502504 // Use result_path as temp storage.
503505 result_path.set_size(0);
504506 StringRef m = model.toStringRef(result_path);