From edf3b277a5f2ebe144827ed47463c22743cac5f9 Mon Sep 17 00:00:00 2001 From: Abhina Sree Date: Thu, 19 Sep 2024 14:30:10 -0400 Subject: [SystemZ][z/OS] Propagate IsText parameter to open text files as text (#107906) This patch adds an IsText parameter to the following functions openFileForRead, getBufferForFile, getBufferForFileImpl and determines whether a file is text by querying the file tag on z/OS. 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. --- llvm/lib/Support/VirtualFileSystem.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'llvm/lib/Support/VirtualFileSystem.cpp') diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 928c0b5a24ed..ceca65b46e48 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -117,8 +117,9 @@ FileSystem::~FileSystem() = default; ErrorOr> 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 = openFileForRead(Name, IsText); if (!F) return F.getError(); @@ -278,7 +279,8 @@ public: } ErrorOr status(const Twine &Path) override; - ErrorOr> openFileForRead(const Twine &Path) override; + ErrorOr> openFileForRead(const Twine &Path, + bool IsText = true) override; directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override; llvm::ErrorOr getCurrentWorkingDirectory() const override; @@ -323,10 +325,11 @@ ErrorOr RealFileSystem::status(const Twine &Path) { } ErrorOr> -RealFileSystem::openFileForRead(const Twine &Name) { +RealFileSystem::openFileForRead(const Twine &Name, bool IsText) { SmallString<256> RealName, Storage; Expected FDOrErr = sys::fs::openNativeFileForRead( - adjustPath(Name, Storage), sys::fs::OF_None, &RealName); + adjustPath(Name, Storage), IsText ? sys::fs::OF_Text : sys::fs::OF_None, + &RealName); if (!FDOrErr) return errorToErrorCode(FDOrErr.takeError()); return std::unique_ptr( @@ -458,10 +461,10 @@ bool OverlayFileSystem::exists(const Twine &Path) { } ErrorOr> -OverlayFileSystem::openFileForRead(const llvm::Twine &Path) { +OverlayFileSystem::openFileForRead(const llvm::Twine &Path, bool IsText) { // FIXME: handle symlinks that cross file systems for (iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) { - auto Result = (*I)->openFileForRead(Path); + auto Result = (*I)->openFileForRead(Path, IsText); if (Result || Result.getError() != llvm::errc::no_such_file_or_directory) return Result; } @@ -1073,7 +1076,7 @@ llvm::ErrorOr InMemoryFileSystem::status(const Twine &Path) { } llvm::ErrorOr> -InMemoryFileSystem::openFileForRead(const Twine &Path) { +InMemoryFileSystem::openFileForRead(const Twine &Path, bool IsText) { auto Node = lookupNode(Path,/*FollowFinalSymlink=*/true); if (!Node) return Node.getError(); @@ -2537,7 +2540,7 @@ File::getWithPath(ErrorOr> Result, const Twine &P) { } ErrorOr> -RedirectingFileSystem::openFileForRead(const Twine &OriginalPath) { +RedirectingFileSystem::openFileForRead(const Twine &OriginalPath, bool IsText) { SmallString<256> Path; OriginalPath.toVector(Path); -- cgit v1.2.3