std/os
Typed libc bindings (memory, file descriptors, sockets, threads, processes) plus the green-aware fd wrappers the rest of the standard library is built on. Most programs only reach for it in FFI code; for files, sockets and processes use std/fs, std/net and std/process.
from "std/os" import { malloc, free }API reference
acceptFd
pub fn acceptFd(fd: i32): i32Accept one connection; returns the client fd (<0 on error). In a green task the client fd is left nonblocking so later readFd/writeFd calls skip a redundant fcntl round-trip.
acceptFdNb
pub fn acceptFdNb(fd: i32): i32Single-shot nonblocking accept: the client fd, or -1 when no connection is pending. For event loops that multiplex accept with other work and must not park on the listener — a blocking accept stops every other event source until the next connection arrives (milojs's cold-fetch hang).
bindIn
pub fn bindIn(fd: i32, addr: &SockAddrIn): i32bindIn6
pub fn bindIn6(fd: i32, addr: &SockAddrIn6): i32bindUn
pub fn bindUn(fd: i32, addr: &SockAddrUn): i32connectFdIn
pub fn connectFdIn(fd: i32, addr: &SockAddrIn): i32connectFdIn6
pub fn connectFdIn6(fd: i32, addr: &SockAddrIn6): i32connectFdIn6Wait
pub fn connectFdIn6Wait(fd: i32, addr: &SockAddrIn6, wait: (bool) => bool): i32connectFdInWait for an IPv6 address.
connectFdInWait
pub fn connectFdInWait(fd: i32, addr: &SockAddrIn, wait: (bool) => bool): i32connect(2) that waits through wait. 0 on success, -1 on failure, IO_GAVE_UP.
connectFdUn
pub fn connectFdUn(fd: i32, addr: &SockAddrUn): i32getSockAddr4
pub fn getSockAddr4(fd: i32): i64The bound IPv4 address of fd in network order (as ip4 builds it), or -1 when it is not an IPv4 socket or getsockname fails. The family is read from the length the kernel reports (a sockaddr_in is 16 bytes) because the family field sits at a different offset on darwin (sin_len first) and linux. -1 under replay, where descriptors are synthetic; callers use it only for diagnostics.
getSockPort
pub fn getSockPort(fd: i32): i32The bound port, whatever family the socket is. getsockname writes into storage-sized space because the kernel picks the family; sin_port and sin6_port BOTH sit at offset 2 (same invariant as sun_path), so one read serves v4 and v6. Returns -1 on failure.
readFd
pub fn readFd(fd: i32, buf: *u8, len: i64): i64One read(2). Returns bytes read, 0 at EOF, <0 on error.
recvFd
pub fn recvFd(fd: i32, buf: *u8, len: i64): i64Green-aware SOCKET read/write. Identical shape to readFd/writeFd but through the sockRead/sockWrite seam: on POSIX that is read/write (a socket fd is a normal fd), but on Windows a SOCKET is NOT a CRT fd — the CRT _read/_write behind read/write fast-fail on one, so socket data must go through recv/send. Socket code (std/net, raw-socket programs) must use these, not readFd/writeFd, which stay bound to the CRT fd path for stdout/stdin/pipes.
recvFdWait
pub fn recvFdWait(fd: i32, buf: *u8, len: i64, wait: (bool) => bool): i64One socket read that waits through wait. Bytes read, 0 at EOF, <0 on error, IO_GAVE_UP.
sendFd
pub fn sendFd(fd: i32, buf: *u8, len: i64): i64sendFdWait
pub fn sendFdWait(fd: i32, buf: *u8, len: i64, wait: (bool) => bool): i64Write all len bytes, waiting through wait. len, <0 on error, or IO_GAVE_UP.
sysAccept
pub fn sysAccept(fd: i32): i32accept(2), discarding the peer address. Under replay the recorded client fd comes back as a synthetic socket.
sysClose
pub fn sysClose(fd: i32): i32close(2). Under replay a synthetic descriptor is forgotten, never passed to the OS.
sysDup
pub fn sysDup(fd: i32): i32dup(2). Under replay the duplicate of a descriptor is synthetic like everything else the trace hands out, and keeps the original's record kinds.
sysIsatty
pub fn sysIsatty(fd: i32): boolisatty(3) through the trace: whether a descriptor is a terminal is an input too.
sysKill
pub fn sysKill(pid: i32, sig: i32): i32kill(2) through the trace. Under replay no signal is sent: the pid is the recorded run's, and whatever has it now is not ours.
sysListen
pub fn sysListen(fd: i32, backlog: i32): i32listen(2).
sysLseek
pub fn sysLseek(fd: i32, off: i64, whence: i32): i64lseek(2): the new offset, or <0.
sysOpen
pub fn sysOpen(path: &string, flags: i32, mode: i32): i32open(2) with a creation mode (ignored unless flags creates). The fd, or <0.
sysRead
pub fn sysRead(fd: i32, buf: *u8, len: i64): i64One read(2): bytes read, 0 at EOF, <0 with errno set. At most 2147479552 bytes.
sysSocket
pub fn sysSocket(domain: i32, sockType: i32, protocol: i32): i32socket(2). Under replay the recorded number comes back as a synthetic socket.
sysWaitpid
pub fn sysWaitpid(pid: i32, status: *u8, options: i32): i32waitpid(2) through the trace: the return value and the status word the kernel wrote. Under replay no child exists; the recorded exit comes back.
sysWrite
pub fn sysWrite(fd: i32, buf: *u8, len: i64): i64One write(2): bytes written, <0 with errno set. At most 2147479552 bytes.
writeFd
pub fn writeFd(fd: i32, buf: *u8, len: i64): i64Write all len bytes (loops over partial writes). Returns len or <0 on error.