I believe usize is intended simply because what this function is doing is performing a linux syscall without linking libc. this is possible because linux syscalls have a stable ABI, one part of which is returning usize.
const epoll_create_rc = std.os.linux.epoll_create1(...); // This is the return code of the syscall
// Then check for errors on the return code.
const epoll_errno = std.os.linux.errno(epoll_create_rc);
switch (epoll_errno) {
.SUCCESS => {
// No errors, so epoll_create_rc is an actual file descriptor.
return epoll_create_rc; // Just an example.
},
else => {
// Handle errors properly.
}
}
If I recall correctly, this should be insipred by the musl libc
If I remember right drivers’ methods (for ex.) in case of error return -ESOMEERROR and then syscall (or libc wrapper, do not know exactly) return -1 (usually) and set errno to ESOMEERROR.
You could do @as(i32, @intCast(rc)) where rc is the return code.
If you’re using zig 0.16 you have to use std.os.linux, it returns a usize because it is doing actual syscalls, bypassing libc, have a look here and here.
The posix namespace will be removed because it will be redundant with the new std.Io stuff iirc.