std.sys¶
The C library, declared exactly once: every other module borrows these names instead of redeclaring them, because an extern's C symbol is its CAIRN name and two declarations of one symbol collide in the emitted program. Prefer std.io and std.net; these are raw. Cost: one syscall per call, no buffering, and io plus ffi:<symbol> in every caller's row.
// An extent may name a later parameter, which is how C orders (pointer, length).
// effects: ffi:read, ffi_precondition, io, trap, write:data
pub extern fn read(fd:i32, data:rw<u8>[n]@host, n:usize) -> i64 effects(io)
// effects: ffi:write, ffi_precondition, io, read:data, trap
pub extern fn write(fd:i32, data:ro<u8>[n]@host, n:usize) -> i64 effects(io)
// A C string is a pointer, not a view: pass path[0..1] and keep the NUL inside the storage.
// effects: ffi:open, ffi_precondition, io, read:path, trap
pub extern fn open(path:ro<u8>[1]@host, flags:i32, mode:u32) -> i32 effects(io)
pub extern fn close(fd:i32) -> i32 effects(io) // effects: ffi:close, io
pub extern fn lseek(fd:i32, offset:i64, whence:i32) -> i64 effects(io) // effects: ffi:lseek, io
pub extern fn fsync(fd:i32) -> i32 effects(io) // effects: ffi:fsync, io
pub extern fn ftruncate(fd:i32, length:i64) -> i32 effects(io) // effects: ffi:ftruncate, io
// effects: ffi:unlink, ffi_precondition, io, read:path, trap
pub extern fn unlink(path:ro<u8>[1]@host) -> i32 effects(io)
// effects: ffi:rename, ffi_precondition, io, read:from, read:to, trap
pub extern fn rename(from:ro<u8>[1]@host, to:ro<u8>[1]@host) -> i32 effects(io)
// effects: ffi:access, ffi_precondition, io, read:path, trap
pub extern fn access(path:ro<u8>[1]@host, mode:i32) -> i32 effects(io)
// struct timespec is two 64-bit words on every supported target.
// effects: ffi:clock_gettime, ffi_precondition, io, trap, write:ts
pub extern fn clock_gettime(clock:i32, ts:rw<i64>[2]@host) -> i32 effects(io)
// effects: ffi:nanosleep, ffi_precondition, io, read:wanted, trap, write:left
pub extern fn nanosleep(wanted:ro<i64>[2]@host, left:rw<i64>[2]@host) -> i32 effects(io)
// errno is a macro over a thread-local int*, so its address arrives as an integer.
pub extern fn __errno_location() -> usize effects(io) // effects: ffi:__errno_location, io
pub extern fn getpid() -> i32 effects(io) // effects: ffi:getpid, io
pub extern fn socket(domain:i32, kind:i32, protocol:i32) -> i32 effects(io) // effects: ffi:socket, io
// effects: ffi:bind, ffi_precondition, io, read:addr, trap
pub extern fn bind(fd:i32, addr:ro<u8>[16]@host, length:u32) -> i32 effects(io)
pub extern fn listen(fd:i32, backlog:i32) -> i32 effects(io) // effects: ffi:listen, io
// effects: ffi:accept, ffi_precondition, io, trap, write:addr, write:length
pub extern fn accept(fd:i32, addr:rw<u8>[16]@host, length:rw<u32>) -> i32 effects(io)
// effects: ffi:connect, ffi_precondition, io, read:addr, trap
pub extern fn connect(fd:i32, addr:ro<u8>[16]@host, length:u32) -> i32 effects(io)
// effects: ffi:send, ffi_precondition, io, read:data, trap
pub extern fn send(fd:i32, data:ro<u8>[n]@host, n:usize, flags:i32) -> i64 effects(io)
// effects: ffi:recv, ffi_precondition, io, trap, write:data
pub extern fn recv(fd:i32, data:rw<u8>[n]@host, n:usize, flags:i32) -> i64 effects(io)
// effects: ffi:setsockopt, ffi_precondition, io, read:value, trap
pub extern fn setsockopt(fd:i32, level:i32, option:i32, value:ro<u8>[4]@host, length:u32) -> i32 effects(io)
// The last error the C library recorded: one volatile 32-bit load of errno's address.
pub fn errno() -> i32 // effects: ffi:__errno_location, io, mmio, trap
A generic function's effects are what it may do for any arguments within its bounds, besides what their own trait members do.