X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FFileOutputBuffer.cpp;h=ed084faed789e2d11c629ff6dfd1a6cafaacfba8;hb=fc699872e35ec794d7373680be6f1946fe8e9ca6;hp=cd430f218bc367ea23e9b4f0ebf8bc8be75e7b04;hpb=6bc86018d189e9ab62d30ef8190bac961dd22248;p=oota-llvm.git diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index cd430f218bc..ed084faed78 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -62,39 +62,24 @@ 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::unique_file(Twine(FilePath) + ".tmp%%%%%%%", - FD, TempFilePath, false, 0644); + EC = sys::fs::createUniqueFile(Twine(FilePath) + ".tmp%%%%%%%", FD, + TempFilePath, Mode); if (EC) return EC; - OwningPtr MappedFile( - new mapped_file_region(FD, mapped_file_region::readwrite, Size, 0, EC)); + OwningPtr MappedFile(new mapped_file_region( + FD, true, mapped_file_region::readwrite, Size, 0, EC)); 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();