Skip to content

Commit 55b0814

Browse files
committed
Add msvcrt.setmode
1 parent e9ef854 commit 55b0814

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

vm/src/stdlib/msvcrt.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::os::errno_err;
12
use crate::obj::objbytes::PyBytesRef;
23
use crate::obj::objstr::PyStringRef;
34
use crate::pyobject::{PyObjectRef, PyResult};
@@ -45,6 +46,19 @@ fn msvcrt_putwch(s: PyStringRef, vm: &VirtualMachine) -> PyResult<()> {
4546
Ok(())
4647
}
4748

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+
4862
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
4963
let ctx = &vm.ctx;
5064
py_module!(vm, "_msvcrt", {
@@ -54,5 +68,6 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
5468
"getwche" => ctx.new_function(msvcrt_getwche),
5569
"putch" => ctx.new_function(msvcrt_putch),
5670
"putwch" => ctx.new_function(msvcrt_putwch),
71+
"setmode" => ctx.new_function(msvcrt_setmode),
5772
})
5873
}

0 commit comments

Comments
 (0)