Skip to content

Commit 05adf7f

Browse files
committed
update
Signed-off-by: yjhmelody <465402634@qq.com>
1 parent f288e7c commit 05adf7f

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

vm/src/stdlib/io.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,7 @@ fn compute_c_flag(mode: &str) -> u32 {
302302
let flag = match mode.chars().next() {
303303
Some(mode) => match mode {
304304
'w' => libc::O_WRONLY | libc::O_CREAT,
305-
'x' => {
306-
libc::O_WRONLY
307-
| libc::O_CREAT
308-
| libc::O_EXCL
309-
}
305+
'x' => libc::O_WRONLY | libc::O_CREAT | libc::O_EXCL,
310306
'a' => libc::O_APPEND,
311307
'+' => libc::O_RDWR,
312308
_ => libc::O_RDONLY,

vm/src/stdlib/os.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::ffi::CStr;
44
use std::fs::File;
55
use std::fs::OpenOptions;
66
use std::io::{self, Error, ErrorKind, Read, Write};
7+
use std::convert::TryInto;
78
#[cfg(unix)]
89
use std::os::unix::fs::OpenOptionsExt;
910
#[cfg(windows)]
@@ -32,6 +33,8 @@ use crate::pyobject::{
3233
};
3334
use crate::vm::VirtualMachine;
3435

36+
use bitflags::bitflags;
37+
3538
#[cfg(unix)]
3639
pub fn raw_file_number(handle: File) -> i64 {
3740
use std::os::unix::io::IntoRawFd;
@@ -119,8 +122,14 @@ pub fn os_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
119122
let fname = &make_path(vm, name, &dir_fd).value;
120123

121124
let mut options = OpenOptions::new();
122-
let flags = objint::get_value(flags).to_i32().unwrap();
123-
options.custom_flags(flags);
125+
126+
if cfg!(unix) {
127+
let flags = objint::get_value(flags).to_i32().unwrap();
128+
options.custom_flags(flags);
129+
} else {
130+
let flags = objint::get_value(flags).to_u32().unwrap();
131+
options.custom_flags(flags.try_into().unwrap_or_default());
132+
};
124133

125134
let handle = options
126135
.open(&fname)
@@ -1075,14 +1084,13 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
10751084
"O_RDONLY" => ctx.new_int(libc::O_RDONLY),
10761085
"O_WRONLY" => ctx.new_int(libc::O_WRONLY),
10771086
"O_RDWR" => ctx.new_int(libc::O_RDWR),
1078-
"O_NONBLOCK" => ctx.new_int(libc::O_NONBLOCK),
10791087
"O_APPEND" => ctx.new_int(libc::O_APPEND),
10801088
"O_EXCL" => ctx.new_int(libc::O_EXCL),
10811089
"O_CREAT" => ctx.new_int(libc::O_CREAT),
1082-
"F_OK" => ctx.new_int(libc::F_OK),
1083-
"R_OK" => ctx.new_int(libc::R_OK),
1084-
"W_OK" => ctx.new_int(libc::W_OK),
1085-
"X_OK" => ctx.new_int(libc::X_OK),
1090+
"F_OK" => ctx.new_int(0),
1091+
"R_OK" => ctx.new_int(4),
1092+
"W_OK" => ctx.new_int(2),
1093+
"X_OK" => ctx.new_int(1),
10861094
});
10871095

10881096
for support in support_funcs {

0 commit comments

Comments
 (0)