[libc] Refactor FILE* File mode handling
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Currently the file struct handles its mode flags in the C style: https://github.com/llvm/llvm-project/blob/38d27329ec681563090a69b1937313ccb311f46e/libc/src/__support/File/file.h#L77
Specifically, there's a bit field in the class that represents the whether the file can read/write/append/etc. There are helper functions for "read_allowed" and "write_allowed" but when a linux file is being opened it's currently masking the flags manually: https://github.com/llvm/llvm-project/blob/38d27329ec681563090a69b1937313ccb311f46e/libc/src/__support/File/linux/file.cpp#L71
Ideally there would be a class that abstracts this away. `File` would have a `FileMode` member with methods for `write_allowed`, `read_allowed`, `append_allowed`, `binary_format`, etc. This would make the `if` conditions in `linux_file` more understandable and readable.
Contributor guide
Assessment
This issue has not been assessed yet.