[libc-commits] [libc] 29a631a - [libc][NFC] Add a separate flag for capturing the '+' in fopen mode string.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Thu Mar 17 08:44:14 PDT 2022


Author: Siva Chandra Reddy
Date: 2022-03-17T15:44:04Z
New Revision: 29a631a273d7e64b6eeb15e5403f8b0f4c2ab5aa

URL: https://github.com/llvm/llvm-project/commit/29a631a273d7e64b6eeb15e5403f8b0f4c2ab5aa
DIFF: https://github.com/llvm/llvm-project/commit/29a631a273d7e64b6eeb15e5403f8b0f4c2ab5aa.diff

LOG: [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

Added: 
    

Modified: 
    libc/src/__support/File/file.cpp
    libc/src/__support/File/file.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/File/file.cpp b/libc/src/__support/File/file.cpp
index 6d1d3b54f25d2..ed765f5c88321 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<ModeFlags>(OpenMode::WRITE) |
-                static_cast<ModeFlags>(OpenMode::READ));
+      flags |= static_cast<ModeFlags>(OpenMode::PLUS);
       break;
     case 'b':
       flags |= static_cast<ModeFlags>(ContentType::BINARY);

diff  --git a/libc/src/__support/File/file.h b/libc/src/__support/File/file.h
index 6bc31fa80e0fa..26849ad96b23e 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 @@ class File {
     READ = 0x1,
     WRITE = 0x2,
     APPEND = 0x4,
+    PLUS = 0x8,
   };
 
   // Denotes a file opened in binary mode (which is specified by including
@@ -97,11 +100,13 @@ class File {
 protected:
   bool write_allowed() const {
     return mode & (static_cast<ModeFlags>(OpenMode::WRITE) |
-                   static_cast<ModeFlags>(OpenMode::APPEND));
+                   static_cast<ModeFlags>(OpenMode::APPEND) |
+                   static_cast<ModeFlags>(OpenMode::PLUS));
   }
 
   bool read_allowed() const {
-    return mode & static_cast<ModeFlags>(OpenMode::READ);
+    return mode & (static_cast<ModeFlags>(OpenMode::READ) |
+                   static_cast<ModeFlags>(OpenMode::PLUS));
   }
 
 public:
@@ -185,6 +190,10 @@ class FileLock {
   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


        


More information about the libc-commits mailing list