Module: sys.fd
Source: ./sys/fd.reef
Overview
sys/fd - File descriptor operations
Low-level file descriptor API for pipes, dup, open/close, and fcntl. For higher-level file I/O, use the io module instead.
Example - Pipe: let fds = fd_pipe() fd_write(fds[1], "hello") let msg = fd_read(fds[0], 32) fd_close(fds[0]) fd_close(fds[1])
Example - Open file: let fd = fd_open("/tmp/test.txt", O_WRONLY() | O_CREAT() | O_TRUNC(), 0o644) fd_write(fd, "hello world") fd_close(fd)
Functions
fn fd_open(path: string, flags: int, mode: int): int
Open a file descriptor
fn fd_close(fd: int): int
Close a file descriptor
fn fd_read(fd: int, max_len: int): string
Read from a file descriptor, returns data as string
fn fd_write(fd: int, data: string): int
Write string data to a file descriptor
fn fd_dup(oldfd: int): int
Duplicate a file descriptor
fn fd_dup2(oldfd: int, newfd: int): int
Duplicate fd to specific number
fn fd_pipe(): option.Option[[int]]
Create a pipe, returns [read_fd, write_fd]
0.9.2 C16: Some([read, write]) or None. This returned an EMPTY ARRAY as its
failure signal, and callers indexed [0]/[1] straight away -- reproduced
under fd exhaustion as array index 1 out of bounds (length 0).
DELIBERATELY NO fd_pipe_or. None means the pipe(2) call FAILED (EMFILE, ENFILE); it is not a missing lookup. Handing back a caller-supplied array would give out file descriptors that were never opened, and the caller would read and write them. Failures are handled, not defaulted.
fn fd_set_nonblocking(fd: int, enable: bool): int
Set non-blocking mode on fd
fn fd_set_cloexec(fd: int, enable: bool): int
Set close-on-exec flag on fd
fn STDIN(): int
Standard file descriptor constants
fn STDOUT(): int
fn STDERR(): int
fn O_RDONLY(): int
Open flag constants
fn O_WRONLY(): int
fn O_RDWR(): int
fn O_CREAT(): int
fn O_TRUNC(): int
fn O_APPEND(): int
fn O_CLOEXEC(): int
Generated by reefc doc