@@ -4,6 +4,7 @@ use std::ffi::CStr;
44use std:: fs:: File ;
55use std:: fs:: OpenOptions ;
66use std:: io:: { self , Error , ErrorKind , Read , Write } ;
7+ use std:: convert:: TryInto ;
78#[ cfg( unix) ]
89use std:: os:: unix:: fs:: OpenOptionsExt ;
910#[ cfg( windows) ]
@@ -32,6 +33,8 @@ use crate::pyobject::{
3233} ;
3334use crate :: vm:: VirtualMachine ;
3435
36+ use bitflags:: bitflags;
37+
3538#[ cfg( unix) ]
3639pub 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