diff options
author | Abhina Sree <Abhina.Sreeskantharajan@ibm.com> | 2024-10-21 08:20:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-21 08:20:22 -0400 |
commit | 46dc91e7d9a1b6dd0144e628519d06954b7b4e53 (patch) | |
tree | 09268f150d0a775e4bd7466176a2db515a94db3b /llvm/lib/Support/VirtualFileSystem.cpp | |
parent | c47df3e8c8f47bab8a8302757c50710e0e1c43fb (diff) | |
download | llvm-46dc91e7d9a1b6dd0144e628519d06954b7b4e53.zip llvm-46dc91e7d9a1b6dd0144e628519d06954b7b4e53.tar.gz llvm-46dc91e7d9a1b6dd0144e628519d06954b7b4e53.tar.bz2 |
[SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText parameter to getBufferForFile (#111723)
This patch adds an IsText parameter to the following getBufferForFile,
getBufferForFileImpl. We introduce a new virtual function
openFileForReadBinary which defaults to openFileForRead except in
RealFileSystem which uses the OF_None flag instead of OF_Text.
The default is set to OF_Text instead of OF_None, this change in value
does not affect any other platforms other than z/OS. Setting this
parameter correctly is required to open files on z/OS in the correct
encoding. The IsText parameter is based on the context of where we open
files, for example, in the ASTReader, HeaderMap requires that files
always be opened in binary even though they might be tagged as text.
Diffstat (limited to 'llvm/lib/Support/VirtualFileSystem.cpp')
-rw-r--r-- | llvm/lib/Support/VirtualFileSystem.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 3e79ecf..b3cdaa3 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -117,8 +117,9 @@ FileSystem::~FileSystem() = default; ErrorOr<std::unique_ptr<MemoryBuffer>> FileSystem::getBufferForFile(const llvm::Twine &Name, int64_t FileSize, - bool RequiresNullTerminator, bool IsVolatile) { - auto F = openFileForRead(Name); + bool RequiresNullTerminator, bool IsVolatile, + bool IsText) { + auto F = IsText ? openFileForRead(Name) : openFileForReadBinary(Name); if (!F) return F.getError(); @@ -279,6 +280,8 @@ public: ErrorOr<Status> status(const Twine &Path) override; ErrorOr<std::unique_ptr<File>> openFileForRead(const Twine &Path) override; + ErrorOr<std::unique_ptr<File>> + openFileForReadBinary(const Twine &Path) override; directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override; llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override; @@ -302,6 +305,17 @@ private: return Storage; } + ErrorOr<std::unique_ptr<File>> + openFileForReadWithFlags(const Twine &Name, sys::fs::OpenFlags Flags) { + SmallString<256> RealName, Storage; + Expected<file_t> FDOrErr = sys::fs::openNativeFileForRead( + adjustPath(Name, Storage), Flags, &RealName); + if (!FDOrErr) + return errorToErrorCode(FDOrErr.takeError()); + return std::unique_ptr<File>( + new RealFile(*FDOrErr, Name.str(), RealName.str())); + } + struct WorkingDirectory { // The current working directory, without symlinks resolved. (echo $PWD). SmallString<128> Specified; @@ -324,13 +338,12 @@ ErrorOr<Status> RealFileSystem::status(const Twine &Path) { ErrorOr<std::unique_ptr<File>> RealFileSystem::openFileForRead(const Twine &Name) { - SmallString<256> RealName, Storage; - Expected<file_t> FDOrErr = sys::fs::openNativeFileForRead( - adjustPath(Name, Storage), sys::fs::OF_None, &RealName); - if (!FDOrErr) - return errorToErrorCode(FDOrErr.takeError()); - return std::unique_ptr<File>( - new RealFile(*FDOrErr, Name.str(), RealName.str())); + return openFileForReadWithFlags(Name, sys::fs::OF_Text); +} + +ErrorOr<std::unique_ptr<File>> +RealFileSystem::openFileForReadBinary(const Twine &Name) { + return openFileForReadWithFlags(Name, sys::fs::OF_None); } llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory() const { |