Skip to content

Commit 29a631a

Browse files
author
Siva Chandra Reddy
committed
[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
1 parent 295172e commit 29a631a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

libc/src/__support/File/file.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ File::ModeFlags File::mode_flags(const char *mode) {
215215
++main_mode_count;
216216
break;
217217
case '+':
218-
flags |= (static_cast<ModeFlags>(OpenMode::WRITE) |
219-
static_cast<ModeFlags>(OpenMode::READ));
218+
flags |= static_cast<ModeFlags>(OpenMode::PLUS);
220219
break;
221220
case 'b':
222221
flags |= static_cast<ModeFlags>(ContentType::BINARY);

libc/src/__support/File/file.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace __llvm_libc {
2121
// suitable for their platform.
2222
class File {
2323
public:
24+
static constexpr size_t DEFAULT_BUFFER_SIZE = 1024;
25+
2426
using LockFunc = void(File *);
2527
using UnlockFunc = void(File *);
2628

@@ -41,6 +43,7 @@ class File {
4143
READ = 0x1,
4244
WRITE = 0x2,
4345
APPEND = 0x4,
46+
PLUS = 0x8,
4447
};
4548

4649
// Denotes a file opened in binary mode (which is specified by including
@@ -97,11 +100,13 @@ class File {
97100
protected:
98101
bool write_allowed() const {
99102
return mode & (static_cast<ModeFlags>(OpenMode::WRITE) |
100-
static_cast<ModeFlags>(OpenMode::APPEND));
103+
static_cast<ModeFlags>(OpenMode::APPEND) |
104+
static_cast<ModeFlags>(OpenMode::PLUS));
101105
}
102106

103107
bool read_allowed() const {
104-
return mode & static_cast<ModeFlags>(OpenMode::READ);
108+
return mode & (static_cast<ModeFlags>(OpenMode::READ) |
109+
static_cast<ModeFlags>(OpenMode::PLUS));
105110
}
106111

107112
public:
@@ -185,6 +190,10 @@ class FileLock {
185190
FileLock(FileLock &&) = delete;
186191
};
187192

193+
// The implementaiton of this function is provided by the platfrom_file
194+
// library.
195+
File *openfile(const char *path, const char *mode);
196+
188197
} // namespace __llvm_libc
189198

190199
#endif // LLVM_LIBC_SRC_SUPPORT_OSUTIL_FILE_H

0 commit comments

Comments
 (0)