File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -388,6 +388,27 @@ pub(crate) mod module {
388
388
}
389
389
}
390
390
391
+ #[ pyfunction]
392
+ fn getlogin ( vm : & VirtualMachine ) -> PyResult < String > {
393
+ let mut buffer = [ 0u16 ; 257 ] ;
394
+ let mut size = buffer. len ( ) as u32 ;
395
+
396
+ let success = unsafe {
397
+ windows_sys:: Win32 :: System :: WindowsProgramming :: GetUserNameW (
398
+ buffer. as_mut_ptr ( ) ,
399
+ & mut size,
400
+ )
401
+ } ;
402
+
403
+ if success != 0 {
404
+ // Convert the buffer (which is UTF-16) to a Rust String
405
+ let username = std:: ffi:: OsString :: from_wide ( & buffer[ ..( size - 1 ) as usize ] ) ;
406
+ Ok ( username. to_str ( ) . unwrap ( ) . to_string ( ) )
407
+ } else {
408
+ Err ( vm. new_os_error ( format ! ( "Error code: {success}" ) ) )
409
+ }
410
+ }
411
+
391
412
pub fn raw_set_handle_inheritable ( handle : intptr_t , inheritable : bool ) -> std:: io:: Result < ( ) > {
392
413
let flags = if inheritable {
393
414
Foundation :: HANDLE_FLAG_INHERIT
You can’t perform that action at this time.
0 commit comments