Landin library reference source

platform/posix

Target scope is enforced by the module assertion below.

POSIX's facilities in Landin types, on Linux, Darwin and FreeBSD alike.

A descriptor is a handle type, not a number to count with, so descriptors compare with == and nothing else; standard_input, standard_output and standard_error are 0, 1 and 2, and working_directory is the directory an *_at call's relative path starts from. A failure is the errno as an atom of errno, one atom for each errno the three systems define, named after its C macro in lower case, enoent and eintr among them; number gives the number this system uses for an atom and errno_of the atom for a number, and unlisted is a failure with no errno this module names. A path or an argument is a host string, which the module copies into a buffer of the system's PATH_MAX with the NUL a C call needs, refusing one that holds a NUL with einval and one too long with enametoolong. The calls are POSIX's own, not policy: open_at with open_options (reading and writing are the two the hosted provider uses), read, write, close, status_at for a structured status of device, inode, kind and size, open_directory, read_directory and close_directory over a caller's buffer, listing . and .. as POSIX does, make_directory_at, unlink_at and remove_directory_at, map and unmap for anonymous memory and page_size, exit, and poll over entries made by watch and read by happened, whose poll_events is a distinct flag set: poll_input, poll_output and poll_urgent are asked about, poll_error, poll_hung_up and poll_invalid only reported, combined with | and tested with & against poll_no_events. An interrupted call fails with eintr and is not retried here, and a short transfer is returned as it came. The process's arguments are its root, established by _landin_host_initialize_arguments and read through arguments and argument. It is written twice beneath its interface, over platform/linux's system calls and over platform/libc, and a system that is not POSIX, as Windows is not, has none.

compiler.assert(compiler.os == linux or compiler.os == darwin
                or compiler.os == freebsd)

Items

Executable example

This complete program is maintained in the repository runtime tests. View source.

--  platform/posix's files: a descriptor is a handle, a failure is the
--  errno as an atom, and a path is a host string, terminated beneath the
--  caller.  The program makes a scratch directory, opens a file in it
--  relative to the directory's own descriptor, writes and reads it back,
--  asks its status, and removes both.  Each failure is the errno POSIX
--  names for it, the same atom on Linux, Darwin and FreeBSD: a missing
--  name, an exclusive create of a taken one, a file used as a directory, a
--  directory opened for writing, a closed descriptor, a path holding a NUL
--  and one longer than PATH_MAX.  The program writes each atom's number
--  on this system, so a failing lane shows what it met.
import core/text
import platform/posix

top: []u8 = "posix-files-scratch"
inner: []u8 = "posix-files-scratch/data"

--  Write LINE to standard output.
say: (line: []u8) -> none =
    _ = posix.write(posix.standard_output, line) else 0
end say

--  Write NAME, `=` and the number PROBLEM has on this system.
said: (name: []u8, problem: posix.errno) -> none =
    mut line: [32]u8 = zeroed
    mut used: usize = 0
    for byte in name do
        line[used] = byte
        inc used
    end for
    line[used] = 61
    inc used
    used = text.write_u32(line[0..<32], used,
                          u32(posix.number(problem))) else used
    line[used] = 10
    say(line[0..<used + 1])
end said

--  Remove what an earlier run may have left.
clear: () -> none =
    posix.unlink_at(posix.working_directory, text.host_over(inner)) else (p)
        _ = p
    end
    posix.remove_directory_at(posix.working_directory,
                              text.host_over(top)) else (p)
        _ = p
    end
end clear

--  Whether opening PATH with OPTIONS, relative to AT, fails with WANTED.
refused: (at: posix.descriptor, path: text.host_string,
          options: posix.open_options, wanted: posix.errno, name: []u8)
         -> (yes: bool) =
    yes = false
    opened: posix.descriptor = posix.open_at(at, path, options, 0o644)
      else (problem)
        said(name, problem)
        yes = problem == wanted
        return
    end
    posix.close(opened) else (p)
        _ = p
    end
end refused

public main: () -> (code: i32) =
    clear()
    code = 1
    posix.make_directory_at(posix.working_directory, text.host_over(top),
                            0o755) else (problem)
        said("mkdir", problem)
        return
    end
    code = 2
    folder: posix.descriptor =
        posix.open_at(posix.working_directory, text.host_over(top),
                      (access: posix.read_only, create: false,
                       exclusive: false, truncate: false, append: false,
                       directory: true), 0) else (problem)
        said("folder", problem)
        return
    end

    --  A file made relative to the directory's descriptor, written and
    --  read back through a second descriptor.
    code = 3
    written: posix.descriptor =
        posix.open_at(folder, text.host_over("data"), posix.writing,
                      0o644) else (problem)
        said("create", problem)
        return
    end
    count: usize = posix.write(written, "posix\n") else (problem)
        said("write", problem)
        return
    end
    return when count <> 6
    posix.close(written) else (problem)
        said("close", problem)
        return
    end
    code = 4
    reading: posix.descriptor =
        posix.open_at(posix.working_directory, text.host_over(inner),
                      posix.reading, 0) else (problem)
        said("open", problem)
        return
    end
    mut buffer: [16]u8 = zeroed
    got: usize = posix.read(reading, buffer[0..<16]) else (problem)
        said("read", problem)
        return
    end
    return when got <> 6 or buffer[0] <> 112 or buffer[5] <> 10
    ended: usize = posix.read(reading, buffer[0..<16]) else (problem)
        said("eof", problem)
        return
    end
    return when ended <> 0
    posix.close(reading) else (problem)
        said("close", problem)
        return
    end

    --  Its status: a regular file of six bytes, the same file by either
    --  path, inside a directory.
    code = 5
    file: posix.status =
        posix.status_at(folder, text.host_over("data"), false) else (problem)
        said("stat", problem)
        return
    end
    again: posix.status =
        posix.status_at(posix.working_directory, text.host_over(inner),
                        true) else (problem)
        said("stat", problem)
        return
    end
    holder: posix.status =
        posix.status_at(posix.working_directory, text.host_over(top),
                        true) else (problem)
        said("stat", problem)
        return
    end
    return when file.kind <> posix.regular or file.size <> 6
      or file.device <> again.device or file.inode <> again.inode
      or holder.kind <> posix.directory or holder.inode == file.inode

    --  The failure oracles.
    code = 6
    return when not refused(folder, text.host_over("absent"), posix.reading,
                            posix.enoent, "absent")
    code = 7
    return when not refused(folder, text.host_over("data"),
                            (access: posix.write_only, create: true,
                             exclusive: true, truncate: false,
                             append: false, directory: false),
                            posix.eexist, "exclusive")
    code = 8
    return when not refused(folder, text.host_over("data/below"),
                            posix.reading, posix.enotdir, "through")
    code = 9
    return when not refused(posix.working_directory, text.host_over(top),
                            posix.writing, posix.eisdir, "directory")
    code = 10
    return when not refused(posix.working_directory,
                            text.host_over("posix\x00files"), posix.reading,
                            posix.einval, "nul")
    code = 11
    long: [5000]u8 = [5000 of 97]
    return when not refused(posix.working_directory,
                            text.host_over(long[0..<5000]), posix.reading,
                            posix.enametoolong, "long")
    code = 12
    _ = posix.read(reading, buffer[0..<16]) else (problem)
        said("closed", problem)
        return when problem <> posix.ebadf
        0
    end

    code = 13
    posix.close(folder) else (problem)
        said("close", problem)
        return
    end
    posix.unlink_at(posix.working_directory, text.host_over(inner))
      else (problem)
        said("unlink", problem)
        return
    end
    posix.remove_directory_at(posix.working_directory, text.host_over(top))
      else (problem)
        said("rmdir", problem)
        return
    end
    code = 42
end main

access type

public access: type = read_only | write_only | read_write

platform/posix/posix.ldn:67

How an open file may be used: read_only, write_only or read_write.

argument_table type

public argument_table: type = struct
    values: ptr ptr u8
    count: usize
end argument_table

platform/posix/posix.ldn:417

The process's arguments as its entry gave them: argv after argv[0] and their count. arguments gives the table, which lends what it points to from storage the process keeps, and argument reads it.

descriptor type

public descriptor: type = descriptor_value

platform/posix/posix.ldn:31

An open file's descriptor: a handle the system gives, which names one open file until it is closed. It is a handle and not a number to count with; descriptor(n) and i32(d) convert at a C boundary.

directory_entry type

public directory_entry: type = struct
    name: text.host_string
    kind: file_kind
end directory_entry

platform/posix/posix.ldn:198

An entry of a directory: its name, lent from the buffer it was read into until the next read, and its kind, unknown_kind where the file system records none.

directory_stream type

public directory_stream: type = struct
    descriptor: descriptor
    stream: usize
    filled: usize
    cursor: usize
    finished: bool
end directory_stream

platform/posix/posix.ldn:187

An open directory stream, POSIX's DIR: a value its caller keeps and passes inout to read_directory, with the same buffer each time. Its fields belong to this module: the directory's descriptor, the C library's stream where there is one, and how much of the buffer the system has filled and the caller has read.

errno type

public errno: type = eperm | enoent | esrch | eintr | eio | enxio | e2big

platform/posix/errno.ldn:330

Every failure a POSIX call here reports: the errno it failed with, as an atom, or unlisted. number gives the errno's number on this system and errno_of the atom for a number.

file_kind type

public file_kind: type = regular | directory | symbolic_link | fifo

platform/posix/posix.ldn:151

What a file is.

open_options type

public open_options: type = struct
    access: access
    create: bool
    exclusive: bool
    truncate: bool
    append: bool
    directory: bool
end open_options

platform/posix/posix.ldn:73

How open_at opens a file: its access, and whether to create it when it is missing, refuse it when it exists (exclusive, with create), truncate it, append every write to its end, or refuse anything that is not a directory with enotdir.

poll_entry type

public poll_entry: type = poll_record

platform/posix/posix.ldn:331

One descriptor for poll to watch and the events asked about, made by watch, and after the call what happened, which happened reads.

poll_events type

public poll_events: type = events_value

platform/posix/posix.ldn:303

Poll events, POSIX's poll bits as a set: a value combines with |, & and ~ and compares with == and <>. poll_input, poll_output and poll_urgent are what an entry can ask about; poll_error, poll_hung_up and poll_invalid are only ever reported. The bits are the same on Linux, Darwin and FreeBSD.

status type

public status: type = struct
    device: u64
    inode: u64
    kind: file_kind
    size: u64
end status

platform/posix/posix.ldn:160

A file's status, POSIX's stat: the device and inode that identify it, what it is and its size in bytes. On Linux the device is the kernel's major number in the upper 32 bits and its minor in the lower, as statx reports them; elsewhere it is the system's st_dev. Two paths name the same file when both identify it alike.

block_device atom

public block_device: atom

platform/posix/posix.ldn:146

A block device.

character_device atom

public character_device: atom

platform/posix/posix.ldn:144

A character device.

directory atom

public directory: atom

platform/posix/posix.ldn:136

A directory.

e2big atom

public e2big: atom

platform/posix/errno.ldn:31

errno E2BIG: Argument list too long.

eacces atom

public eacces: atom

platform/posix/errno.ldn:43

errno EACCES: Permission denied.

eaddrinuse atom

public eaddrinuse: atom

platform/posix/errno.ldn:209

errno EADDRINUSE: Address already in use.

eaddrnotavail atom

public eaddrnotavail: atom

platform/posix/errno.ldn:211

errno EADDRNOTAVAIL: Cannot assign requested address.

eadv atom

public eadv: atom

platform/posix/errno.ldn:149

errno EADV: Advertise error.

eafnosupport atom

public eafnosupport: atom

platform/posix/errno.ldn:207

errno EAFNOSUPPORT: Address family not supported by protocol.

eagain atom

public eagain: atom

platform/posix/errno.ldn:39

errno EAGAIN: Try again.

ealready atom

public ealready: atom

platform/posix/errno.ldn:241

errno EALREADY: Operation already in progress.

eauth atom

public eauth: atom

platform/posix/errno.ldn:281

errno EAUTH: Authentication error.

ebadarch atom

public ebadarch: atom

platform/posix/errno.ldn:283

errno EBADARCH: Bad CPU type in executable.

ebade atom

public ebade: atom

platform/posix/errno.ldn:119

errno EBADE: Invalid exchange.

ebadexec atom

public ebadexec: atom

platform/posix/errno.ldn:285

errno EBADEXEC: Bad executable (or shared library).

ebadf atom

public ebadf: atom

platform/posix/errno.ldn:35

errno EBADF: Bad file number.

ebadfd atom

public ebadfd: atom

platform/posix/errno.ldn:167

errno EBADFD: File descriptor in bad state.

ebadmacho atom

public ebadmacho: atom

platform/posix/errno.ldn:287

errno EBADMACHO: Malformed Mach-o file.

ebadmsg atom

public ebadmsg: atom

platform/posix/errno.ldn:161

errno EBADMSG: Not a data message.

ebadr atom

public ebadr: atom

platform/posix/errno.ldn:121

errno EBADR: Invalid request descriptor.

ebadrpc atom

public ebadrpc: atom

platform/posix/errno.ldn:289

errno EBADRPC: RPC struct is bad.

ebadrqc atom

public ebadrqc: atom

platform/posix/errno.ldn:127

errno EBADRQC: Invalid request code.

ebadslt atom

public ebadslt: atom

platform/posix/errno.ldn:129

errno EBADSLT: Invalid slot.

ebfont atom

public ebfont: atom

platform/posix/errno.ldn:131

errno EBFONT: Bad font file format.

ebusy atom

public ebusy: atom

platform/posix/errno.ldn:49

errno EBUSY: Device or resource busy.

ecanceled atom

public ecanceled: atom

platform/posix/errno.ldn:263

errno ECANCELED: Operation Canceled.

ecapmode atom

public ecapmode: atom

platform/posix/errno.ldn:291

errno ECAPMODE: Not permitted in capability mode.

echild atom

public echild: atom

platform/posix/errno.ldn:37

errno ECHILD: No child processes.

echrng atom

public echrng: atom

platform/posix/errno.ldn:103

errno ECHRNG: Channel number out of range.

ecomm atom

public ecomm: atom

platform/posix/errno.ldn:153

errno ECOMM: Communication error on send.

econnaborted atom

public econnaborted: atom

platform/posix/errno.ldn:219

errno ECONNABORTED: Software caused connection abort.

econnrefused atom

public econnrefused: atom

platform/posix/errno.ldn:235

errno ECONNREFUSED: Connection refused.

econnreset atom

public econnreset: atom

platform/posix/errno.ldn:221

errno ECONNRESET: Connection reset by peer.

edeadlk atom

public edeadlk: atom

platform/posix/errno.ldn:87

errno EDEADLK: Resource deadlock would occur.

edestaddrreq atom

public edestaddrreq: atom

platform/posix/errno.ldn:191

errno EDESTADDRREQ: Destination address required.

edeverr atom

public edeverr: atom

platform/posix/errno.ldn:293

errno EDEVERR: Device error.

edom atom

public edom: atom

platform/posix/errno.ldn:83

errno EDOM: Math argument out of domain of func.

edoofus atom

public edoofus: atom

platform/posix/errno.ldn:295

errno EDOOFUS: Programming error.

edotdot atom

public edotdot: atom

platform/posix/errno.ldn:159

errno EDOTDOT: RFS specific error.

edquot atom

public edquot: atom

platform/posix/errno.ldn:257

errno EDQUOT: Quota exceeded.

eexist atom

public eexist: atom

platform/posix/errno.ldn:51

errno EEXIST: File exists.

efault atom

public efault: atom

platform/posix/errno.ldn:45

errno EFAULT: Bad address.

efbig atom

public efbig: atom

platform/posix/errno.ldn:71

errno EFBIG: File too large.

eftype atom

public eftype: atom

platform/posix/errno.ldn:297

errno EFTYPE: Inappropriate file type or format.

ehostdown atom

public ehostdown: atom

platform/posix/errno.ldn:237

errno EHOSTDOWN: Host is down.

ehostunreach atom

public ehostunreach: atom

platform/posix/errno.ldn:239

errno EHOSTUNREACH: No route to host.

ehwpoison atom

public ehwpoison: atom

platform/posix/errno.ldn:279

errno EHWPOISON: Memory page has hardware error.

eidrm atom

public eidrm: atom

platform/posix/errno.ldn:101

errno EIDRM: Identifier removed.

eilseq atom

public eilseq: atom

platform/posix/errno.ldn:181

errno EILSEQ: Illegal byte sequence.

einprogress atom

public einprogress: atom

platform/posix/errno.ldn:243

errno EINPROGRESS: Operation now in progress.

eintegrity atom

public eintegrity: atom

platform/posix/errno.ldn:299

errno EINTEGRITY: Integrity check failed.

eintr atom

public eintr: atom

platform/posix/errno.ldn:25

errno EINTR: Interrupted system call.

einval atom

public einval: atom

platform/posix/errno.ldn:61

errno EINVAL: Invalid argument.

eio atom

public eio: atom

platform/posix/errno.ldn:27

errno EIO: I/O error.

eisconn atom

public eisconn: atom

platform/posix/errno.ldn:225

errno EISCONN: Transport endpoint is already connected.

eisdir atom

public eisdir: atom

platform/posix/errno.ldn:59

errno EISDIR: Is a directory.

eisnam atom

public eisnam: atom

platform/posix/errno.ldn:253

errno EISNAM: Is a named type file.

ekeyexpired atom

public ekeyexpired: atom

platform/posix/errno.ldn:267

errno EKEYEXPIRED: Key has expired.

ekeyrejected atom

public ekeyrejected: atom

platform/posix/errno.ldn:271

errno EKEYREJECTED: Key was rejected by service.

ekeyrevoked atom

public ekeyrevoked: atom

platform/posix/errno.ldn:269

errno EKEYREVOKED: Key has been revoked.

el2hlt atom

public el2hlt: atom

platform/posix/errno.ldn:117

errno EL2HLT: Level 2 halted.

el2nsync atom

public el2nsync: atom

platform/posix/errno.ldn:105

errno EL2NSYNC: Level 2 not synchronized.

el3hlt atom

public el3hlt: atom

platform/posix/errno.ldn:107

errno EL3HLT: Level 3 halted.

el3rst atom

public el3rst: atom

platform/posix/errno.ldn:109

errno EL3RST: Level 3 reset.

elibacc atom

public elibacc: atom

platform/posix/errno.ldn:171

errno ELIBACC: Can not access a needed shared library.

elibbad atom

public elibbad: atom

platform/posix/errno.ldn:173

errno ELIBBAD: Accessing a corrupted shared library.

elibexec atom

public elibexec: atom

platform/posix/errno.ldn:179

errno ELIBEXEC: Cannot exec a shared library directly.

elibmax atom

public elibmax: atom

platform/posix/errno.ldn:177

errno ELIBMAX: Attempting to link in too many shared libraries.

elibscn atom

public elibscn: atom

platform/posix/errno.ldn:175

errno ELIBSCN: .lib section in a.out corrupted.

elnrng atom

public elnrng: atom

platform/posix/errno.ldn:111

errno ELNRNG: Link number out of range.

eloop atom

public eloop: atom

platform/posix/errno.ldn:97

errno ELOOP: Too many symbolic links encountered.

emediumtype atom

public emediumtype: atom

platform/posix/errno.ldn:261

errno EMEDIUMTYPE: Wrong medium type.

emfile atom

public emfile: atom

platform/posix/errno.ldn:65

errno EMFILE: Too many open files.

emsgsize atom

public emsgsize: atom

platform/posix/errno.ldn:193

errno EMSGSIZE: Message too long.

emultihop atom

public emultihop: atom

platform/posix/errno.ldn:157

errno EMULTIHOP: Multihop attempted.

enametoolong atom

public enametoolong: atom

platform/posix/errno.ldn:89

errno ENAMETOOLONG: File name too long.

enavail atom

public enavail: atom

platform/posix/errno.ldn:251

errno ENAVAIL: No XENIX semaphores available.

eneedauth atom

public eneedauth: atom

platform/posix/errno.ldn:301

errno ENEEDAUTH: Need authenticator.

enetdown atom

public enetdown: atom

platform/posix/errno.ldn:213

errno ENETDOWN: Network is down.

enetreset atom

public enetreset: atom

platform/posix/errno.ldn:217

errno ENETRESET: Network dropped connection because of reset.

enetunreach atom

public enetunreach: atom

platform/posix/errno.ldn:215

errno ENETUNREACH: Network is unreachable.

enfile atom

public enfile: atom

platform/posix/errno.ldn:63

errno ENFILE: File table overflow.

enoano atom

public enoano: atom

platform/posix/errno.ldn:125

errno ENOANO: No anode.

enoattr atom

public enoattr: atom

platform/posix/errno.ldn:303

errno ENOATTR: Attribute not found.

enobufs atom

public enobufs: atom

platform/posix/errno.ldn:223

errno ENOBUFS: No buffer space available.

enocsi atom

public enocsi: atom

platform/posix/errno.ldn:115

errno ENOCSI: No CSI structure available.

enodata atom

public enodata: atom

platform/posix/errno.ldn:135

errno ENODATA: No data available.

enodev atom

public enodev: atom

platform/posix/errno.ldn:55

errno ENODEV: No such device.

enoent atom

public enoent: atom

platform/posix/errno.ldn:21

errno ENOENT: No such file or directory.

enoexec atom

public enoexec: atom

platform/posix/errno.ldn:33

errno ENOEXEC: Exec format error.

enokey atom

public enokey: atom

platform/posix/errno.ldn:265

errno ENOKEY: Required key not available.

enolck atom

public enolck: atom

platform/posix/errno.ldn:91

errno ENOLCK: No record locks available.

enomedium atom

public enomedium: atom

platform/posix/errno.ldn:259

errno ENOMEDIUM: No medium found.

enomem atom

public enomem: atom

platform/posix/errno.ldn:41

errno ENOMEM: Out of memory.

enomsg atom

public enomsg: atom

platform/posix/errno.ldn:99

errno ENOMSG: No message of desired type.

enonet atom

public enonet: atom

platform/posix/errno.ldn:141

errno ENONET: Machine is not on the network.

enopkg atom

public enopkg: atom

platform/posix/errno.ldn:143

errno ENOPKG: Package not installed.

enopolicy atom

public enopolicy: atom

platform/posix/errno.ldn:305

errno ENOPOLICY: Policy not found.

enoprotoopt atom

public enoprotoopt: atom

platform/posix/errno.ldn:197

errno ENOPROTOOPT: Protocol not available.

enospc atom

public enospc: atom

platform/posix/errno.ldn:73

errno ENOSPC: No space left on device.

enosr atom

public enosr: atom

platform/posix/errno.ldn:139

errno ENOSR: Out of streams resources.

enostr atom

public enostr: atom

platform/posix/errno.ldn:133

errno ENOSTR: Device not a stream.

enosys atom

public enosys: atom

platform/posix/errno.ldn:93

errno ENOSYS: Invalid system call number.

enotblk atom

public enotblk: atom

platform/posix/errno.ldn:47

errno ENOTBLK: Block device required.

enotcapable atom

public enotcapable: atom

platform/posix/errno.ldn:307

errno ENOTCAPABLE: Capabilities insufficient.

enotconn atom

public enotconn: atom

platform/posix/errno.ldn:227

errno ENOTCONN: Transport endpoint is not connected.

enotdir atom

public enotdir: atom

platform/posix/errno.ldn:57

errno ENOTDIR: Not a directory.

enotempty atom

public enotempty: atom

platform/posix/errno.ldn:95

errno ENOTEMPTY: Directory not empty.

enotnam atom

public enotnam: atom

platform/posix/errno.ldn:249

errno ENOTNAM: Not a XENIX named type file.

enotrecoverable atom

public enotrecoverable: atom

platform/posix/errno.ldn:275

errno ENOTRECOVERABLE: State not recoverable.

enotsock atom

public enotsock: atom

platform/posix/errno.ldn:189

errno ENOTSOCK: Socket operation on non-socket.

enotsup atom

public enotsup: atom

platform/posix/errno.ldn:309

errno ENOTSUP: Operation not supported.

enotty atom

public enotty: atom

platform/posix/errno.ldn:67

errno ENOTTY: Not a typewriter.

enotuniq atom

public enotuniq: atom

platform/posix/errno.ldn:165

errno ENOTUNIQ: Name not unique on network.

enxio atom

public enxio: atom

platform/posix/errno.ldn:29

errno ENXIO: No such device or address.

eopnotsupp atom

public eopnotsupp: atom

platform/posix/errno.ldn:203

errno EOPNOTSUPP: Operation not supported on transport endpoint.

eoverflow atom

public eoverflow: atom

platform/posix/errno.ldn:163

errno EOVERFLOW: Value too large for defined data type.

eownerdead atom

public eownerdead: atom

platform/posix/errno.ldn:273

errno EOWNERDEAD: Owner died.

eperm atom

public eperm: atom

platform/posix/errno.ldn:19

errno EPERM: Operation not permitted.

epfnosupport atom

public epfnosupport: atom

platform/posix/errno.ldn:205

errno EPFNOSUPPORT: Protocol family not supported.

epipe atom

public epipe: atom

platform/posix/errno.ldn:81

errno EPIPE: Broken pipe.

eproclim atom

public eproclim: atom

platform/posix/errno.ldn:311

errno EPROCLIM: Too many processes.

eprocunavail atom

public eprocunavail: atom

platform/posix/errno.ldn:313

errno EPROCUNAVAIL: Bad procedure for program.

eprogmismatch atom

public eprogmismatch: atom

platform/posix/errno.ldn:315

errno EPROGMISMATCH: Program version wrong.

eprogunavail atom

public eprogunavail: atom

platform/posix/errno.ldn:317

errno EPROGUNAVAIL: RPC prog. not avail.

eproto atom

public eproto: atom

platform/posix/errno.ldn:155

errno EPROTO: Protocol error.

eprotonosupport atom

public eprotonosupport: atom

platform/posix/errno.ldn:199

errno EPROTONOSUPPORT: Protocol not supported.

eprototype atom

public eprototype: atom

platform/posix/errno.ldn:195

errno EPROTOTYPE: Protocol wrong type for socket.

epwroff atom

public epwroff: atom

platform/posix/errno.ldn:319

errno EPWROFF: Device power is off.

eqfull atom

public eqfull: atom

platform/posix/errno.ldn:321

errno EQFULL: Interface output queue is full.

erange atom

public erange: atom

platform/posix/errno.ldn:85

errno ERANGE: Math result not representable.

eremchg atom

public eremchg: atom

platform/posix/errno.ldn:169

errno EREMCHG: Remote address changed.

eremote atom

public eremote: atom

platform/posix/errno.ldn:145

errno EREMOTE: Object is remote.

eremoteio atom

public eremoteio: atom

platform/posix/errno.ldn:255

errno EREMOTEIO: Remote I/O error.

erestart atom

public erestart: atom

platform/posix/errno.ldn:183

errno ERESTART: Interrupted system call should be restarted.

erfkill atom

public erfkill: atom

platform/posix/errno.ldn:277

errno ERFKILL: Operation not possible due to RF-kill.

erofs atom

public erofs: atom

platform/posix/errno.ldn:77

errno EROFS: Read-only file system.

erpcmismatch atom

public erpcmismatch: atom

platform/posix/errno.ldn:323

errno ERPCMISMATCH: RPC version wrong.

eshlibvers atom

public eshlibvers: atom

platform/posix/errno.ldn:325

errno ESHLIBVERS: Shared library version mismatch.

eshutdown atom

public eshutdown: atom

platform/posix/errno.ldn:229

errno ESHUTDOWN: Cannot send after transport endpoint shutdown.

esocktnosupport atom

public esocktnosupport: atom

platform/posix/errno.ldn:201

errno ESOCKTNOSUPPORT: Socket type not supported.

espipe atom

public espipe: atom

platform/posix/errno.ldn:75

errno ESPIPE: Illegal seek.

esrch atom

public esrch: atom

platform/posix/errno.ldn:23

errno ESRCH: No such process.

esrmnt atom

public esrmnt: atom

platform/posix/errno.ldn:151

errno ESRMNT: Srmount error.

estale atom

public estale: atom

platform/posix/errno.ldn:245

errno ESTALE: Stale file handle.

estrpipe atom

public estrpipe: atom

platform/posix/errno.ldn:185

errno ESTRPIPE: Streams pipe error.

etime atom

public etime: atom

platform/posix/errno.ldn:137

errno ETIME: Timer expired.

etimedout atom

public etimedout: atom

platform/posix/errno.ldn:233

errno ETIMEDOUT: Connection timed out.

etoomanyrefs atom

public etoomanyrefs: atom

platform/posix/errno.ldn:231

errno ETOOMANYREFS: Too many references: cannot splice.

etxtbsy atom

public etxtbsy: atom

platform/posix/errno.ldn:69

errno ETXTBSY: Text file busy.

euclean atom

public euclean: atom

platform/posix/errno.ldn:247

errno EUCLEAN: Structure needs cleaning.

eunatch atom

public eunatch: atom

platform/posix/errno.ldn:113

errno EUNATCH: Protocol driver not attached.

eusers atom

public eusers: atom

platform/posix/errno.ldn:187

errno EUSERS: Too many users.

exdev atom

public exdev: atom

platform/posix/errno.ldn:53

errno EXDEV: Cross-device link.

exfull atom

public exfull: atom

platform/posix/errno.ldn:123

errno EXFULL: Exchange full.

fifo atom

public fifo: atom

platform/posix/posix.ldn:140

A FIFO, a named pipe.

read_only atom

public read_only: atom

platform/posix/posix.ldn:60

Open for reading only.

read_write atom

public read_write: atom

platform/posix/posix.ldn:64

Open for reading and writing.

regular atom

public regular: atom

platform/posix/posix.ldn:134

A regular file.

socket_file atom

public socket_file: atom

platform/posix/posix.ldn:142

A socket: socket_file, since socket is the name of a call.

unknown_kind atom

public unknown_kind: atom

platform/posix/posix.ldn:149

A kind the system did not say: a directory entry whose file system records none, which status_at then tells.

unlisted atom

public unlisted: atom

platform/posix/errno.ldn:16

A failure no errno this module names describes: a number newer than its tables, or a record the system filled that could not be read. Its number is zero.

write_only atom

public write_only: atom

platform/posix/posix.ldn:62

Open for writing only.

directory_buffer value

public directory_buffer: usize = 1024

platform/posix/posix.ldn:180

The least a buffer read_directory reads into holds: room for any entry any of the three systems gives, its record and its NUL included.

poll_error value

public poll_error: poll_events = events_value(8)

platform/posix/posix.ldn:314

An error on the file.

poll_hung_up value

public poll_hung_up: poll_events = events_value(16)

platform/posix/posix.ldn:316

The peer has gone.

poll_input value

public poll_input: poll_events = events_value(1)

platform/posix/posix.ldn:308

Data to read, or the end of a file.

poll_invalid value

public poll_invalid: poll_events = events_value(32)

platform/posix/posix.ldn:318

A descriptor that is not open.

poll_no_events value

public poll_no_events: poll_events = events_value(0)

platform/posix/posix.ldn:306

No event.

poll_output value

public poll_output: poll_events = events_value(4)

platform/posix/posix.ldn:312

Room to write.

poll_urgent value

public poll_urgent: poll_events = events_value(2)

platform/posix/posix.ldn:310

Out-of-band data to read.

reading value

public reading: open_options = (access: read_only, create: false,

platform/posix/posix.ldn:83

The options for reading an existing file.

standard_error value

public standard_error: descriptor = descriptor_value(2)

platform/posix/posix.ldn:38

Standard error, descriptor 2.

standard_input value

public standard_input: descriptor = descriptor_value(0)

platform/posix/posix.ldn:34

Standard input, descriptor 0.

standard_output value

public standard_output: descriptor = descriptor_value(1)

platform/posix/posix.ldn:36

Standard output, descriptor 1.

working_directory value

When compiler.os == darwin

public working_directory: descriptor = descriptor_value(-2)

platform/posix/posix.ldn:43

The working directory as the directory an *_at call's relative path is relative to: C's AT_FDCWD, which is no open file.

When not (compiler.os == darwin) and (compiler.os == freebsd)

public working_directory: descriptor = descriptor_value(-100)

platform/posix/posix.ldn:50

The working directory as the directory an *_at call's relative path is relative to: C's AT_FDCWD, which is no open file.

When not (compiler.os == darwin or compiler.os == freebsd)

public working_directory: descriptor = descriptor_value(-100)

platform/posix/posix.ldn:55

The working directory as the directory an *_at call's relative path is relative to: C's AT_FDCWD, which is no open file.

writing value

public writing: open_options = (access: write_only, create: true,

platform/posix/posix.ldn:89

The options for writing a file from its start, creating it when it is missing and truncating it when it is not.

_landin_host_initialize_arguments function

public extern(c) _landin_host_initialize_arguments:
    (count: i32, escaping values: ptr ptr u8) -> none

platform/posix/posix.ldn:388

Establish the process's argument root from C's main carriers. The hosted entry calls this with its own argc and argv before its body runs; a C main that drives Landin exports calls it itself, before it reads an argument and before starting a thread that may.

The first call needs a nonnegative count and a non-null table, and keeps that exact pair without copying: the caller keeps the table and its strings readable while any argument lent from them is in use. Repeating the identical pair changes nothing; a negative count, a null table or a different pair traps. The published arguments omit argv[0], so their count is max(argc - 1, 0).

argument function

public link(symbol: "_landin_posix_argument") argument:
    (table: argument_table, index: usize)
    -> (value: text.host_string from table)

platform/posix/posix.ldn:442

The argument index, from zero, as a host string lending the process's own storage, which nothing copies. An index at or past the table's count traps, as does a null entry, which C promises none below argc is.

arguments function

public link(symbol: "_landin_posix_arguments") arguments:
    () -> (table: argument_table)

platform/posix/posix.ldn:426

The process's arguments, argv[0] not among them. It traps when no argument root has been established: the hosted entry establishes one before main runs, and a C main calls _landin_host_initialize_arguments itself.

close function

public link(symbol: "_landin_posix_close") close:
    (closing: descriptor) -> none ! errno

platform/posix/posix.ldn:128

Close closing. The descriptor is released even when this fails, so a failed close is never retried: the number may already name another file.

close_directory function

public link(symbol: "_landin_posix_close_directory") close_directory:
    (opened: directory_stream) -> none ! errno

platform/posix/posix.ldn:229

Close the directory stream and its descriptor, which are released even when this fails.

errno_of function

public link(symbol: "_landin_posix_errno_of") errno_of:
    (value: i32) -> (problem: errno)

platform/posix/errno.ldn:426

The errno atom for the number value on this system: unlisted for a number it does not define.

exit function

public link(symbol: "_landin_posix_exit") exit:
    (status: i32) -> noreturn

platform/posix/posix.ldn:290

End the process with status at once, POSIX's _exit: nothing more of the program runs, and no C stream is flushed.

happened function

public link(symbol: "_landin_posix_happened") happened:
    (entry: poll_entry) -> (events: poll_events)

platform/posix/posix.ldn:346

What happened to an entry's descriptor in the last poll; nothing, before one.

make_directory_at function

public link(symbol: "_landin_posix_make_directory_at") make_directory_at:
    (at: descriptor, path: text.host_string,
     permissions: u32) -> none ! errno

platform/posix/posix.ldn:237

Make the directory path names, relative to at, with the permission bits permissions, which the process umask filters: eexist when the name is taken, enoent when its parent is missing.

map function

public link(symbol: "_landin_posix_map") map:
    (length: usize) -> (base: ptr mut u8) ! errno

platform/posix/posix.ldn:268

Map length bytes of fresh, zeroed memory that this process alone may read and write, POSIX's anonymous private mmap: its first byte, which is aligned to a page, or the errno, enomem when the system has no room.

number function

public link(symbol: "_landin_posix_number") number:
    (problem: errno) -> (value: i32)

platform/posix/errno.ldn:436

The number problem has on this system, as C's errno holds it: zero for unlisted and for an errno this system does not define. ENOTSUP is EOPNOTSUPP's number on Linux and FreeBSD.

open_at function

public link(symbol: "_landin_posix_open_at") open_at:
    (at: descriptor, path: text.host_string,
     options: open_options, permissions: u32)
    -> (opened: descriptor) ! errno

platform/posix/posix.ldn:100

Open the file path names, relative to the directory open as at (or working_directory), with options; a file it creates gets the permission bits permissions, which the process umask filters. The new descriptor, or the errno: enoent for a missing name, enotdir when a component is not a directory, eacces when refused, eexist for an exclusive name that is taken, eintr when a signal came first.

open_directory function

public link(symbol: "_landin_posix_open_directory") open_directory:
    (at: descriptor, path: text.host_string)
    -> (opened: directory_stream) ! errno

platform/posix/posix.ldn:206

Open the directory path names, relative to at, for reading: enotdir when it is not a directory, enoent when it is missing. Close it with close_directory, which also closes its descriptor.

page_size function

public link(symbol: "_landin_posix_page_size") page_size:
    () -> (bytes: usize)

platform/posix/posix.ldn:283

The size of the system's pages in bytes, which map aligns to: 16 KiB on Darwin arm64 and 4 KiB on the others. On Linux it is what the kernel told a static executable's entry, and 4096 when the C runtime started the program instead.

poll function

public link(symbol: "_landin_posix_poll") poll:
    (entries: []mut poll_entry, milliseconds: i32)
    -> (ready: usize) ! errno

platform/posix/posix.ldn:356

Wait until an event happens to one of entries' descriptors, or milliseconds pass, waiting indefinitely when it is negative and not at all when it is zero, POSIX's poll: how many entries had an event, each of which happened reads, zero when the time passed first, or the errno, eintr when a signal came first.

read function

public link(symbol: "_landin_posix_read") read:
    (source: descriptor, into: []mut u8) -> (count: usize) ! errno

platform/posix/posix.ldn:112

Read at most lenof into bytes from source into into: the count read, zero at the end of a file, or the errno; eintr means nothing was read.

read_directory function

public link(symbol: "_landin_posix_read_directory") read_directory:
    (inout opened: directory_stream, buffer: []mut u8)
    -> (item: directory_entry from buffer) ! errno

platform/posix/posix.ldn:220

The directory's next entry, read into buffer, which must be the buffer every earlier read of this stream was given and hold at least directory_buffer bytes, or einval. The entry lends its name from buffer until the next read. An entry with an empty name is the end of the directory. Entries come in the system's order, . and .. among them, as POSIX's readdir gives them.

remove_directory_at function

public link(symbol: "_landin_posix_remove_directory_at") remove_directory_at:
    (at: descriptor, path: text.host_string)
    -> none ! errno

platform/posix/posix.ldn:256

Remove the empty directory path names, relative to at, POSIX's unlinkat with AT_REMOVEDIR: enotempty when it holds anything.

status_at function

public link(symbol: "_landin_posix_status_at") status_at:
    (at: descriptor, path: text.host_string, follow: bool)
    -> (result: status) ! errno

platform/posix/posix.ldn:170

The status of the file path names, relative to the directory open as at (or working_directory), following a final symbolic link when follow is true and reporting the link itself when it is not.

unmap function

public link(symbol: "_landin_posix_unmap") unmap:
    (base: ptr mut u8, length: usize) -> none ! errno

platform/posix/posix.ldn:274

Give back the length bytes mapped at base, POSIX's munmap.

watch function

public link(symbol: "_landin_posix_watch") watch:
    (watched: descriptor, wanted: poll_events)
    -> (entry: poll_entry)

platform/posix/posix.ldn:336

An entry watching watched for the events wanted asks about; its poll_error, poll_hung_up and poll_invalid are reported whether asked or not.

write function

public link(symbol: "_landin_posix_write") write:
    (to: descriptor, bytes: []u8) -> (count: usize) ! errno

platform/posix/posix.ldn:120

Write at most lenof bytes bytes of bytes to to: the count accepted, which may be short, or the errno; eintr means nothing was written.