llvm.org GIT mirror llvm / ac69459
Replace the F_Binary flag with a F_Text one. After this I will set the default back to F_None. The advantage is that before this patch forgetting to set F_Binary would corrupt a file on windows. Forgetting to set F_Text produces one that cannot be read in notepad, which is a better failure mode :-) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202052 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
35 changed file(s) with 50 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
107107 if (OutputFilename != "-") {
108108 std::string ErrInfo;
109109 out = new raw_fd_ostream(OutputFilename.c_str(), ErrInfo,
110 sys::fs::F_Binary);
110 sys::fs::F_None);
111111 }
112112 }
113113
6868
6969 errs() << "Writing '" << Filename << "'...";
7070
71 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_None);
71 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
7272 std::string GraphName = DOTGraphTraits::getGraphName(Graph);
7373 std::string Title = GraphName + " for '" + F.getName().str() + "' function";
7474
131131
132132 errs() << "Writing '" << Filename << "'...";
133133
134 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_None);
134 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
135135 std::string Title = DOTGraphTraits::getGraphName(Graph);
136136
137137 if (ErrorInfo.empty())
577577 /// with F_Excl.
578578 F_Append = 2,
579579
580 /// F_Binary - The file should be opened in binary mode on platforms that
581 /// make this distinction.
582 F_Binary = 4,
580 /// The file should be opened in text mode on platforms that make this
581 /// distinction.
582 F_Text = 4,
583583
584584 /// Open the file for read and write.
585585 F_RW = 8
7979 errs() << "Writing '" << Filename << "'...";
8080
8181 std::string ErrorInfo;
82 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_None);
82 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
8383
8484 if (ErrorInfo.empty())
8585 WriteGraph(File, (const Function*)&F);
113113 errs() << "Writing '" << Filename << "'...";
114114
115115 std::string ErrorInfo;
116 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_None);
116 raw_fd_ostream File(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
117117
118118 if (ErrorInfo.empty())
119119 WriteGraph(File, (const Function*)&F, true);
1717
1818 int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
1919 std::string ErrorInfo;
20 raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_Binary);
20 raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_None);
2121
2222 if (!ErrorInfo.empty())
2323 return -1;
275275 raw_ostream *OutFile = 0;
276276 if (OutFileName) {
277277 std::string ErrorInfo;
278 OutFile = new raw_fd_ostream(OutFileName, ErrorInfo, sys::fs::F_Append);
278 OutFile = new raw_fd_ostream(OutFileName, ErrorInfo,
279 sys::fs::F_Append | sys::fs::F_Text);
279280 if (!ErrorInfo.empty()) {
280281 errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n';
281282 exit(1);
594594 rs << round;
595595 std::string graphFileName(fqn + "." + rs.str() + ".pbqpgraph");
596596 std::string tmp;
597 raw_fd_ostream os(graphFileName.c_str(), tmp, sys::fs::F_None);
597 raw_fd_ostream os(graphFileName.c_str(), tmp, sys::fs::F_Text);
598598 DEBUG(dbgs() << "Dumping graph for round " << round << " to \""
599599 << graphFileName << "\"\n");
600600 problem->getGraph().dump(os);
129129 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
130130 char **ErrorMessage) {
131131 std::string error;
132 raw_fd_ostream dest(Filename, error, sys::fs::F_None);
132 raw_fd_ostream dest(Filename, error, sys::fs::F_Text);
133133 if (!error.empty()) {
134134 *ErrorMessage = strdup(error.c_str());
135135 return true;
481481 std::string CoveragePath = mangleCoveragePath(Filename,
482482 Options.PreservePaths);
483483 std::string ErrorInfo;
484 raw_fd_ostream OS(CoveragePath.c_str(), ErrorInfo, sys::fs::F_None);
484 raw_fd_ostream OS(CoveragePath.c_str(), ErrorInfo, sys::fs::F_Text);
485485 if (!ErrorInfo.empty())
486486 errs() << ErrorInfo << "\n";
487487
190190
191191 // create output file
192192 std::string ErrInfo;
193 tool_output_file Out(path, ErrInfo, sys::fs::F_Binary);
193 tool_output_file Out(path, ErrInfo, sys::fs::F_None);
194194 if (!ErrInfo.empty()) {
195195 errMsg = "could not open bitcode file for writing: ";
196196 errMsg += path;
633633 raw_ostream *OS = getContext().getSecureLog();
634634 if (OS == NULL) {
635635 std::string Err;
636 OS = new raw_fd_ostream(SecureLogFile, Err, sys::fs::F_Append);
636 OS = new raw_fd_ostream(SecureLogFile, Err,
637 sys::fs::F_Append | sys::fs::F_Text);
637638 if (!Err.empty()) {
638639 delete OS;
639640 return Error(IDLoc, Twine("can't open secure log file: ") +
200200 // Try to open + create the file.
201201 switch (Type) {
202202 case FS_File: {
203 if (error_code EC = sys::fs::openFileForWrite(
204 Twine(ResultPath.begin()), ResultFD,
205 sys::fs::F_RW | sys::fs::F_Excl | sys::fs::F_Binary, Mode)) {
203 if (error_code EC =
204 sys::fs::openFileForWrite(Twine(ResultPath.begin()), ResultFD,
205 sys::fs::F_RW | sys::fs::F_Excl, Mode)) {
206206 if (EC == errc::file_exists)
207207 goto retry_random_path;
208208 return EC;
6565 // compensate for this, the test-suite Makefiles have code to delete the
6666 // info output file before running commands which write to it.
6767 std::string Error;
68 raw_ostream *Result =
69 new raw_fd_ostream(OutputFilename.c_str(), Error, sys::fs::F_Append);
68 raw_ostream *Result = new raw_fd_ostream(
69 OutputFilename.c_str(), Error, sys::fs::F_Append | sys::fs::F_Text);
7070 if (Error.empty())
7171 return Result;
7272
875875 if (Flags & F_Append)
876876 OpenFlags |= _O_APPEND;
877877
878 if (!(Flags & F_Binary))
878 if (Flags & F_Text)
879879 OpenFlags |= _O_TEXT;
880880
881881 int FD = ::_open_osfhandle(intptr_t(H), OpenFlags);
442442 FD = STDOUT_FILENO;
443443 // If user requested binary then put stdout into binary mode if
444444 // possible.
445 if (Flags & sys::fs::F_Binary)
445 if (!(Flags & sys::fs::F_Text))
446446 sys::ChangeStdoutToBinary();
447447 // Close stdout when we're done, to detect any output errors.
448448 ShouldClose = true;
5656 return 1;
5757 }
5858 std::string Error;
59 tool_output_file DepOut(DependFilename.c_str(), Error, sys::fs::F_None);
59 tool_output_file DepOut(DependFilename.c_str(), Error, sys::fs::F_Text);
6060 if (!Error.empty()) {
6161 errs() << argv0 << ": error opening " << DependFilename
6262 << ":" << Error << "\n";
102102 return 1;
103103
104104 std::string Error;
105 tool_output_file Out(OutputFilename.c_str(), Error, sys::fs::F_None);
105 tool_output_file Out(OutputFilename.c_str(), Error, sys::fs::F_Text);
106106 if (!Error.empty()) {
107107 errs() << argv0 << ": error opening " << OutputFilename
108108 << ":" << Error << "\n";
237237 LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
238238 char* Filename, LLVMCodeGenFileType codegen, char** ErrorMessage) {
239239 std::string error;
240 raw_fd_ostream dest(Filename, error, sys::fs::F_Binary);
240 raw_fd_ostream dest(Filename, error, sys::fs::F_None);
241241 if (!error.empty()) {
242242 *ErrorMessage = strdup(error.c_str());
243243 return true;
527527
528528 if (!fd) {
529529 std::string Path = getPath();
530 Out.reset(new raw_fd_ostream(Path.c_str(), error, sys::fs::F_None));
530 Out.reset(new raw_fd_ostream(Path.c_str(), error, sys::fs::F_Text));
531531 DEBUG(dbgs() << "WRITING debug bitcode from Module " << M << " to file "
532532 << Path << "\n");
533533 } else {
465465 DICompileUnit CU(CU_Nodes->getOperand(i));
466466 std::string ErrorInfo;
467467 raw_fd_ostream out(mangleName(CU, "gcno").c_str(), ErrorInfo,
468 sys::fs::F_Binary);
468 sys::fs::F_None);
469469 std::string EdgeDestinations;
470470
471471 DIArray SPs = CU.getSubprograms();
7070 bool BugDriver::writeProgramToFile(const std::string &Filename,
7171 const Module *M) const {
7272 std::string ErrInfo;
73 tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_Binary);
73 tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_None);
7474 if (ErrInfo.empty())
7575 return writeProgramToFileAux(Out, M);
7676 return true;
149149 // Open the file.
150150 std::string error;
151151 sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
152 if (Binary)
153 OpenFlags |= sys::fs::F_Binary;
152 if (!Binary)
153 OpenFlags |= sys::fs::F_Text;
154154 tool_output_file *FDOut = new tool_output_file(OutputFilename.c_str(), error,
155155 OpenFlags);
156156 if (!error.empty()) {
272272 sys::path::remove_filename(dir);
273273 sys::fs::create_directories(Twine(dir));
274274 }
275 raw_fd_ostream outfile(CacheName.c_str(), errStr, sys::fs::F_Binary);
275 raw_fd_ostream outfile(CacheName.c_str(), errStr, sys::fs::F_None);
276276 outfile.write(Obj->getBufferStart(), Obj->getBufferSize());
277277 outfile.close();
278278 }
321321
322322 int FD;
323323 failIfError(
324 sys::fs::openFileForWrite(Storage.c_str(), FD, sys::fs::F_Binary, Mode),
324 sys::fs::openFileForWrite(Storage.c_str(), FD, sys::fs::F_None, Mode),
325325 Storage.c_str());
326326
327327 {
6969
7070 std::string ErrorInfo;
7171 OwningPtr Out(new tool_output_file(
72 OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary));
72 OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
7373 if (!ErrorInfo.empty()) {
7474 errs() << ErrorInfo << '\n';
7575 exit(1);
171171
172172 std::string ErrorInfo;
173173 OwningPtr Out(new tool_output_file(
174 OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary));
174 OutputFilename.c_str(), ErrorInfo, sys::fs::F_None));
175175 if (!ErrorInfo.empty()) {
176176 errs() << ErrorInfo << '\n';
177177 return 1;
264264 Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
265265
266266 std::string ErrorInfo;
267 tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary);
267 tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
268268 if (!ErrorInfo.empty()) {
269269 errs() << ErrorInfo << '\n';
270270 return 1;
109109 if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
110110
111111 std::string ErrorInfo;
112 tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary);
112 tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
113113 if (!ErrorInfo.empty()) {
114114 errs() << ErrorInfo << '\n';
115115 return 1;
141141 }
142142
143143 raw_fd_ostream FileStream(OutputFilename.c_str(), ErrorInfo,
144 sys::fs::F_Binary);
144 sys::fs::F_None);
145145 if (!ErrorInfo.empty()) {
146146 errs() << argv[0] << ": error opening the file '" << OutputFilename
147147 << "': " << ErrorInfo << "\n";
210210
211211 std::string Err;
212212 tool_output_file *Out =
213 new tool_output_file(OutputFilename.c_str(), Err, sys::fs::F_Binary);
213 new tool_output_file(OutputFilename.c_str(), Err, sys::fs::F_None);
214214 if (!Err.empty()) {
215215 errs() << Err << '\n';
216216 delete Out;
191191 MCInstPrinter *IP) {
192192 // Start a new dot file.
193193 std::string Error;
194 raw_fd_ostream Out(FileName, Error, sys::fs::F_None);
194 raw_fd_ostream Out(FileName, Error, sys::fs::F_Text);
195195 if (!Error.empty()) {
196196 errs() << "llvm-objdump: warning: " << Error << '\n';
197197 return;
372372 }
373373 if (!YAMLCFG.empty()) {
374374 std::string Error;
375 raw_fd_ostream YAMLOut(YAMLCFG.c_str(), Error, sys::fs::F_None);
375 raw_fd_ostream YAMLOut(YAMLCFG.c_str(), Error, sys::fs::F_Text);
376376 if (!Error.empty()) {
377377 errs() << ToolName << ": warning: " << Error << '\n';
378378 return;
111111 OutputFilename = "-";
112112
113113 std::string ErrorInfo;
114 raw_fd_ostream Output(OutputFilename.data(), ErrorInfo, sys::fs::F_None);
114 raw_fd_ostream Output(OutputFilename.data(), ErrorInfo, sys::fs::F_Text);
115115 if (!ErrorInfo.empty())
116116 exitWithError(ErrorInfo, OutputFilename);
117117
704704
705705 std::string ErrorInfo;
706706 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
707 sys::fs::F_Binary));
707 sys::fs::F_None));
708708 if (!ErrorInfo.empty()) {
709709 errs() << ErrorInfo << '\n';
710710 return 1;
380380
381381 std::string ErrorInfo;
382382 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
383 sys::fs::F_Binary));
383 sys::fs::F_None));
384384 if (!ErrorInfo.empty()) {
385385 errs() << ErrorInfo << '\n';
386386 return 1;
466466
467467 std::string ErrorInfo;
468468 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
469 sys::fs::F_Binary));
469 sys::fs::F_None));
470470 if (!ErrorInfo.empty()) {
471471 errs() << ErrorInfo << '\n';
472472 return 1;
500500 SmallString<128> file_pathname(TestDirectory);
501501 path::append(file_pathname, i->filename);
502502 std::string ErrMsg;
503 raw_fd_ostream file(file_pathname.c_str(), ErrMsg, sys::fs::F_Binary);
503 raw_fd_ostream file(file_pathname.c_str(), ErrMsg, sys::fs::F_None);
504504 ASSERT_FALSE(file.has_error());
505505 StringRef magic(i->magic_str, i->magic_str_len);
506506 file << magic;
520520 path::append(FilePathname, "test");
521521
522522 {
523 raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_None);
523 raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_Text);
524524 EXPECT_EQ(ErrMsg, "");
525525 File << '\n';
526526 }
531531 }
532532
533533 {
534 raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_Binary);
534 raw_fd_ostream File(FilePathname.c_str(), ErrMsg, sys::fs::F_None);
535535 EXPECT_EQ(ErrMsg, "");
536536 File << '\n';
537537 }
7070 << "', contents changed.\n";
7171 std::string ErrorStr;
7272 tool_output_file OutStream(OutputFilename.c_str(), ErrorStr,
73 sys::fs::F_Binary);
73 sys::fs::F_None);
7474 if (!ErrorStr.empty()) {
7575 errs() << argv[0] << ": Unable to write output '"
7676 << OutputFilename << "': " << ErrorStr << '\n';