1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ci: fix -cstrict checks after 7585e86

This commit is contained in:
Delyan Angelov 2022-08-17 18:40:15 +03:00
parent 18e737aee2
commit 7ed3389fa8
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -611,7 +611,7 @@ pub fn read_file_array<T>(path string) []T {
pub fn executable() string { pub fn executable() string {
mut result := [max_path_buffer_size]u8{} mut result := [max_path_buffer_size]u8{}
$if windows { $if windows {
pu16_result := unsafe { &u16(&result) } pu16_result := unsafe { &u16(&result[0]) }
len := C.GetModuleFileName(0, pu16_result, 512) len := C.GetModuleFileName(0, pu16_result, 512)
// determine if the file is a windows symlink // determine if the file is a windows symlink
attrs := C.GetFileAttributesW(pu16_result) attrs := C.GetFileAttributesW(pu16_result)
@ -625,10 +625,10 @@ pub fn executable() string {
} }
final_path := [max_path_buffer_size]u8{} final_path := [max_path_buffer_size]u8{}
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew
final_len := C.GetFinalPathNameByHandleW(file, unsafe { &u16(&final_path) }, final_len := C.GetFinalPathNameByHandleW(file, unsafe { &u16(&final_path[0]) },
max_path_buffer_size, 0) max_path_buffer_size, 0)
if final_len < max_path_buffer_size { if final_len < max_path_buffer_size {
sret := unsafe { string_from_wide2(&u16(&final_path), final_len) } sret := unsafe { string_from_wide2(&u16(&final_path[0]), final_len) }
defer { defer {
unsafe { sret.free() } unsafe { sret.free() }
} }
@ -646,46 +646,46 @@ pub fn executable() string {
} }
$if macos { $if macos {
pid := C.getpid() pid := C.getpid()
ret := proc_pidpath(pid, &result, max_path_len) ret := proc_pidpath(pid, &result[0], max_path_len)
if ret <= 0 { if ret <= 0 {
eprintln('os.executable() failed at calling proc_pidpath with pid: $pid . proc_pidpath returned $ret ') eprintln('os.executable() failed at calling proc_pidpath with pid: $pid . proc_pidpath returned $ret ')
return executable_fallback() return executable_fallback()
} }
res := unsafe { tos_clone(&result) } res := unsafe { tos_clone(&result[0]) }
return res return res
} }
$if freebsd { $if freebsd {
bufsize := usize(max_path_buffer_size) bufsize := usize(max_path_buffer_size)
mib := [1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1] mib := [1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1]
unsafe { C.sysctl(mib.data, mib.len, &result, &bufsize, 0, 0) } unsafe { C.sysctl(mib.data, mib.len, &result[0], &bufsize, 0, 0) }
res := unsafe { tos_clone(&result) } res := unsafe { tos_clone(&result[0]) }
return res return res
} }
$if netbsd { $if netbsd {
count := C.readlink(c'/proc/curproc/exe', &char(&result), max_path_len) count := C.readlink(c'/proc/curproc/exe', &char(&result[0]), max_path_len)
if count < 0 { if count < 0 {
eprintln('os.executable() failed at reading /proc/curproc/exe to get exe path') eprintln('os.executable() failed at reading /proc/curproc/exe to get exe path')
return executable_fallback() return executable_fallback()
} }
res := unsafe { tos_clone(&result) } res := unsafe { tos_clone(&result[0]) }
return res return res
} }
$if dragonfly { $if dragonfly {
count := C.readlink(c'/proc/curproc/file', &char(&result), max_path_len) count := C.readlink(c'/proc/curproc/file', &char(&result[0]), max_path_len)
if count < 0 { if count < 0 {
eprintln('os.executable() failed at reading /proc/curproc/file to get exe path') eprintln('os.executable() failed at reading /proc/curproc/file to get exe path')
return executable_fallback() return executable_fallback()
} }
res := unsafe { tos_clone(&result) } res := unsafe { tos_clone(&result[0]) }
return res return res
} }
$if linux { $if linux {
count := C.readlink(c'/proc/self/exe', &char(&result), max_path_len) count := C.readlink(c'/proc/self/exe', &char(&result[0]), max_path_len)
if count < 0 { if count < 0 {
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 { tos_clone(&result) } res := unsafe { tos_clone(&result[0]) }
return res return res
} }
// "Sadly there is no way to get the full path of the executed file in OpenBSD." // "Sadly there is no way to get the full path of the executed file in OpenBSD."
@ -752,16 +752,16 @@ pub fn getwd() string {
unsafe { unsafe {
buf := [max_path_buffer_size]u8{} buf := [max_path_buffer_size]u8{}
$if windows { $if windows {
if C._wgetcwd(&u16(&buf), max_path_len) == 0 { if C._wgetcwd(&u16(&buf[0]), max_path_len) == 0 {
return '' return ''
} }
res := string_from_wide(&u16(&buf)) res := string_from_wide(&u16(&buf[0]))
return res return res
} $else { } $else {
if C.getcwd(&char(&buf), max_path_len) == 0 { if C.getcwd(&char(&buf[0]), max_path_len) == 0 {
return '' return ''
} }
res := tos_clone(&buf) res := tos_clone(&buf[0])
return res return res
} }
} }
@ -777,7 +777,7 @@ pub fn real_path(fpath string) string {
mut fullpath := [max_path_buffer_size]u8{} mut fullpath := [max_path_buffer_size]u8{}
mut res := '' mut res := ''
$if windows { $if windows {
pu16_fullpath := unsafe { &u16(&fullpath) } pu16_fullpath := unsafe { &u16(&fullpath[0]) }
// gets handle with GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 // gets handle with GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
// use C.CreateFile(fpath.to_wide(), 0x80000000, 1, 0, 3, 0x80, 0) instead of get_file_handle // use C.CreateFile(fpath.to_wide(), 0x80000000, 1, 0, 3, 0x80, 0) instead of get_file_handle
// try to open the file to get symbolic link path // try to open the file to get symbolic link path
@ -815,7 +815,7 @@ pub fn real_path(fpath string) string {
res = unsafe { string_from_wide(pu16_fullpath) } res = unsafe { string_from_wide(pu16_fullpath) }
} }
} $else { } $else {
ret := &char(C.realpath(&char(fpath.str), &char(&fullpath))) ret := &char(C.realpath(&char(fpath.str), &char(&fullpath[0])))
if ret == 0 { if ret == 0 {
unsafe { res.free() } unsafe { res.free() }
return fpath.clone() return fpath.clone()
@ -825,7 +825,7 @@ pub fn real_path(fpath string) string {
// resulting string from that buffer, to a shorter one, and then free the // resulting string from that buffer, to a shorter one, and then free the
// 4KB fullpath buffer. // 4KB fullpath buffer.
unsafe { res.free() } unsafe { res.free() }
res = unsafe { tos_clone(&fullpath) } res = unsafe { tos_clone(&fullpath[0]) }
} }
unsafe { normalize_drive_letter(res) } unsafe { normalize_drive_letter(res) }
return res return res