fix open bindings

`open` specifies the `mode` argument as vararg (presumably to make it
optional). varargs actually have rules about casting, in this case the
rule that any integer arg of size <= 4 has to be casted to `i32` before
passing it.

Not doing that implicit cast makes the permissions wrong or not apply at
all.
This commit is contained in:
Laytan Laats
2024-08-16 22:54:53 +02:00
parent 970dc7a1f2
commit f7d7d65bc0
8 changed files with 45 additions and 21 deletions
+21
View File
@@ -287,3 +287,24 @@ test_pthreads :: proc(t: ^testing.T) {
return nil
}
}
@(test)
open_permissions :: proc(t: ^testing.T) {
in_mode := posix.mode_t{.IRUSR, .IWUSR, .IROTH, .IRGRP}
fd := posix.open("test_posix_permissions.txt", {.CREAT, .RDWR}, in_mode)
testing.expectf(t, fd != -1, "failed to open: %v", posix.strerror())
defer {
ret := posix.close(fd)
testing.expectf(t, ret == .OK, "failed to close: %v", posix.strerror())
ret2 := posix.remove("test_posix_permissions.txt")
testing.expectf(t, ret2 == 0, "failed to remove: %v", posix.strerror())
}
stat: posix.stat_t
res := posix.fstat(fd, &stat)
testing.expectf(t, res == .OK, "failed to stat: %v", posix.strerror())
stat.st_mode -= posix.S_IFMT
testing.expect_value(t, stat.st_mode, in_mode)
}