os: use GetComputerNameW to retrieve hostname on Windows (#9861)
							parent
							
								
									dee4904bee
								
							
						
					
					
						commit
						187895c93c
					
				|  | @ -215,6 +215,8 @@ fn C.SetHandleInformation(hObject voidptr, dwMask u32, dw_flags u32) bool | ||||||
| 
 | 
 | ||||||
| fn C.ExpandEnvironmentStringsW(lpSrc &u16, lpDst &u16, nSize u32) u32 | fn C.ExpandEnvironmentStringsW(lpSrc &u16, lpDst &u16, nSize u32) u32 | ||||||
| 
 | 
 | ||||||
|  | fn C.GetComputerNameW(&u16, &u32) bool | ||||||
|  | 
 | ||||||
| [trusted] | [trusted] | ||||||
| fn C.SendMessageTimeout() u32 | fn C.SendMessageTimeout() u32 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -390,8 +390,13 @@ pub fn uname() Uname { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn hostname() string { | pub fn hostname() string { | ||||||
| 	// TODO: use C.GetComputerName(&u16, u32) int instead
 | 	hostname := [255]u16{} | ||||||
| 	return execute('cmd /c hostname').output | 	size := u32(255) | ||||||
|  | 	res := C.GetComputerNameW(&hostname[0], &size) | ||||||
|  | 	if !res { | ||||||
|  | 		return error(get_error_msg(int(C.GetLastError()))) | ||||||
|  | 	} | ||||||
|  | 	return unsafe { string_from_wide(&hostname[0]) } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn loginname() string { | pub fn loginname() string { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue