From 29a631a273d7e64b6eeb15e5403f8b0f4c2ab5aa Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Thu, 17 Mar 2022 08:39:58 +0000 Subject: [PATCH] [libc][NFC] Add a separate flag for capturing the '+' in fopen mode string. Having a separate flag helps in setting up proper flags when implementing, say the Linux specialization of File. Along the way, a signature for a function which is to be used to open files has been added. The implementation of the function is to be included in platform specializations. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D121889 --- libc/src/__support/File/file.cpp | 3 +-- libc/src/__support/File/file.h | 13 +++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libc/src/__support/File/file.cpp b/libc/src/__support/File/file.cpp index 6d1d3b5..ed765f5 100644 --- a/libc/src/__support/File/file.cpp +++ b/libc/src/__support/File/file.cpp @@ -215,8 +215,7 @@ File::ModeFlags File::mode_flags(const char *mode) { ++main_mode_count; break; case '+': - flags |= (static_cast(OpenMode::WRITE) | - static_cast(OpenMode::READ)); + flags |= static_cast(OpenMode::PLUS); break; case 'b': flags |= static_cast(ContentType::BINARY); diff --git a/libc/src/__support/File/file.h b/libc/src/__support/File/file.h index 6bc31fa..26849ad 100644 --- a/libc/src/__support/File/file.h +++ b/libc/src/__support/File/file.h @@ -21,6 +21,8 @@ namespace __llvm_libc { // suitable for their platform. class File { public: + static constexpr size_t DEFAULT_BUFFER_SIZE = 1024; + using LockFunc = void(File *); using UnlockFunc = void(File *); @@ -41,6 +43,7 @@ public: READ = 0x1, WRITE = 0x2, APPEND = 0x4, + PLUS = 0x8, }; // Denotes a file opened in binary mode (which is specified by including @@ -97,11 +100,13 @@ private: protected: bool write_allowed() const { return mode & (static_cast(OpenMode::WRITE) | - static_cast(OpenMode::APPEND)); + static_cast(OpenMode::APPEND) | + static_cast(OpenMode::PLUS)); } bool read_allowed() const { - return mode & static_cast(OpenMode::READ); + return mode & (static_cast(OpenMode::READ) | + static_cast(OpenMode::PLUS)); } public: @@ -185,6 +190,10 @@ public: FileLock(FileLock &&) = delete; }; +// The implementaiton of this function is provided by the platfrom_file +// library. +File *openfile(const char *path, const char *mode); + } // namespace __llvm_libc #endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_FILE_H -- 2.7.4