io

API Reference

Enums

enum IORequest

A low-level operation sent through the ambient 'io effect.

Effects

effect 'io(request: IORequest) -> Int

Sends one low-level request to the nearest I/O handler and returns its integer reply.

Globals

let EPERM: Int

Operation was not permitted by the host.

let ENOENT: Int

The requested file or directory does not exist.

let EIO: Int

The host reported a generic I/O failure.

let EBADF: Int

The supplied file descriptor is invalid.

let EAGAIN: Int

The non-blocking operation would need to wait.

let EACCES: Int

Access to the requested resource was denied.

let EEXIST: Int

Creation failed because the path already exists.

let ENOTDIR: Int

A path component expected to be a directory was not one.

let EISDIR: Int

The operation is invalid for a directory.

let EINVAL: Int

An argument was outside the host operation's valid domain.

let EMFILE: Int

The process has too many open file descriptors.

let ENOSPC: Int

The target device has no space remaining.

let EPIPE: Int

A write targeted a pipe or socket with no reader.

let POLLIN: Int

Poll interest bit for data available to read.

let POLLOUT: Int

Poll interest bit for capacity available to write.

let POLLERR: Int

Poll result bit for an asynchronous descriptor error.

let POLLHUP: Int

Poll result bit for a peer hangup.

let O_RDONLY: Int

Opens a file descriptor for reading only.

let O_WRONLY: Int

Opens a file descriptor for writing only.

let O_RDWR: Int

Opens a file descriptor for both reading and writing.

let O_CREAT: Int

Creates the file when it does not exist.

let O_TRUNC: Int

Truncates an existing file to zero bytes when opened.

let O_APPEND: Int

Directs writes to the end of the file.

let O_NONBLOCK: Int

Makes operations return rather than block waiting for readiness.

let SEEK_SET: Int

Interprets a seek offset relative to the start of the file.

let SEEK_CUR: Int

Interprets a seek offset relative to the current file position.

let SEEK_END: Int

Interprets a seek offset relative to the end of the file.

let S_IRUSR: Int

Grants the owning user permission to read the file.

let S_IWUSR: Int

Grants the owning user permission to write the file.

let S_IXUSR: Int

Grants the owning user permission to execute the file.

let S_IRGRP: Int

Grants the owning group permission to read the file.

let S_IWGRP: Int

Grants the owning group permission to write the file.

let S_IXGRP: Int

Grants the owning group permission to execute the file.

let S_IROTH: Int

Grants other users permission to read the file.

let S_IWOTH: Int

Grants other users permission to write the file.

let S_IXOTH: Int

Grants other users permission to execute the file.

let STDIN_FD: Int

The process's standard-input file descriptor.

let STDOUT_FD: Int

The process's standard-output file descriptor.

let STDERR_FD: Int

The process's standard-error file descriptor.

Functions

func _io_open(path: RawPtr, flags: Int, mode: Int) 'io -> Int

Low-level open for raw pointers. path is expected to point to a NUL-terminated C string.

func open_path(path: String, flags: Int, mode: Int) '[io, alloc] -> Int

High-level open for Talk strings: copy the path into fresh memory with a NUL terminator (allocations are zero-filled, so the terminator comes free) and open through the C-string path.

func _io_read(fd: Int, buf: RawPtr, count: Int) 'io -> Int

Reads up to count bytes from fd into buf; returns a count or negative errno.

func _io_write(fd: Int, buf: RawPtr, count: Int) 'io -> Int

Writes up to count bytes from buf to fd; returns a count or negative errno.

func _io_cwd_len() 'io -> Int

Returns the byte length of the current working directory, or a negative errno.

func _io_cwd_copy(buf: RawPtr) 'io -> Int

Copies the current working directory into buf; returns bytes copied or a negative errno.

func _io_getenv_len(name: RawPtr, name_len: Int) 'io -> Int

Returns an environment value's byte length, or a negative errno when unavailable.

func _io_argc() 'io -> Int

Returns the number of process arguments supplied by the host.

func _io_arg_len(index: Int) 'io -> Int

Returns the byte length of argument index, or a negative errno.

func _io_dir_count(path: RawPtr) 'io -> Int

Counts entries in the NUL-terminated directory path, or returns a negative errno.

func _io_realpath_len(path: RawPtr) 'io -> Int

Canonicalize a NUL-terminated path (resolving ".", "..", and symlinks, like POSIX realpath): the resolved byte length or a negative errno. Pair with iorealpath_copy.

func _io_seek(fd: Int, offset: Int, whence: Int) 'io -> Int

Move a descriptor's file offset (POSIX lseek): the new absolute offset or a negative errno. whence is SEEKSET, SEEKCUR, or SEEK_END.

func _io_file_size(fd: Int) 'io -> Int

The byte size of the file behind a descriptor (POSIX fstat), or a negative errno.

func _io_monotonic_nanos() 'io -> Int

Monotonic nanoseconds from an arbitrary per-process anchor (the clock behind core Instant.now). Only deltas between two reads are meaningful.

func _io_exit(code: Int) 'io -> Never

Terminates the process with code; this operation never resumes.

func _io_ctl(fd: Int, op: Int, arg: Int) 'io -> Int

Sends runtime control operation op and integer arg to fd.

func _io_poll(fds: RawPtr, count: Int, timeout: Int) 'io -> Int

Polls count descriptor records until readiness or timeout milliseconds.

func is_error(result: Int) -> Bool

Returns whether a host result is a negative errno value.

func _io_clamp(count: Int, capacity: Int) -> Int

'io replies are untrusted for memory safety: a user handler may intercept any request (ADR 0039), so a count is clamped to the capacity the caller actually allocated before it becomes a view's length. A lying handler yields wrong data, never an out-of-bounds view. _io_clamp(n, n) sanitizes a bare length (negative becomes 0).

func print<T: Showable>(_ value: T) -> ()

Displays value on standard output followed by a newline.