From 7005c07d235c036a5001eee6c210a71c8a17b9d6 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 1 Aug 2026 13:50:32 +0100 Subject: [PATCH 1/2] Add more flags in fopen --- libcc2rs/src/libc_shims/cfile.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/libcc2rs/src/libc_shims/cfile.rs b/libcc2rs/src/libc_shims/cfile.rs index 914f3bdb..e25c0f79 100644 --- a/libcc2rs/src/libc_shims/cfile.rs +++ b/libcc2rs/src/libc_shims/cfile.rs @@ -19,13 +19,30 @@ impl CFile { } pub fn open(path: &str, mode: &str) -> Option { - let flags = match mode { - "rb" => nix::fcntl::OFlag::O_RDONLY, - "wb" => nix::fcntl::OFlag::O_WRONLY - .union(nix::fcntl::OFlag::O_CREAT) - .union(nix::fcntl::OFlag::O_TRUNC), - m => panic!("fopen: unsupported mode {:?}", m), + use nix::fcntl::OFlag; + let mut chars = mode.chars(); + let mut flags = match chars.next() { + Some('r') => OFlag::O_RDONLY, + Some('w') => OFlag::O_WRONLY + .union(OFlag::O_CREAT) + .union(OFlag::O_TRUNC), + Some('a') => OFlag::O_WRONLY + .union(OFlag::O_CREAT) + .union(OFlag::O_APPEND), + _ => panic!("fopen: unsupported mode {:?}", mode), }; + for c in chars { + match c { + 'b' => {} + '+' => { + flags.remove(OFlag::O_WRONLY); + flags.insert(OFlag::O_RDWR); + } + 'x' => flags.insert(OFlag::O_EXCL), + 'e' => flags.insert(OFlag::O_CLOEXEC), + _ => panic!("fopen: unsupported mode {:?}", mode), + } + } match nix::fcntl::open(path, flags, nix::sys::stat::Mode::from_bits_truncate(0o666)) { Ok(ofd) => Some(CFile::new(FdRegistry::register(ofd))), Err(e) => { From b2187fefe3e1ba76773f0d7dade2823d045cd217 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 11 Aug 2026 13:21:49 +0100 Subject: [PATCH 2/2] format --- libcc2rs/src/libc_shims/cfile.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libcc2rs/src/libc_shims/cfile.rs b/libcc2rs/src/libc_shims/cfile.rs index e25c0f79..a80e77ad 100644 --- a/libcc2rs/src/libc_shims/cfile.rs +++ b/libcc2rs/src/libc_shims/cfile.rs @@ -23,12 +23,8 @@ impl CFile { let mut chars = mode.chars(); let mut flags = match chars.next() { Some('r') => OFlag::O_RDONLY, - Some('w') => OFlag::O_WRONLY - .union(OFlag::O_CREAT) - .union(OFlag::O_TRUNC), - Some('a') => OFlag::O_WRONLY - .union(OFlag::O_CREAT) - .union(OFlag::O_APPEND), + Some('w') => OFlag::O_WRONLY.union(OFlag::O_CREAT).union(OFlag::O_TRUNC), + Some('a') => OFlag::O_WRONLY.union(OFlag::O_CREAT).union(OFlag::O_APPEND), _ => panic!("fopen: unsupported mode {:?}", mode), }; for c in chars {