System I/O, files, networking, and processes

FD-based I/O, file systems, sockets/TCP/UDP, process APIs, and their failure contracts.

Wave Foundation

Opening and closing files

import("std::fs::file")::{fs_open_read, fs_close};

fun main() {
    var fd: i64 = fs_open_read("input.txt");
    if (fd >= 0) {
        fs_close(fd);
    }
}

fs_open_read can preserve a negative failure result, so check it before use. fs_close also returns a result; code that cares about close failures should inspect it.

std::io

std::io provides file-descriptor operations for reading, writing, exact-length transfers, seeking, and copying. APIs that accept buffers require the pointer and length to be kept in the same unit and contract.

std::fs

std::fs::file includes helpers for existence checks, opening, closing, size queries, removing files, creating/removing directories, complete reads/writes, and file copying.

var size: i64 = fs_file_size("input.txt");
if (size < 0) {
    println("file error");
}

Networking

std::net is divided into address handling, base sockets, socket options, polling, TCP, and UDP. Network code should explicitly manage:

  • Address family and socket type
  • Port/integer byte order
  • Blocking versus non-blocking state
  • Partial reads and writes
  • Shutdown and error results

Processes

std::process provides source units for process creation, waiting, constants, and standard-stream redirection. Treat successful process creation and the child's eventual exit status as separate results.

Platform dependence

These modules cross the operating-system boundary through std::sys and native calls. Error values, flags, and some structures follow the selected operating system and ABI, so platform-dependent programs should make that target explicit and test it directly.