mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: Make windows allocations more consistent & LocalFree args_list
if max is 512 then allocate `max * sizeof(wchar_t)`
This commit is contained in:
parent
f8bc893972
commit
ca70d1f8a3
15
vlib/os/os.v
15
vlib/os/os.v
@ -100,6 +100,8 @@ fn init_os_args(argc int, argv *byteptr) []string {
|
||||
for i := 0; i < args_count; i++ {
|
||||
args << string_from_wide(&u16(args_list[i]))
|
||||
}
|
||||
|
||||
C.LocalFree(args_list)
|
||||
} $else {
|
||||
for i := 0; i < argc; i++ {
|
||||
args << string(argv[i])
|
||||
@ -520,7 +522,7 @@ pub fn get_line() string {
|
||||
pub fn get_raw_line() string {
|
||||
$if windows {
|
||||
max := 512 // MAX_PATH * sizeof(wchar_t)
|
||||
buf := &u16(malloc(max))
|
||||
buf := &u16(malloc(max*2))
|
||||
h_input := C.GetStdHandle(STD_INPUT_HANDLE)
|
||||
if h_input == INVALID_HANDLE_VALUE {
|
||||
panic('get_raw_line() error getting input handle.')
|
||||
@ -658,8 +660,9 @@ pub fn executable() string {
|
||||
return string(result, count)
|
||||
}
|
||||
$if windows {
|
||||
mut result := &u16(malloc(512)) // MAX_PATH * sizeof(wchar_t)
|
||||
len := int(C.GetModuleFileName( 0, result, MAX_PATH ))
|
||||
max := 512
|
||||
mut result := &u16(malloc(max*2)) // MAX_PATH * sizeof(wchar_t)
|
||||
len := int(C.GetModuleFileName( 0, result, max ))
|
||||
return string_from_wide2(result, len)
|
||||
}
|
||||
$if mac {
|
||||
@ -731,9 +734,9 @@ pub fn chdir(path string) {
|
||||
|
||||
pub fn getwd() string {
|
||||
$if windows {
|
||||
max := 1024 // MAX_PATH * sizeof(wchar_t)
|
||||
buf := &u16(malloc(max))
|
||||
if C._wgetcwd(buf, max/2) == 0 {
|
||||
max := 512 // MAX_PATH * sizeof(wchar_t)
|
||||
buf := &u16(malloc(max*2))
|
||||
if C._wgetcwd(buf, max) == 0 {
|
||||
return ''
|
||||
}
|
||||
return string_from_wide(buf)
|
||||
|
Loading…
Reference in New Issue
Block a user