summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-08 15:22:09 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-08 15:22:09 +0000
commit9a7801566f9c9ace5cc73c4681b857ad18dbbddf (patch)
tree302ac54f6d3a7748af89d7ae26e2a679269bbcde /llvm/lib/Support/FileOutputBuffer.cpp
parente840ee2ca208d1a999d492b553deeb1dd58593bc (diff)
downloadbcm5719-llvm-9a7801566f9c9ace5cc73c4681b857ad18dbbddf.tar.gz
bcm5719-llvm-9a7801566f9c9ace5cc73c4681b857ad18dbbddf.zip
Create files with the correct permission instead of changing it afterwards.
Not intended functionality change. llvm-svn: 185830
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp29
1 files changed, 7 insertions, 22 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index fbfda317e75..ed084faed78 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/lib/Support/FileOutputBuffer.cpp
@@ -62,11 +62,16 @@ error_code FileOutputBuffer::create(StringRef FilePath,
if (EC)
return EC;
+ unsigned Mode = sys::fs::all_read | sys::fs::all_write;
+ // If requested, make the output file executable.
+ if (Flags & F_executable)
+ Mode |= sys::fs::all_exe;
+
// Create new file in same directory but with random name.
SmallString<128> TempFilePath;
int FD;
- EC = sys::fs::createUniqueFile(Twine(FilePath) + ".tmp%%%%%%%",
- FD, TempFilePath);
+ EC = sys::fs::createUniqueFile(Twine(FilePath) + ".tmp%%%%%%%", FD,
+ TempFilePath, Mode);
if (EC)
return EC;
@@ -75,26 +80,6 @@ error_code FileOutputBuffer::create(StringRef FilePath,
if (EC)
return EC;
- // If requested, make the output file executable.
- if ( Flags & F_executable ) {
- sys::fs::file_status Stat2;
- EC = sys::fs::status(Twine(TempFilePath), Stat2);
- if (EC)
- return EC;
-
- sys::fs::perms new_perms = Stat2.permissions();
- if ( new_perms & sys::fs::owner_read )
- new_perms |= sys::fs::owner_exe;
- if ( new_perms & sys::fs::group_read )
- new_perms |= sys::fs::group_exe;
- if ( new_perms & sys::fs::others_read )
- new_perms |= sys::fs::others_exe;
- new_perms |= sys::fs::add_perms;
- EC = sys::fs::permissions(Twine(TempFilePath), new_perms);
- if (EC)
- return EC;
- }
-
Result.reset(new FileOutputBuffer(MappedFile.get(), FilePath, TempFilePath));
if (Result)
MappedFile.take();
OpenPOWER on IntegriCloud