diff options
author | Alexey Lapshin <a.v.lapshin@mail.ru> | 2021-03-04 12:51:30 +0300 |
---|---|---|
committer | Alexey Lapshin <a.v.lapshin@mail.ru> | 2021-03-22 15:41:10 +0300 |
commit | 972b6a3a3471c2a742c5c5d8ec004ff640d544c4 (patch) | |
tree | 3e6c7e5feddf2c2d47a29ae748dcbdd6193c084d /llvm/tools/llvm-objcopy/llvm-objcopy.cpp | |
parent | 9cd7c4130635a6f0c94046f529fb1ee19118bbfb (diff) | |
download | llvm-972b6a3a3471c2a742c5c5d8ec004ff640d544c4.zip llvm-972b6a3a3471c2a742c5c5d8ec004ff640d544c4.tar.gz llvm-972b6a3a3471c2a742c5c5d8ec004ff640d544c4.tar.bz2 |
[llvm-objcopy][Support] move writeToOutput helper function to Support.
writeToOutput function is useful when it is necessary to create different kinds
of streams(based on stream name) and when we need to use a temporary file
while writing(which would be renamed into the resulting file in a success case).
This patch moves the writeToStream helper into the Support library.
Differential Revision: https://reviews.llvm.org/D98426
Diffstat (limited to 'llvm/tools/llvm-objcopy/llvm-objcopy.cpp')
-rw-r--r-- | llvm/tools/llvm-objcopy/llvm-objcopy.cpp | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp index a8a570a..6c6b26b3 100644 --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp @@ -57,34 +57,6 @@ namespace llvm { namespace objcopy { -Error writeToFile(StringRef OutputFileName, - std::function<Error(raw_ostream &)> Write) { - if (OutputFileName == "-") - return Write(outs()); - - if (OutputFileName == "/dev/null") { - raw_null_ostream Out; - return Write(Out); - } - - unsigned Mode = sys::fs::all_read | sys::fs::all_write | sys::fs::all_exe; - Expected<sys::fs::TempFile> Temp = - sys::fs::TempFile::create(OutputFileName + ".temp-objcopy-%%%%%%", Mode); - if (!Temp) - return createFileError(OutputFileName, Temp.takeError()); - - raw_fd_ostream Out(Temp->FD, false); - - if (Error E = Write(Out)) { - if (Error DiscardError = Temp->discard()) - return joinErrors(std::move(E), std::move(DiscardError)); - return E; - } - Out.flush(); - - return Temp->keep(OutputFileName); -} - // The name this program was invoked as. StringRef ToolName; @@ -369,21 +341,21 @@ static Error executeObjcopy(CopyConfig &Config) { if (Config.SplitDWO.empty()) { // Apply transformations described by Config and store result into // Config.OutputFilename using specified ObjcopyFunc function. - if (Error E = writeToFile(Config.OutputFilename, ObjcopyFunc)) + if (Error E = writeToOutput(Config.OutputFilename, ObjcopyFunc)) return E; } else { Config.ExtractDWO = true; Config.StripDWO = false; // Copy .dwo tables from the Config.InputFilename into Config.SplitDWO // file using specified ObjcopyFunc function. - if (Error E = writeToFile(Config.SplitDWO, ObjcopyFunc)) + if (Error E = writeToOutput(Config.SplitDWO, ObjcopyFunc)) return E; Config.ExtractDWO = false; Config.StripDWO = true; // Apply transformations described by Config, remove .dwo tables and // store result into Config.OutputFilename using specified ObjcopyFunc // function. - if (Error E = writeToFile(Config.OutputFilename, ObjcopyFunc)) + if (Error E = writeToOutput(Config.OutputFilename, ObjcopyFunc)) return E; } } |