Skip to content

Commit 725cfcc

Browse files
committed
compute_c_flag ignore chars after first
1 parent 3085ead commit 725cfcc

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

vm/src/stdlib/io.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,19 @@ fn buffered_reader_read(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
284284
}
285285

286286
fn compute_c_flag(mode: &str) -> u32 {
287-
let flags = match mode {
288-
"w" => os::FileCreationFlags::O_WRONLY | os::FileCreationFlags::O_CREAT,
289-
"x" => {
290-
os::FileCreationFlags::O_WRONLY
291-
| os::FileCreationFlags::O_CREAT
292-
| os::FileCreationFlags::O_EXCL
293-
}
294-
"a" => os::FileCreationFlags::O_APPEND,
295-
"+" => os::FileCreationFlags::O_RDWR,
296-
_ => os::FileCreationFlags::O_RDONLY,
287+
let flags = match mode.chars().next() {
288+
Some(mode) => match mode {
289+
'w' => os::FileCreationFlags::O_WRONLY | os::FileCreationFlags::O_CREAT,
290+
'x' => {
291+
os::FileCreationFlags::O_WRONLY
292+
| os::FileCreationFlags::O_CREAT
293+
| os::FileCreationFlags::O_EXCL
294+
}
295+
'a' => os::FileCreationFlags::O_APPEND,
296+
'+' => os::FileCreationFlags::O_RDWR,
297+
_ => os::FileCreationFlags::O_RDONLY,
298+
},
299+
None => os::FileCreationFlags::O_RDONLY,
297300
};
298301
flags.bits()
299302
}

0 commit comments

Comments
 (0)