llvm / llvm/llvm-project

[libc] Refactor FILE* File mode handling

Open
#213,374 6 comments 0 reactions 1 assignee Claimed by @obadafidii View on GitHub
libc
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.