File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change
1
+ use super :: os:: errno_err;
1
2
use crate :: obj:: objbytes:: PyBytesRef ;
2
3
use crate :: obj:: objstr:: PyStringRef ;
3
4
use crate :: pyobject:: { PyObjectRef , PyResult } ;
@@ -45,6 +46,19 @@ fn msvcrt_putwch(s: PyStringRef, vm: &VirtualMachine) -> PyResult<()> {
45
46
Ok ( ( ) )
46
47
}
47
48
49
+ extern "C" {
50
+ fn _setmode ( fd : i32 , flags : i32 ) -> i32 ;
51
+ }
52
+
53
+ fn msvcrt_setmode ( fd : i32 , flags : i32 , vm : & VirtualMachine ) -> PyResult < i32 > {
54
+ let flags = unsafe { suppress_iph ! ( _setmode( fd, flags) ) } ;
55
+ if flags == -1 {
56
+ Err ( errno_err ( vm) )
57
+ } else {
58
+ Ok ( flags)
59
+ }
60
+ }
61
+
48
62
pub fn make_module ( vm : & VirtualMachine ) -> PyObjectRef {
49
63
let ctx = & vm. ctx ;
50
64
py_module ! ( vm, "_msvcrt" , {
@@ -54,5 +68,6 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
54
68
"getwche" => ctx. new_function( msvcrt_getwche) ,
55
69
"putch" => ctx. new_function( msvcrt_putch) ,
56
70
"putwch" => ctx. new_function( msvcrt_putwch) ,
71
+ "setmode" => ctx. new_function( msvcrt_setmode) ,
57
72
} )
58
73
}
You can’t perform that action at this time.
0 commit comments