diff options
author | Abhina Sreeskantharajan <Abhina.Sreeskantharajan@ibm.com> | 2021-03-19 08:09:01 -0400 |
---|---|---|
committer | Abhina Sreeskantharajan <Abhina.Sreeskantharajan@ibm.com> | 2021-03-19 08:09:57 -0400 |
commit | 4f750f6ebc412869ce6bb28331313a9c9a9d9af7 (patch) | |
tree | 537fc11c22134d3d9700fffe1d2e030d8a470d9a /llvm/lib/Support/MemoryBuffer.cpp | |
parent | c2313a45307e807a6ee08d3b32cf6e4d099849a6 (diff) | |
download | llvm-4f750f6ebc412869ce6bb28331313a9c9a9d9af7.zip llvm-4f750f6ebc412869ce6bb28331313a9c9a9d9af7.tar.gz llvm-4f750f6ebc412869ce6bb28331313a9c9a9d9af7.tar.bz2 |
[SystemZ][z/OS] Distinguish between text and binary files on z/OS
This patch consists of the initial changes to help distinguish between text and binary content correctly on z/OS. I would like to get feedback from Windows users on setting OF_None for all ToolOutputFiles. This seems to have been done as an optimization to prevent CRLF translation on Windows in the past.
Reviewed By: zibi
Differential Revision: https://reviews.llvm.org/D97785
Diffstat (limited to 'llvm/lib/Support/MemoryBuffer.cpp')
-rw-r--r-- | llvm/lib/Support/MemoryBuffer.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp index a05b7d8..955bf11 100644 --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -106,7 +106,8 @@ public: template <typename MB> static ErrorOr<std::unique_ptr<MB>> getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, - uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile); + uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, + bool IsText); std::unique_ptr<MemoryBuffer> MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName, @@ -141,20 +142,20 @@ MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) { ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getFileOrSTDIN(const Twine &Filename, int64_t FileSize, - bool RequiresNullTerminator) { + bool RequiresNullTerminator, bool IsText) { SmallString<256> NameBuf; StringRef NameRef = Filename.toStringRef(NameBuf); if (NameRef == "-") return getSTDIN(); - return getFile(Filename, FileSize, RequiresNullTerminator); + return getFile(Filename, FileSize, RequiresNullTerminator, false, IsText); } ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize, uint64_t Offset, bool IsVolatile) { return getFileAux<MemoryBuffer>(FilePath, -1, MapSize, Offset, false, - IsVolatile); + IsVolatile, false); } //===----------------------------------------------------------------------===// @@ -240,12 +241,12 @@ getMemoryBufferForStream(sys::fs::file_t FD, const Twine &BufferName) { return getMemBufferCopyImpl(Buffer, BufferName); } - ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, - bool RequiresNullTerminator, bool IsVolatile) { + bool RequiresNullTerminator, bool IsVolatile, + bool IsText) { return getFileAux<MemoryBuffer>(Filename, FileSize, FileSize, 0, - RequiresNullTerminator, IsVolatile); + RequiresNullTerminator, IsVolatile, IsText); } template <typename MB> @@ -257,9 +258,10 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, template <typename MB> static ErrorOr<std::unique_ptr<MB>> getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, - uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile) { - Expected<sys::fs::file_t> FDOrErr = - sys::fs::openNativeFileForRead(Filename, sys::fs::OF_None); + uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, + bool IsText) { + Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead( + Filename, IsText ? sys::fs::OF_Text : sys::fs::OF_None); if (!FDOrErr) return errorToErrorCode(FDOrErr.takeError()); sys::fs::file_t FD = *FDOrErr; @@ -274,14 +276,14 @@ WritableMemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, bool IsVolatile) { return getFileAux<WritableMemoryBuffer>(Filename, FileSize, FileSize, 0, /*RequiresNullTerminator*/ false, - IsVolatile); + IsVolatile, false); } ErrorOr<std::unique_ptr<WritableMemoryBuffer>> WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile) { return getFileAux<WritableMemoryBuffer>(Filename, -1, MapSize, Offset, false, - IsVolatile); + IsVolatile, false); } std::unique_ptr<WritableMemoryBuffer> |