os: make minior improvement to C function semantics and related code (#21565)

This commit is contained in:
Turiiya 2024-05-25 10:30:04 +02:00 committed by GitHub
parent a7cf1ad7d5
commit 25be36296e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -61,9 +61,9 @@ pub const s_iwoth = 0o0002 // Write by others
pub const s_ixoth = 0o0001
fn C.utime(&char, voidptr) int
fn C.utime(&char, &C.utimbuf) int
fn C.uname(name voidptr) int
fn C.uname(name &C.utsname) int
fn C.symlink(&char, &char) int
@ -215,7 +215,7 @@ fn native_glob_pattern(pattern string, mut matches []string) ! {
pub fn utime(path string, actime int, modtime int) ! {
u := C.utimbuf{actime, modtime}
if C.utime(&char(path.str), voidptr(&u)) != 0 {
if C.utime(&char(path.str), &u) != 0 {
return error_with_code(posix_get_error_msg(C.errno), C.errno)
}
}
@ -238,10 +238,8 @@ pub fn utime(path string, actime int, modtime int) ! {
// See also https://pubs.opengroup.org/onlinepubs/7908799/xsh/sysutsname.h.html
pub fn uname() Uname {
mut u := Uname{}
utsize := sizeof(C.utsname)
unsafe {
x := malloc_noscan(int(utsize))
d := &C.utsname(x)
d := &C.utsname(malloc_noscan(int(sizeof(C.utsname))))
if C.uname(d) == 0 {
u.sysname = cstring_to_vstring(d.sysname)
u.nodename = cstring_to_vstring(d.nodename)