ci: fix linux-cross job; os.real_path cleanup
parent
f9c4365dc7
commit
95cf120e2e
|
@ -263,7 +263,7 @@ pub fn malloc(n int) &byte {
|
||||||
[unsafe]
|
[unsafe]
|
||||||
pub fn v_realloc(b &byte, n int) &byte {
|
pub fn v_realloc(b &byte, n int) &byte {
|
||||||
$if trace_realloc ? {
|
$if trace_realloc ? {
|
||||||
C.fprintf(C.stderr, c'v_realloc new_size: %6d\n', new_size)
|
C.fprintf(C.stderr, c'v_realloc %6d\n', n)
|
||||||
}
|
}
|
||||||
mut new_ptr := &byte(0)
|
mut new_ptr := &byte(0)
|
||||||
$if prealloc {
|
$if prealloc {
|
||||||
|
|
|
@ -487,7 +487,7 @@ pub fn rmdir(path string) ? {
|
||||||
// print_c_errno will print the current value of `C.errno`.
|
// print_c_errno will print the current value of `C.errno`.
|
||||||
fn print_c_errno() {
|
fn print_c_errno() {
|
||||||
e := C.errno
|
e := C.errno
|
||||||
se := unsafe { tos_clone(&byte(C.strerror(C.errno))) }
|
se := unsafe { tos_clone(&byte(C.strerror(e))) }
|
||||||
println('errno=$e err=$se')
|
println('errno=$e err=$se')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,9 +625,7 @@ pub fn executable() string {
|
||||||
eprintln('os.executable() failed at reading /proc/self/exe to get exe path')
|
eprintln('os.executable() failed at reading /proc/self/exe to get exe path')
|
||||||
return executable_fallback()
|
return executable_fallback()
|
||||||
}
|
}
|
||||||
res := unsafe { xresult.vstring() }.clone()
|
return unsafe { xresult.vstring() }
|
||||||
unsafe { free(xresult) }
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
$if windows {
|
$if windows {
|
||||||
max := 512
|
max := 512
|
||||||
|
@ -761,15 +759,13 @@ pub fn getwd() string {
|
||||||
return string_from_wide(buf)
|
return string_from_wide(buf)
|
||||||
}
|
}
|
||||||
} $else {
|
} $else {
|
||||||
buf := vcalloc(512)
|
buf := vcalloc(max_path_len)
|
||||||
unsafe {
|
unsafe {
|
||||||
if C.getcwd(&char(buf), 512) == 0 {
|
if C.getcwd(&char(buf), max_path_len) == 0 {
|
||||||
free(buf)
|
free(buf)
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
res := buf.vstring().clone()
|
return buf.vstring()
|
||||||
free(buf)
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -782,55 +778,31 @@ pub fn getwd() string {
|
||||||
[manualfree]
|
[manualfree]
|
||||||
pub fn real_path(fpath string) string {
|
pub fn real_path(fpath string) string {
|
||||||
mut fullpath := &byte(0)
|
mut fullpath := &byte(0)
|
||||||
defer {
|
|
||||||
unsafe { free(fullpath) }
|
|
||||||
}
|
|
||||||
mut res := ''
|
mut res := ''
|
||||||
$if windows {
|
$if windows {
|
||||||
/*
|
// GetFullPathName doesn't work with symbolic links,
|
||||||
// GetFullPathName doesn't work with symbolic links
|
// so if it is not a file, get full path
|
||||||
// TODO: TCC32 gets runtime error
|
|
||||||
max := 512
|
|
||||||
size := max * 2 // max_path_len * sizeof(wchar_t)
|
|
||||||
// gets handle with GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
|
|
||||||
// use get_file_handle instead of C.CreateFile(fpath.to_wide(), 0x80000000, 1, 0, 3, 0x80, 0)
|
|
||||||
// try to open the file to get symbolic link path
|
|
||||||
file := get_file_handle(fpath)
|
|
||||||
if file != voidptr(-1) {
|
|
||||||
fullpath = unsafe { &u16(vcalloc(size)) }
|
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew
|
|
||||||
final_len := C.GetFinalPathNameByHandleW(file, fullpath, size, 0)
|
|
||||||
if final_len < size {
|
|
||||||
ret := unsafe { string_from_wide2(fullpath, final_len) }
|
|
||||||
res = ret[4..]
|
|
||||||
} else {
|
|
||||||
eprintln('os.real_path() saw that the file path was too long')
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*/
|
|
||||||
// if it is not a file get full path
|
|
||||||
fullpath = unsafe { &u16(vcalloc(max_path_len * 2)) }
|
fullpath = unsafe { &u16(vcalloc(max_path_len * 2)) }
|
||||||
// TODO: check errors if path len is not enough
|
// TODO: check errors if path len is not enough
|
||||||
ret := C.GetFullPathName(fpath.to_wide(), max_path_len, fullpath, 0)
|
ret := C.GetFullPathName(fpath.to_wide(), max_path_len, fullpath, 0)
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
|
unsafe { free(fullpath) }
|
||||||
return fpath
|
return fpath
|
||||||
}
|
}
|
||||||
res = unsafe { string_from_wide(fullpath) }
|
res = unsafe { string_from_wide(fullpath) }
|
||||||
//}
|
|
||||||
// C.CloseHandle(file)
|
|
||||||
} $else {
|
} $else {
|
||||||
fullpath = vcalloc(max_path_len)
|
fullpath = vcalloc(max_path_len)
|
||||||
ret := &char(C.realpath(&char(fpath.str), &char(fullpath)))
|
ret := &char(C.realpath(&char(fpath.str), &char(fullpath)))
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
|
unsafe { free(fullpath) }
|
||||||
return fpath
|
return fpath
|
||||||
}
|
}
|
||||||
res = unsafe { fullpath.vstring() }
|
res = unsafe { fullpath.vstring() }
|
||||||
}
|
}
|
||||||
nres := normalize_drive_letter(res)
|
return normalize_drive_letter(res)
|
||||||
cres := nres.clone()
|
|
||||||
return cres
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[direct_array_access; manualfree]
|
||||||
fn normalize_drive_letter(path string) string {
|
fn normalize_drive_letter(path string) string {
|
||||||
// normalize_drive_letter is needed, because a path like c:\nv\.bin (note the small `c`)
|
// normalize_drive_letter is needed, because a path like c:\nv\.bin (note the small `c`)
|
||||||
// in %PATH is NOT recognized by cmd.exe (and probably other programs too)...
|
// in %PATH is NOT recognized by cmd.exe (and probably other programs too)...
|
||||||
|
|
Loading…
Reference in New Issue