[libc-commits] [libc] [libc] Implement freopen (PR #207837)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Wed Jul 8 07:50:48 PDT 2026


================
@@ -128,9 +135,9 @@ ErrorOr<LinuxFile *> create_file_from_fd(int fd, const char *mode) {
 
   using OpenMode = File::OpenMode;
   if (((fd_flags & O_ACCMODE) == O_RDONLY &&
-       !(modeflags & static_cast<ModeFlags>(OpenMode::READ))) ||
+       (modeflags & static_cast<ModeFlags>(OpenMode::WRITE))) ||
       ((fd_flags & O_ACCMODE) == O_WRONLY &&
-       !(modeflags & static_cast<ModeFlags>(OpenMode::WRITE)))) {
+       (modeflags & static_cast<ModeFlags>(OpenMode::READ)))) {
     return Error(EINVAL);
   }
----------------
kaladron wrote:

It's out of scope for this patch, but I'd love to see us have a "FileMode" class with an enum and constexpr items for these.  The whole REQUIRES_WRITE, REQUIRES_READ could be part of it, etc.  Then you'd just be querying an object.  It shoudl have no runtime penalty or space penalty.  Then we get rid of potentially fragile bit twiddling throughout.

https://github.com/llvm/llvm-project/pull/207837


More information about the libc-commits mailing list