Standard Library: I/O

std.io wraps the two POSIX-shaped intrinsics __mind_read and __mind_write into a small file-handle module written in pure MIND. There is no buffered I/O, no global state, and no implicit allocations — every entry point is a thin layer over the syscall surface.

Availability: first shipped with mindc 0.4.0+; as of mindc 0.7.1 the std-surface layer is the shipped default (no opt-in flag).

File handle

File is a one-field heap record holding the OS file descriptor:

pub struct File {
    fd: i64,
}

Public API

  • stdin() -> File — standard input.
  • stdout() -> File — standard output.
  • stderr() -> File — standard error.
  • print_bytes(buf: i64, len: i64) -> i64 — write to stdout.
  • eprint_bytes(buf: i64, len: i64) -> i64 — write to stderr.
  • read_stdin_bytes(buf: i64, len: i64) -> i64 — read from stdin.
  • file_open(...) -> File — open path with O_RDONLY semantics.
  • file_close(f: File) -> i64 — close descriptor.
  • file_read_all(f: File) -> (i64, i64) — read entire file.

All errors surface as a negative return value (negated errno). The module never silently swallows them — that is a spec-level requirement, not a convention.

Intrinsics

std.io bottoms out in exactly two host-supplied intrinsics:

  • __mind_read(fd: i64, buf: i64, count: i64) -> i64
  • __mind_write(fd: i64, buf: i64, count: i64) -> i64

Both follow the POSIX read(2) / write(2) contract: return the byte count on success, or a negative value carrying -errno on failure.

Forking for sandboxed I/O (Phase D)

A deployment that needs sandboxed I/O — e.g. write-allowlist enforcement, audit logging on every __mind_write— can ship its own io.mind and point MIND_STDLIB_PATH=path at it. The project loader swaps the bundled blob at parse time without recompiling mindc. Shipped in v0.4.3 (RFC 0005 Phase D₁); see std.vec for the full override contract.