<script>
<style>
/* force tight list */
.markdown-body li > p { margin-top: 0; margin-bottom: 0; }
</style>
> Transformed from: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md
Skip to [Types](#Types).
# Modules
## Imports
### Memory
Linear memory to be accessed by WASI functions that need it.
## Functions
### <a href="#args_get" id="args_get">#</a> args_get
**`args_get`**`(argv: Pointer<Pointer<u8>>, argv_buf: Pointer<u8>) → Result<(), errno>`
Read command-line argument data.
The size of the array should match that returned by [`args_sizes_get`](#args_sizes_get).
Each argument is expected to be `\0` terminated.
The first argument should be a string containing the "name" of the
program. This need not be a usable filesystem path or even file name,
and may even be a fixed string. Subsequent arguments are the arguments
passed to the program by the user.
##### Params
- <a href="#args_get.argv" id="args_get.argv"></a> `argv`: `Pointer<Pointer<u8>>`
- <a href="#args_get.argv_buf" id="args_get.argv_buf"></a> `argv_buf`: `Pointer<u8>`
##### Results
- <a href="#args_get.error" id="args_get.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#args_get.error.ok" id="args_get.error.ok"></a> `ok`
* <a href="#args_get.error.err" id="args_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#args_sizes_get" id="args_sizes_get">#</a> args_sizes_get
**`args_sizes_get`**`() → Result<(size, size), errno>`
Return command-line argument data sizes.
##### Params
*None*
##### Results
- <a href="#args_sizes_get.error" id="args_sizes_get.error"></a> `error`: `Result<(size, size), errno>` \
Returns the number of arguments and the size of the argument string
data, or an error.
###### Variants
- *size*: **12**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#args_sizes_get.error.ok" id="args_sizes_get.error.ok"></a> `ok`: `(size, size)`
* (Offset: **0**) <a href="#args_sizes_get.error.ok.0" id="args_sizes_get.error.ok.0"></a> `0`: [`size`](#size)
* (Offset: **4**) <a href="#args_sizes_get.error.ok.1" id="args_sizes_get.error.ok.1"></a> `1`: [`size`](#size)
* <a href="#args_sizes_get.error.err" id="args_sizes_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#environ_get" id="environ_get">#</a> environ_get
**`environ_get`**`(environ: Pointer<Pointer<u8>>, environ_buf: Pointer<u8>) → Result<(), errno>`
Read environment variable data.
The sizes of the buffers should match that returned by [`environ_sizes_get`](#environ_sizes_get).
Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s.
##### Params
- <a href="#environ_get.environ" id="environ_get.environ"></a> `environ`: `Pointer<Pointer<u8>>`
- <a href="#environ_get.environ_buf" id="environ_get.environ_buf"></a> `environ_buf`: `Pointer<u8>`
##### Results
- <a href="#environ_get.error" id="environ_get.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#environ_get.error.ok" id="environ_get.error.ok"></a> `ok`
* <a href="#environ_get.error.err" id="environ_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#environ_sizes_get" id="environ_sizes_get">#</a> environ_sizes_get
**`environ_sizes_get`**`() → Result<(size, size), errno>`
Return environment variable data sizes.
##### Params
*None*
##### Results
- <a href="#environ_sizes_get.error" id="environ_sizes_get.error"></a> `error`: `Result<(size, size), errno>` \
Returns the number of environment variable arguments and the size of the
environment variable data.
###### Variants
- *size*: **12**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#environ_sizes_get.error.ok" id="environ_sizes_get.error.ok"></a> `ok`: `(size, size)`
* (Offset: **0**) <a href="#environ_sizes_get.error.ok.0" id="environ_sizes_get.error.ok.0"></a> `0`: [`size`](#size)
* (Offset: **4**) <a href="#environ_sizes_get.error.ok.1" id="environ_sizes_get.error.ok.1"></a> `1`: [`size`](#size)
* <a href="#environ_sizes_get.error.err" id="environ_sizes_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#clock_res_get" id="clock_res_get">#</a> clock_res_get
**`clock_res_get`**`(id: clockid) → Result<timestamp, errno>`
Return the resolution of a clock.
Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
return [`errno::inval`](#errno.inval).
Note: This is similar to `clock_getres` in POSIX.
##### Params
- <a href="#clock_res_get.id" id="clock_res_get.id"></a> `id`: [`clockid`](#clockid) \
The clock for which to return the resolution.
##### Results
- <a href="#clock_res_get.error" id="clock_res_get.error"></a> `error`: `Result<timestamp, errno>` \
The resolution of the clock, or an error if one happened.
###### Variants
- *size*: **16**; *align*: 8; *tag_size*: 4
- **Cases**:
* <a href="#clock_res_get.error.ok" id="clock_res_get.error.ok"></a> `ok`: [`timestamp`](#timestamp)
* <a href="#clock_res_get.error.err" id="clock_res_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#clock_time_get" id="clock_time_get">#</a> clock_time_get
**`clock_time_get`**`(id: clockid, precision: timestamp) → Result<timestamp, errno>`
Return the time value of a clock.
Note: This is similar to `clock_gettime` in POSIX.
##### Params
- <a href="#clock_time_get.id" id="clock_time_get.id"></a> `id`: [`clockid`](#clockid) \
The clock for which to return the time.
- <a href="#clock_time_get.precision" id="clock_time_get.precision"></a> `precision`: [`timestamp`](#timestamp) \
The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
##### Results
- <a href="#clock_time_get.error" id="clock_time_get.error"></a> `error`: `Result<timestamp, errno>` \
The time value of the clock.
###### Variants
- *size*: **16**; *align*: 8; *tag_size*: 4
- **Cases**:
* <a href="#clock_time_get.error.ok" id="clock_time_get.error.ok"></a> `ok`: [`timestamp`](#timestamp)
* <a href="#clock_time_get.error.err" id="clock_time_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_advise" id="fd_advise">#</a> fd_advise
**`fd_advise`**`(fd: fd, offset: filesize, len: filesize, advice: advice) → Result<(), errno>`
Provide file advisory information on a file descriptor.
Note: This is similar to `posix_fadvise` in POSIX.
##### Params
- <a href="#fd_advise.fd" id="fd_advise.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_advise.offset" id="fd_advise.offset"></a> `offset`: [`filesize`](#filesize) \
The offset within the file to which the advisory applies.
- <a href="#fd_advise.len" id="fd_advise.len"></a> `len`: [`filesize`](#filesize) \
The length of the region to which the advisory applies.
- <a href="#fd_advise.advice" id="fd_advise.advice"></a> `advice`: [`advice`](#advice) \
The advice.
##### Results
- <a href="#fd_advise.error" id="fd_advise.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_advise.error.ok" id="fd_advise.error.ok"></a> `ok`
* <a href="#fd_advise.error.err" id="fd_advise.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_allocate" id="fd_allocate">#</a> fd_allocate
**`fd_allocate`**`(fd: fd, offset: filesize, len: filesize) → Result<(), errno>`
Force the allocation of space in a file.
Note: This is similar to `posix_fallocate` in POSIX.
##### Params
- <a href="#fd_allocate.fd" id="fd_allocate.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_allocate.offset" id="fd_allocate.offset"></a> `offset`: [`filesize`](#filesize) \
The offset at which to start the allocation.
- <a href="#fd_allocate.len" id="fd_allocate.len"></a> `len`: [`filesize`](#filesize) \
The length of the area that is allocated.
##### Results
- <a href="#fd_allocate.error" id="fd_allocate.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_allocate.error.ok" id="fd_allocate.error.ok"></a> `ok`
* <a href="#fd_allocate.error.err" id="fd_allocate.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_close" id="fd_close">#</a> fd_close
**`fd_close`**`(fd: fd) → Result<(), errno>`
Close a file descriptor.
Note: This is similar to `close` in POSIX.
##### Params
- <a href="#fd_close.fd" id="fd_close.fd"></a> `fd`: [`fd`](#fd)
##### Results
- <a href="#fd_close.error" id="fd_close.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_close.error.ok" id="fd_close.error.ok"></a> `ok`
* <a href="#fd_close.error.err" id="fd_close.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_datasync" id="fd_datasync">#</a> fd_datasync
**`fd_datasync`**`(fd: fd) → Result<(), errno>`
Synchronize the data of a file to disk.
Note: This is similar to `fdatasync` in POSIX.
##### Params
- <a href="#fd_datasync.fd" id="fd_datasync.fd"></a> `fd`: [`fd`](#fd)
##### Results
- <a href="#fd_datasync.error" id="fd_datasync.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_datasync.error.ok" id="fd_datasync.error.ok"></a> `ok`
* <a href="#fd_datasync.error.err" id="fd_datasync.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_fdstat_get" id="fd_fdstat_get">#</a> fd_fdstat_get
**`fd_fdstat_get`**`(fd: fd) → Result<fdstat, errno>`
Get the attributes of a file descriptor.
Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX, as well as additional fields.
##### Params
- <a href="#fd_fdstat_get.fd" id="fd_fdstat_get.fd"></a> `fd`: [`fd`](#fd)
##### Results
- <a href="#fd_fdstat_get.error" id="fd_fdstat_get.error"></a> `error`: `Result<fdstat, errno>` \
The buffer where the file descriptor's attributes are stored.
###### Variants
- *size*: **32**; *align*: 8; *tag_size*: 4
- **Cases**:
* <a href="#fd_fdstat_get.error.ok" id="fd_fdstat_get.error.ok"></a> `ok`: [`fdstat`](#fdstat)
* <a href="#fd_fdstat_get.error.err" id="fd_fdstat_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_fdstat_set_flags" id="fd_fdstat_set_flags">#</a> fd_fdstat_set_flags
**`fd_fdstat_set_flags`**`(fd: fd, flags: fdflags) → Result<(), errno>`
Adjust the flags associated with a file descriptor.
Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
##### Params
- <a href="#fd_fdstat_set_flags.fd" id="fd_fdstat_set_flags.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_fdstat_set_flags.flags" id="fd_fdstat_set_flags.flags"></a> `flags`: [`fdflags`](#fdflags) \
The desired values of the file descriptor flags.
##### Results
- <a href="#fd_fdstat_set_flags.error" id="fd_fdstat_set_flags.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_fdstat_set_flags.error.ok" id="fd_fdstat_set_flags.error.ok"></a> `ok`
* <a href="#fd_fdstat_set_flags.error.err" id="fd_fdstat_set_flags.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_fdstat_set_rights" id="fd_fdstat_set_rights">#</a> fd_fdstat_set_rights
**`fd_fdstat_set_rights`**`(fd: fd, fs_rights_base: rights, fs_rights_inheriting: rights) → Result<(), errno>`
Adjust the rights associated with a file descriptor.
This can only be used to remove rights, and returns [`errno::notcapable`](#errno.notcapable) if called in a way that would attempt to add rights
##### Params
- <a href="#fd_fdstat_set_rights.fd" id="fd_fdstat_set_rights.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_fdstat_set_rights.fs_rights_base" id="fd_fdstat_set_rights.fs_rights_base"></a> `fs_rights_base`: [`rights`](#rights) \
The desired rights of the file descriptor.
- <a href="#fd_fdstat_set_rights.fs_rights_inheriting" id="fd_fdstat_set_rights.fs_rights_inheriting"></a> `fs_rights_inheriting`: [`rights`](#rights)
##### Results
- <a href="#fd_fdstat_set_rights.error" id="fd_fdstat_set_rights.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_fdstat_set_rights.error.ok" id="fd_fdstat_set_rights.error.ok"></a> `ok`
* <a href="#fd_fdstat_set_rights.error.err" id="fd_fdstat_set_rights.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_filestat_get" id="fd_filestat_get">#</a> fd_filestat_get
**`fd_filestat_get`**`(fd: fd) → Result<filestat, errno>`
Return the attributes of an open file.
##### Params
- <a href="#fd_filestat_get.fd" id="fd_filestat_get.fd"></a> `fd`: [`fd`](#fd)
##### Results
- <a href="#fd_filestat_get.error" id="fd_filestat_get.error"></a> `error`: `Result<filestat, errno>` \
The buffer where the file's attributes are stored.
###### Variants
- *size*: **72**; *align*: 8; *tag_size*: 4
- **Cases**:
* <a href="#fd_filestat_get.error.ok" id="fd_filestat_get.error.ok"></a> `ok`: [`filestat`](#filestat)
* <a href="#fd_filestat_get.error.err" id="fd_filestat_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_filestat_set_size" id="fd_filestat_set_size">#</a> fd_filestat_set_size
**`fd_filestat_set_size`**`(fd: fd, size: filesize) → Result<(), errno>`
Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
Note: This is similar to `ftruncate` in POSIX.
##### Params
- <a href="#fd_filestat_set_size.fd" id="fd_filestat_set_size.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_filestat_set_size.size" id="fd_filestat_set_size.size"></a> `size`: [`filesize`](#filesize) \
The desired file size.
##### Results
- <a href="#fd_filestat_set_size.error" id="fd_filestat_set_size.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_filestat_set_size.error.ok" id="fd_filestat_set_size.error.ok"></a> `ok`
* <a href="#fd_filestat_set_size.error.err" id="fd_filestat_set_size.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_filestat_set_times" id="fd_filestat_set_times">#</a> fd_filestat_set_times
**`fd_filestat_set_times`**`(fd: fd, atim: timestamp, mtim: timestamp, fst_flags: fstflags) → Result<(), errno>`
Adjust the timestamps of an open file or directory.
Note: This is similar to `futimens` in POSIX.
##### Params
- <a href="#fd_filestat_set_times.fd" id="fd_filestat_set_times.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_filestat_set_times.atim" id="fd_filestat_set_times.atim"></a> `atim`: [`timestamp`](#timestamp) \
The desired values of the data access timestamp.
- <a href="#fd_filestat_set_times.mtim" id="fd_filestat_set_times.mtim"></a> `mtim`: [`timestamp`](#timestamp) \
The desired values of the data modification timestamp.
- <a href="#fd_filestat_set_times.fst_flags" id="fd_filestat_set_times.fst_flags"></a> `fst_flags`: [`fstflags`](#fstflags) \
A bitmask indicating which timestamps to adjust.
##### Results
- <a href="#fd_filestat_set_times.error" id="fd_filestat_set_times.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_filestat_set_times.error.ok" id="fd_filestat_set_times.error.ok"></a> `ok`
* <a href="#fd_filestat_set_times.error.err" id="fd_filestat_set_times.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_pread" id="fd_pread">#</a> fd_pread
**`fd_pread`**`(fd: fd, iovs: iovec_array, offset: filesize) → Result<size, errno>`
Read from a file descriptor, without using and updating the file descriptor's offset.
Note: This is similar to `preadv` in Linux (and other Unix-es).
##### Params
- <a href="#fd_pread.fd" id="fd_pread.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_pread.iovs" id="fd_pread.iovs"></a> `iovs`: [`iovec_array`](#iovec_array) \
List of scatter/gather vectors in which to store data.
- <a href="#fd_pread.offset" id="fd_pread.offset"></a> `offset`: [`filesize`](#filesize) \
The offset within the file at which to read.
##### Results
- <a href="#fd_pread.error" id="fd_pread.error"></a> `error`: `Result<size, errno>` \
The number of bytes read.
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_pread.error.ok" id="fd_pread.error.ok"></a> `ok`: [`size`](#size)
* <a href="#fd_pread.error.err" id="fd_pread.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_prestat_get" id="fd_prestat_get">#</a> fd_prestat_get
**`fd_prestat_get`**`(fd: fd) → Result<prestat, errno>`
Return a description of the given preopened file descriptor.
##### Params
- <a href="#fd_prestat_get.fd" id="fd_prestat_get.fd"></a> `fd`: [`fd`](#fd)
##### Results
- <a href="#fd_prestat_get.error" id="fd_prestat_get.error"></a> `error`: `Result<prestat, errno>` \
The buffer where the description is stored.
###### Variants
- *size*: **12**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_prestat_get.error.ok" id="fd_prestat_get.error.ok"></a> `ok`: [`prestat`](#prestat)
* <a href="#fd_prestat_get.error.err" id="fd_prestat_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_prestat_dir_name" id="fd_prestat_dir_name">#</a> fd_prestat_dir_name
**`fd_prestat_dir_name`**`(fd: fd, path: Pointer<u8>, path_len: size) → Result<(), errno>`
Return a description of the given preopened file descriptor.
##### Params
- <a href="#fd_prestat_dir_name.fd" id="fd_prestat_dir_name.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_prestat_dir_name.path" id="fd_prestat_dir_name.path"></a> `path`: `Pointer<u8>` \
A buffer into which to write the preopened directory name.
- <a href="#fd_prestat_dir_name.path_len" id="fd_prestat_dir_name.path_len"></a> `path_len`: [`size`](#size)
##### Results
- <a href="#fd_prestat_dir_name.error" id="fd_prestat_dir_name.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_prestat_dir_name.error.ok" id="fd_prestat_dir_name.error.ok"></a> `ok`
* <a href="#fd_prestat_dir_name.error.err" id="fd_prestat_dir_name.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_pwrite" id="fd_pwrite">#</a> fd_pwrite
**`fd_pwrite`**`(fd: fd, iovs: ciovec_array, offset: filesize) → Result<size, errno>`
Write to a file descriptor, without using and updating the file descriptor's offset.
Note: This is similar to `pwritev` in Linux (and other Unix-es).
Like Linux (and other Unix-es), any calls of `pwrite` (and other
functions to read or write) for a regular file by other threads in the
WASI process should not be interleaved while `pwrite` is executed.
##### Params
- <a href="#fd_pwrite.fd" id="fd_pwrite.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_pwrite.iovs" id="fd_pwrite.iovs"></a> `iovs`: [`ciovec_array`](#ciovec_array) \
List of scatter/gather vectors from which to retrieve data.
- <a href="#fd_pwrite.offset" id="fd_pwrite.offset"></a> `offset`: [`filesize`](#filesize) \
The offset within the file at which to write.
##### Results
- <a href="#fd_pwrite.error" id="fd_pwrite.error"></a> `error`: `Result<size, errno>` \
The number of bytes written.
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_pwrite.error.ok" id="fd_pwrite.error.ok"></a> `ok`: [`size`](#size)
* <a href="#fd_pwrite.error.err" id="fd_pwrite.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_read" id="fd_read">#</a> fd_read
**`fd_read`**`(fd: fd, iovs: iovec_array) → Result<size, errno>`
Read from a file descriptor.
Note: This is similar to `readv` in POSIX.
##### Params
- <a href="#fd_read.fd" id="fd_read.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_read.iovs" id="fd_read.iovs"></a> `iovs`: [`iovec_array`](#iovec_array) \
List of scatter/gather vectors to which to store data.
##### Results
- <a href="#fd_read.error" id="fd_read.error"></a> `error`: `Result<size, errno>` \
The number of bytes read.
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_read.error.ok" id="fd_read.error.ok"></a> `ok`: [`size`](#size)
* <a href="#fd_read.error.err" id="fd_read.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_readdir" id="fd_readdir">#</a> fd_readdir
**`fd_readdir`**`(fd: fd, buf: Pointer<u8>, buf_len: size, cookie: dircookie) → Result<size, errno>`
Read directory entries from a directory.
When successful, the contents of the output buffer consist of a sequence of
directory entries. Each directory entry consists of a [`dirent`](#dirent) object,
followed by [`dirent::d_namlen`](#dirent.d_namlen) bytes holding the name of the directory
entry.
This function fills the output buffer as much as possible, potentially
truncating the last directory entry. This allows the caller to grow its
read buffer size in case it's too small to fit a single large directory
entry, or skip the oversized directory entry.
Entries for the special `.` and `..` directory entries are included in the
sequence.
##### Params
- <a href="#fd_readdir.fd" id="fd_readdir.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_readdir.buf" id="fd_readdir.buf"></a> `buf`: `Pointer<u8>` \
The buffer where directory entries are stored
- <a href="#fd_readdir.buf_len" id="fd_readdir.buf_len"></a> `buf_len`: [`size`](#size)
- <a href="#fd_readdir.cookie" id="fd_readdir.cookie"></a> `cookie`: [`dircookie`](#dircookie) \
The location within the directory to start reading
##### Results
- <a href="#fd_readdir.error" id="fd_readdir.error"></a> `error`: `Result<size, errno>` \
The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached.
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_readdir.error.ok" id="fd_readdir.error.ok"></a> `ok`: [`size`](#size)
* <a href="#fd_readdir.error.err" id="fd_readdir.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_renumber" id="fd_renumber">#</a> fd_renumber
**`fd_renumber`**`(fd: fd, to: fd) → Result<(), errno>`
Atomically replace a file descriptor by renumbering another file descriptor.
Due to the strong focus on thread safety, this environment does not provide
a mechanism to duplicate or renumber a file descriptor to an arbitrary
number, like `dup2()`. This would be prone to race conditions, as an actual
file descriptor with the same number could be allocated by a different
thread at the same time.
This function provides a way to atomically renumber file descriptors, which
would disappear if `dup2()` were to be removed entirely.
##### Params
- <a href="#fd_renumber.fd" id="fd_renumber.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_renumber.to" id="fd_renumber.to"></a> `to`: [`fd`](#fd) \
The file descriptor to overwrite.
##### Results
- <a href="#fd_renumber.error" id="fd_renumber.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_renumber.error.ok" id="fd_renumber.error.ok"></a> `ok`
* <a href="#fd_renumber.error.err" id="fd_renumber.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_seek" id="fd_seek">#</a> fd_seek
**`fd_seek`**`(fd: fd, offset: filedelta, whence: whence) → Result<filesize, errno>`
Move the offset of a file descriptor.
Note: This is similar to `lseek` in POSIX.
##### Params
- <a href="#fd_seek.fd" id="fd_seek.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_seek.offset" id="fd_seek.offset"></a> `offset`: [`filedelta`](#filedelta) \
The number of bytes to move.
- <a href="#fd_seek.whence" id="fd_seek.whence"></a> `whence`: [`whence`](#whence) \
The base from which the offset is relative.
##### Results
- <a href="#fd_seek.error" id="fd_seek.error"></a> `error`: `Result<filesize, errno>` \
The new offset of the file descriptor, relative to the start of the file.
###### Variants
- *size*: **16**; *align*: 8; *tag_size*: 4
- **Cases**:
* <a href="#fd_seek.error.ok" id="fd_seek.error.ok"></a> `ok`: [`filesize`](#filesize)
* <a href="#fd_seek.error.err" id="fd_seek.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_sync" id="fd_sync">#</a> fd_sync
**`fd_sync`**`(fd: fd) → Result<(), errno>`
Synchronize the data and metadata of a file to disk.
Note: This is similar to `fsync` in POSIX.
##### Params
- <a href="#fd_sync.fd" id="fd_sync.fd"></a> `fd`: [`fd`](#fd)
##### Results
- <a href="#fd_sync.error" id="fd_sync.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_sync.error.ok" id="fd_sync.error.ok"></a> `ok`
* <a href="#fd_sync.error.err" id="fd_sync.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_tell" id="fd_tell">#</a> fd_tell
**`fd_tell`**`(fd: fd) → Result<filesize, errno>`
Return the current offset of a file descriptor.
Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
##### Params
- <a href="#fd_tell.fd" id="fd_tell.fd"></a> `fd`: [`fd`](#fd)
##### Results
- <a href="#fd_tell.error" id="fd_tell.error"></a> `error`: `Result<filesize, errno>` \
The current offset of the file descriptor, relative to the start of the file.
###### Variants
- *size*: **16**; *align*: 8; *tag_size*: 4
- **Cases**:
* <a href="#fd_tell.error.ok" id="fd_tell.error.ok"></a> `ok`: [`filesize`](#filesize)
* <a href="#fd_tell.error.err" id="fd_tell.error.err"></a> `err`: [`errno`](#errno)
### <a href="#fd_write" id="fd_write">#</a> fd_write
**`fd_write`**`(fd: fd, iovs: ciovec_array) → Result<size, errno>`
Write to a file descriptor.
Note: This is similar to `writev` in POSIX.
Like POSIX, any calls of `write` (and other functions to read or write)
for a regular file by other threads in the WASI process should not be
interleaved while `write` is executed.
##### Params
- <a href="#fd_write.fd" id="fd_write.fd"></a> `fd`: [`fd`](#fd)
- <a href="#fd_write.iovs" id="fd_write.iovs"></a> `iovs`: [`ciovec_array`](#ciovec_array) \
List of scatter/gather vectors from which to retrieve data.
##### Results
- <a href="#fd_write.error" id="fd_write.error"></a> `error`: `Result<size, errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#fd_write.error.ok" id="fd_write.error.ok"></a> `ok`: [`size`](#size)
* <a href="#fd_write.error.err" id="fd_write.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_create_directory" id="path_create_directory">#</a> path_create_directory
**`path_create_directory`**`(fd: fd, path: string) → Result<(), errno>`
Create a directory.
Note: This is similar to `mkdirat` in POSIX.
##### Params
- <a href="#path_create_directory.fd" id="path_create_directory.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_create_directory.path" id="path_create_directory.path"></a> `path`: `string` \
The path at which to create the directory.
##### Results
- <a href="#path_create_directory.error" id="path_create_directory.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_create_directory.error.ok" id="path_create_directory.error.ok"></a> `ok`
* <a href="#path_create_directory.error.err" id="path_create_directory.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_filestat_get" id="path_filestat_get">#</a> path_filestat_get
**`path_filestat_get`**`(fd: fd, flags: lookupflags, path: string) → Result<filestat, errno>`
Return the attributes of a file or directory.
Note: This is similar to `stat` in POSIX.
##### Params
- <a href="#path_filestat_get.fd" id="path_filestat_get.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_filestat_get.flags" id="path_filestat_get.flags"></a> `flags`: [`lookupflags`](#lookupflags) \
Flags determining the method of how the path is resolved.
- <a href="#path_filestat_get.path" id="path_filestat_get.path"></a> `path`: `string` \
The path of the file or directory to inspect.
##### Results
- <a href="#path_filestat_get.error" id="path_filestat_get.error"></a> `error`: `Result<filestat, errno>` \
The buffer where the file's attributes are stored.
###### Variants
- *size*: **72**; *align*: 8; *tag_size*: 4
- **Cases**:
* <a href="#path_filestat_get.error.ok" id="path_filestat_get.error.ok"></a> `ok`: [`filestat`](#filestat)
* <a href="#path_filestat_get.error.err" id="path_filestat_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_filestat_set_times" id="path_filestat_set_times">#</a> path_filestat_set_times
**`path_filestat_set_times`**`(fd: fd, flags: lookupflags, path: string, atim: timestamp, mtim: timestamp, fst_flags: fstflags) → Result<(), errno>`
Adjust the timestamps of a file or directory.
Note: This is similar to `utimensat` in POSIX.
##### Params
- <a href="#path_filestat_set_times.fd" id="path_filestat_set_times.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_filestat_set_times.flags" id="path_filestat_set_times.flags"></a> `flags`: [`lookupflags`](#lookupflags) \
Flags determining the method of how the path is resolved.
- <a href="#path_filestat_set_times.path" id="path_filestat_set_times.path"></a> `path`: `string` \
The path of the file or directory to operate on.
- <a href="#path_filestat_set_times.atim" id="path_filestat_set_times.atim"></a> `atim`: [`timestamp`](#timestamp) \
The desired values of the data access timestamp.
- <a href="#path_filestat_set_times.mtim" id="path_filestat_set_times.mtim"></a> `mtim`: [`timestamp`](#timestamp) \
The desired values of the data modification timestamp.
- <a href="#path_filestat_set_times.fst_flags" id="path_filestat_set_times.fst_flags"></a> `fst_flags`: [`fstflags`](#fstflags) \
A bitmask indicating which timestamps to adjust.
##### Results
- <a href="#path_filestat_set_times.error" id="path_filestat_set_times.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_filestat_set_times.error.ok" id="path_filestat_set_times.error.ok"></a> `ok`
* <a href="#path_filestat_set_times.error.err" id="path_filestat_set_times.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_link" id="path_link">#</a> path_link
**`path_link`**`(old_fd: fd, old_flags: lookupflags, old_path: string, new_fd: fd, new_path: string) → Result<(), errno>`
Create a hard link.
Note: This is similar to `linkat` in POSIX.
##### Params
- <a href="#path_link.old_fd" id="path_link.old_fd"></a> `old_fd`: [`fd`](#fd)
- <a href="#path_link.old_flags" id="path_link.old_flags"></a> `old_flags`: [`lookupflags`](#lookupflags) \
Flags determining the method of how the path is resolved.
- <a href="#path_link.old_path" id="path_link.old_path"></a> `old_path`: `string` \
The source path from which to link.
- <a href="#path_link.new_fd" id="path_link.new_fd"></a> `new_fd`: [`fd`](#fd) \
The working directory at which the resolution of the new path starts.
- <a href="#path_link.new_path" id="path_link.new_path"></a> `new_path`: `string` \
The destination path at which to create the hard link.
##### Results
- <a href="#path_link.error" id="path_link.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_link.error.ok" id="path_link.error.ok"></a> `ok`
* <a href="#path_link.error.err" id="path_link.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_open" id="path_open">#</a> path_open
**`path_open`**`(fd: fd, dirflags: lookupflags, path: string, oflags: oflags, fs_rights_base: rights, fs_rights_inheriting: rights, fdflags: fdflags) → Result<fd, errno>`
Open a file or directory.
The returned file descriptor is not guaranteed to be the lowest-numbered
file descriptor not currently open; it is randomized to prevent
applications from depending on making assumptions about indexes, since this
is error-prone in multi-threaded contexts. The returned file descriptor is
guaranteed to be less than 2**31.
Note: This is similar to `openat` in POSIX.
##### Params
- <a href="#path_open.fd" id="path_open.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_open.dirflags" id="path_open.dirflags"></a> `dirflags`: [`lookupflags`](#lookupflags) \
Flags determining the method of how the path is resolved.
- <a href="#path_open.path" id="path_open.path"></a> `path`: `string` \
The relative path of the file or directory to open, relative to the
[`path_open::fd`](#path_open.fd) directory.
- <a href="#path_open.oflags" id="path_open.oflags"></a> `oflags`: [`oflags`](#oflags) \
The method by which to open the file.
- <a href="#path_open.fs_rights_base" id="path_open.fs_rights_base"></a> `fs_rights_base`: [`rights`](#rights) \
The initial rights of the newly created file descriptor. The
implementation is allowed to return a file descriptor with fewer rights
than specified, if and only if those rights do not apply to the type of
file being opened.
The *base* rights are rights that will apply to operations using the file
descriptor itself, while the *inheriting* rights are rights that apply to
file descriptors derived from it.
- <a href="#path_open.fs_rights_inheriting" id="path_open.fs_rights_inheriting"></a> `fs_rights_inheriting`: [`rights`](#rights)
- <a href="#path_open.fdflags" id="path_open.fdflags"></a> `fdflags`: [`fdflags`](#fdflags)
##### Results
- <a href="#path_open.error" id="path_open.error"></a> `error`: `Result<fd, errno>` \
The file descriptor of the file that has been opened.
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_open.error.ok" id="path_open.error.ok"></a> `ok`: [`fd`](#fd)
* <a href="#path_open.error.err" id="path_open.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_readlink" id="path_readlink">#</a> path_readlink
**`path_readlink`**`(fd: fd, path: string, buf: Pointer<u8>, buf_len: size) → Result<size, errno>`
Read the contents of a symbolic link.
Note: This is similar to `readlinkat` in POSIX. If `buf` is not large
enough to contain the contents of the link, the first `buf_len` bytes will be
be written to `buf`.
##### Params
- <a href="#path_readlink.fd" id="path_readlink.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_readlink.path" id="path_readlink.path"></a> `path`: `string` \
The path of the symbolic link from which to read.
- <a href="#path_readlink.buf" id="path_readlink.buf"></a> `buf`: `Pointer<u8>` \
The buffer to which to write the contents of the symbolic link.
- <a href="#path_readlink.buf_len" id="path_readlink.buf_len"></a> `buf_len`: [`size`](#size)
##### Results
- <a href="#path_readlink.error" id="path_readlink.error"></a> `error`: `Result<size, errno>` \
The number of bytes placed in the buffer.
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_readlink.error.ok" id="path_readlink.error.ok"></a> `ok`: [`size`](#size)
* <a href="#path_readlink.error.err" id="path_readlink.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_remove_directory" id="path_remove_directory">#</a> path_remove_directory
**`path_remove_directory`**`(fd: fd, path: string) → Result<(), errno>`
Remove a directory.
Return [`errno::notempty`](#errno.notempty) if the directory is not empty.
Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
##### Params
- <a href="#path_remove_directory.fd" id="path_remove_directory.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_remove_directory.path" id="path_remove_directory.path"></a> `path`: `string` \
The path to a directory to remove.
##### Results
- <a href="#path_remove_directory.error" id="path_remove_directory.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_remove_directory.error.ok" id="path_remove_directory.error.ok"></a> `ok`
* <a href="#path_remove_directory.error.err" id="path_remove_directory.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_rename" id="path_rename">#</a> path_rename
**`path_rename`**`(fd: fd, old_path: string, new_fd: fd, new_path: string) → Result<(), errno>`
Rename a file or directory.
Note: This is similar to `renameat` in POSIX.
##### Params
- <a href="#path_rename.fd" id="path_rename.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_rename.old_path" id="path_rename.old_path"></a> `old_path`: `string` \
The source path of the file or directory to rename.
- <a href="#path_rename.new_fd" id="path_rename.new_fd"></a> `new_fd`: [`fd`](#fd) \
The working directory at which the resolution of the new path starts.
- <a href="#path_rename.new_path" id="path_rename.new_path"></a> `new_path`: `string` \
The destination path to which to rename the file or directory.
##### Results
- <a href="#path_rename.error" id="path_rename.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_rename.error.ok" id="path_rename.error.ok"></a> `ok`
* <a href="#path_rename.error.err" id="path_rename.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_symlink" id="path_symlink">#</a> path_symlink
**`path_symlink`**`(old_path: string, fd: fd, new_path: string) → Result<(), errno>`
Create a symbolic link.
Note: This is similar to `symlinkat` in POSIX.
##### Params
- <a href="#path_symlink.old_path" id="path_symlink.old_path"></a> `old_path`: `string` \
The contents of the symbolic link.
- <a href="#path_symlink.fd" id="path_symlink.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_symlink.new_path" id="path_symlink.new_path"></a> `new_path`: `string` \
The destination path at which to create the symbolic link.
##### Results
- <a href="#path_symlink.error" id="path_symlink.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_symlink.error.ok" id="path_symlink.error.ok"></a> `ok`
* <a href="#path_symlink.error.err" id="path_symlink.error.err"></a> `err`: [`errno`](#errno)
### <a href="#path_unlink_file" id="path_unlink_file">#</a> path_unlink_file
**`path_unlink_file`**`(fd: fd, path: string) → Result<(), errno>`
Unlink a file.
Return [`errno::isdir`](#errno.isdir) if the path refers to a directory.
Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
##### Params
- <a href="#path_unlink_file.fd" id="path_unlink_file.fd"></a> `fd`: [`fd`](#fd)
- <a href="#path_unlink_file.path" id="path_unlink_file.path"></a> `path`: `string` \
The path to a file to unlink.
##### Results
- <a href="#path_unlink_file.error" id="path_unlink_file.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#path_unlink_file.error.ok" id="path_unlink_file.error.ok"></a> `ok`
* <a href="#path_unlink_file.error.err" id="path_unlink_file.error.err"></a> `err`: [`errno`](#errno)
### <a href="#poll_oneoff" id="poll_oneoff">#</a> poll_oneoff
**`poll_oneoff`**`(in: ConstPointer<subscription>, out: Pointer<event>, nsubscriptions: size) → Result<size, errno>`
Concurrently poll for the occurrence of a set of events.
If `nsubscriptions` is 0, returns [`errno::inval`](#errno.inval).
##### Params
- <a href="#poll_oneoff.in" id="poll_oneoff.in"></a> `in`: `ConstPointer<subscription>` \
The events to which to subscribe.
- <a href="#poll_oneoff.out" id="poll_oneoff.out"></a> `out`: `Pointer<event>` \
The events that have occurred.
- <a href="#poll_oneoff.nsubscriptions" id="poll_oneoff.nsubscriptions"></a> `nsubscriptions`: [`size`](#size) \
Both the number of subscriptions and events.
##### Results
- <a href="#poll_oneoff.error" id="poll_oneoff.error"></a> `error`: `Result<size, errno>` \
The number of events stored.
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#poll_oneoff.error.ok" id="poll_oneoff.error.ok"></a> `ok`: [`size`](#size)
* <a href="#poll_oneoff.error.err" id="poll_oneoff.error.err"></a> `err`: [`errno`](#errno)
### <a href="#proc_exit" id="proc_exit">#</a> proc_exit
**`proc_exit`**`(rval: exitcode)`
Terminate the process normally. An exit code of 0 indicates successful
termination of the program. The meanings of other values is dependent on
the environment.
##### Params
- <a href="#proc_exit.rval" id="proc_exit.rval"></a> `rval`: [`exitcode`](#exitcode) \
The exit code returned by the process.
##### Results
### <a href="#proc_raise" id="proc_raise">#</a> proc_raise
**`proc_raise`**`(sig: signal) → Result<(), errno>`
Send a signal to the process of the calling thread.
Note: This is similar to `raise` in POSIX.
##### Params
- <a href="#proc_raise.sig" id="proc_raise.sig"></a> `sig`: [`signal`](#signal) \
The signal condition to trigger.
##### Results
- <a href="#proc_raise.error" id="proc_raise.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#proc_raise.error.ok" id="proc_raise.error.ok"></a> `ok`
* <a href="#proc_raise.error.err" id="proc_raise.error.err"></a> `err`: [`errno`](#errno)
### <a href="#sched_yield" id="sched_yield">#</a> sched_yield
**`sched_yield`**`() → Result<(), errno>`
Temporarily yield execution of the calling thread.
Note: This is similar to [`sched_yield`](#sched_yield) in POSIX.
##### Params
*None*
##### Results
- <a href="#sched_yield.error" id="sched_yield.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#sched_yield.error.ok" id="sched_yield.error.ok"></a> `ok`
* <a href="#sched_yield.error.err" id="sched_yield.error.err"></a> `err`: [`errno`](#errno)
### <a href="#random_get" id="random_get">#</a> random_get
**`random_get`**`(buf: Pointer<u8>, buf_len: size) → Result<(), errno>`
Write high-quality random data into a buffer.
This function blocks when the implementation is unable to immediately
provide sufficient high-quality random data.
This function may execute slowly, so when large mounts of random data are
required, it's advisable to use this function to seed a pseudo-random
number generator, rather than to provide the random data directly.
##### Params
- <a href="#random_get.buf" id="random_get.buf"></a> `buf`: `Pointer<u8>` \
The buffer to fill with random data.
- <a href="#random_get.buf_len" id="random_get.buf_len"></a> `buf_len`: [`size`](#size)
##### Results
- <a href="#random_get.error" id="random_get.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#random_get.error.ok" id="random_get.error.ok"></a> `ok`
* <a href="#random_get.error.err" id="random_get.error.err"></a> `err`: [`errno`](#errno)
### <a href="#sock_accept" id="sock_accept">#</a> sock_accept
**`sock_accept`**`(fd: fd, flags: fdflags) → Result<fd, errno>`
Accept a new incoming connection.
Note: This is similar to `accept` in POSIX.
##### Params
- <a href="#sock_accept.fd" id="sock_accept.fd"></a> `fd`: [`fd`](#fd) \
The listening socket.
- <a href="#sock_accept.flags" id="sock_accept.flags"></a> `flags`: [`fdflags`](#fdflags) \
The desired values of the file descriptor flags.
##### Results
- <a href="#sock_accept.error" id="sock_accept.error"></a> `error`: `Result<fd, errno>` \
New socket connection
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#sock_accept.error.ok" id="sock_accept.error.ok"></a> `ok`: [`fd`](#fd)
* <a href="#sock_accept.error.err" id="sock_accept.error.err"></a> `err`: [`errno`](#errno)
### <a href="#sock_recv" id="sock_recv">#</a> sock_recv
**`sock_recv`**`(fd: fd, ri_data: iovec_array, ri_flags: riflags) → Result<(size, roflags), errno>`
Receive a message from a socket.
Note: This is similar to `recv` in POSIX, though it also supports reading
the data into multiple buffers in the manner of `readv`.
##### Params
- <a href="#sock_recv.fd" id="sock_recv.fd"></a> `fd`: [`fd`](#fd)
- <a href="#sock_recv.ri_data" id="sock_recv.ri_data"></a> `ri_data`: [`iovec_array`](#iovec_array) \
List of scatter/gather vectors to which to store data.
- <a href="#sock_recv.ri_flags" id="sock_recv.ri_flags"></a> `ri_flags`: [`riflags`](#riflags) \
Message flags.
##### Results
- <a href="#sock_recv.error" id="sock_recv.error"></a> `error`: `Result<(size, roflags), errno>` \
Number of bytes stored in ri_data and message flags.
###### Variants
- *size*: **12**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#sock_recv.error.ok" id="sock_recv.error.ok"></a> `ok`: `(size, roflags)`
* (Offset: **0**) <a href="#sock_recv.error.ok.0" id="sock_recv.error.ok.0"></a> `0`: [`size`](#size)
* (Offset: **4**) <a href="#sock_recv.error.ok.1" id="sock_recv.error.ok.1"></a> `1`: [`roflags`](#roflags)
* <a href="#sock_recv.error.err" id="sock_recv.error.err"></a> `err`: [`errno`](#errno)
### <a href="#sock_send" id="sock_send">#</a> sock_send
**`sock_send`**`(fd: fd, si_data: ciovec_array, si_flags: siflags) → Result<size, errno>`
Send a message on a socket.
Note: This is similar to `send` in POSIX, though it also supports writing
the data from multiple buffers in the manner of `writev`.
##### Params
- <a href="#sock_send.fd" id="sock_send.fd"></a> `fd`: [`fd`](#fd)
- <a href="#sock_send.si_data" id="sock_send.si_data"></a> `si_data`: [`ciovec_array`](#ciovec_array) \
List of scatter/gather vectors to which to retrieve data
- <a href="#sock_send.si_flags" id="sock_send.si_flags"></a> `si_flags`: [`siflags`](#siflags) \
Message flags.
##### Results
- <a href="#sock_send.error" id="sock_send.error"></a> `error`: `Result<size, errno>` \
Number of bytes transmitted.
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#sock_send.error.ok" id="sock_send.error.ok"></a> `ok`: [`size`](#size)
* <a href="#sock_send.error.err" id="sock_send.error.err"></a> `err`: [`errno`](#errno)
### <a href="#sock_shutdown" id="sock_shutdown">#</a> sock_shutdown
**`sock_shutdown`**`(fd: fd, how: sdflags) → Result<(), errno>`
Shut down socket send and receive channels.
Note: This is similar to `shutdown` in POSIX.
##### Params
- <a href="#sock_shutdown.fd" id="sock_shutdown.fd"></a> `fd`: [`fd`](#fd)
- <a href="#sock_shutdown.how" id="sock_shutdown.how"></a> `how`: [`sdflags`](#sdflags) \
Which channels on the socket to shut down.
##### Results
- <a href="#sock_shutdown.error" id="sock_shutdown.error"></a> `error`: `Result<(), errno>`
###### Variants
- *size*: **8**; *align*: 4; *tag_size*: 4
- **Cases**:
* <a href="#sock_shutdown.error.ok" id="sock_shutdown.error.ok"></a> `ok`
* <a href="#sock_shutdown.error.err" id="sock_shutdown.error.err"></a> `err`: [`errno`](#errno)
# Types
> See the [complete](https://hackmd.io/cQY7Rx43ShuS_O47CVz_mA) reference here.
## <a href="#size" id="size"></a> `size`: `u32`
- **Size**: 4
- **Alignment**: 4
## <a href="#filesize" id="filesize"></a> `filesize`: `u64`
Non-negative file size or length of a region within a file.
- **Size**: 8
- **Alignment**: 8
## <a href="#timestamp" id="timestamp"></a> `timestamp`: `u64`
Timestamp in nanoseconds.
- **Size**: 8
- **Alignment**: 8
## <a href="#clockid" id="clockid"></a> `clockid`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#clockid)
Identifiers for clocks.
- **Size**: 4
- **Alignment**: 4
## <a href="#errno" id="errno"></a> `errno`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#errno)
Error codes returned by functions.
Not all of these error codes are returned by the functions provided by this
API; some are used in higher-level library layers, and others are provided
merely for alignment with POSIX.
- **Size**: 2
- **Alignment**: 2
## <a href="#rights" id="rights"></a> `rights`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#rights)
File descriptor rights, determining which actions may be performed.
- **Size**: 8
- **Alignment**: 8
## <a href="#fd" id="fd"></a> `fd`: `Handle`
A file descriptor handle.
- **Size**: 4
- **Alignment**: 4
## <a href="#iovec" id="iovec"></a> `iovec`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#iovec)
A region of memory for scatter/gather reads.
- **Size**: 8
- **Alignment**: 4
## <a href="#ciovec" id="ciovec"></a> `ciovec`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#ciovec)
A region of memory for scatter/gather writes.
- **Size**: 8
- **Alignment**: 4
## <a href="#iovec_array" id="iovec_array"></a> `iovec_array`: `List<iovec>`
- **Size**: 8
- **Alignment**: 4
## <a href="#ciovec_array" id="ciovec_array"></a> `ciovec_array`: `List<ciovec>`
- **Size**: 8
- **Alignment**: 4
## <a href="#filedelta" id="filedelta"></a> `filedelta`: `s64`
Relative offset within a file.
- **Size**: 8
- **Alignment**: 8
## <a href="#whence" id="whence"></a> `whence`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#whence)
The position relative to which to set the offset of the file descriptor.
- **Size**: 1
- **Alignment**: 1
## <a href="#dircookie" id="dircookie"></a> `dircookie`: `u64`
A reference to the offset of a directory entry.
The value 0 signifies the start of the directory.
- **Size**: 8
- **Alignment**: 8
## <a href="#dirnamlen" id="dirnamlen"></a> `dirnamlen`: `u32`
The type for the [`dirent::d_namlen`](#dirent.d_namlen) field of [`dirent`](#dirent) struct.
- **Size**: 4
- **Alignment**: 4
## <a href="#inode" id="inode"></a> `inode`: `u64`
File serial number that is unique within its file system.
- **Size**: 8
- **Alignment**: 8
## <a href="#filetype" id="filetype"></a> `filetype`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#filetype)
The type of a file descriptor or file.
- **Size**: 1
- **Alignment**: 1
## <a href="#dirent" id="dirent"></a> `dirent`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#dirent)
A directory entry.
- **Size**: 24
- **Alignment**: 8
## <a href="#advice" id="advice"></a> `advice`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#advice)
File or memory access pattern advisory information.
- **Size**: 1
- **Alignment**: 1
## <a href="#fdflags" id="fdflags"></a> `fdflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#fdflags)
File descriptor flags.
- **Size**: 2
- **Alignment**: 2
## <a href="#fdstat" id="fdstat"></a> `fdstat`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#fdstat)
File descriptor attributes.
- **Size**: 24
- **Alignment**: 8
## <a href="#device" id="device"></a> `device`: `u64`
Identifier for a device containing a file system. Can be used in combination
with [`inode`](#inode) to uniquely identify a file or directory in the filesystem.
- **Size**: 8
- **Alignment**: 8
## <a href="#fstflags" id="fstflags"></a> `fstflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#fstflags)
Which file time attributes to adjust.
- **Size**: 2
- **Alignment**: 2
## <a href="#lookupflags" id="lookupflags"></a> `lookupflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#lookupflags)
Flags determining the method of how paths are resolved.
- **Size**: 4
- **Alignment**: 4
## <a href="#oflags" id="oflags"></a> `oflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#oflags)
Open flags used by [`path_open`](#path_open).
- **Size**: 2
- **Alignment**: 2
## <a href="#linkcount" id="linkcount"></a> `linkcount`: `u64`
Number of hard links to an inode.
- **Size**: 8
- **Alignment**: 8
## <a href="#filestat" id="filestat"></a> `filestat`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#filestat)
File attributes.
- **Size**: 64
- **Alignment**: 8
## <a href="#userdata" id="userdata"></a> `userdata`: `u64`
User-provided value that may be attached to objects that is retained when
extracted from the implementation.
- **Size**: 8
- **Alignment**: 8
## <a href="#eventtype" id="eventtype"></a> `eventtype`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#eventtype)
Type of a subscription to an event or its occurrence.
- **Size**: 1
- **Alignment**: 1
## <a href="#eventrwflags" id="eventrwflags"></a> `eventrwflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#eventrwflags)
The state of the file descriptor subscribed to with
[`eventtype::fd_read`](#eventtype.fd_read) or [`eventtype::fd_write`](#eventtype.fd_write).
- **Size**: 2
- **Alignment**: 2
## <a href="#event_fd_readwrite" id="event_fd_readwrite"></a> `event_fd_readwrite`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#event_fd_readwrite)
The contents of an [`event`](#event) when type is [`eventtype::fd_read`](#eventtype.fd_read) or
[`eventtype::fd_write`](#eventtype.fd_write).
- **Size**: 16
- **Alignment**: 8
## <a href="#event" id="event"></a> `event`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#event)
An event that occurred.
- **Size**: 32
- **Alignment**: 8
## <a href="#subclockflags" id="subclockflags"></a> `subclockflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#subclockflags)
Flags determining how to interpret the timestamp provided in
[`subscription_clock::timeout`](#subscription_clock.timeout).
- **Size**: 2
- **Alignment**: 2
## <a href="#subscription_clock" id="subscription_clock"></a> `subscription_clock`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#subscription_clock)
The contents of a [`subscription`](#subscription) when type is [`eventtype::clock`](#eventtype.clock).
- **Size**: 32
- **Alignment**: 8
## <a href="#subscription_fd_readwrite" id="subscription_fd_readwrite"></a> `subscription_fd_readwrite`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#subscription_fd_readwrite)
The contents of a [`subscription`](#subscription) when type is type is
[`eventtype::fd_read`](#eventtype.fd_read) or [`eventtype::fd_write`](#eventtype.fd_write).
- **Size**: 4
- **Alignment**: 4
## <a href="#subscription_u" id="subscription_u"></a> `subscription_u`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#subscription_u)
The contents of a [`subscription`](#subscription).
- **Size**: 40
- **Alignment**: 8
## <a href="#subscription" id="subscription"></a> `subscription`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#subscription)
Subscription to an event.
- **Size**: 48
- **Alignment**: 8
## <a href="#exitcode" id="exitcode"></a> `exitcode`: `u32`
Exit code generated by a process when exiting.
- **Size**: 4
- **Alignment**: 4
## <a href="#signal" id="signal"></a> `signal`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#signal)
Signal condition.
- **Size**: 1
- **Alignment**: 1
## <a href="#riflags" id="riflags"></a> `riflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#riflags)
Flags provided to [`sock_recv`](#sock_recv).
- **Size**: 2
- **Alignment**: 2
## <a href="#roflags" id="roflags"></a> `roflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#roflags)
Flags returned by [`sock_recv`](#sock_recv).
- **Size**: 2
- **Alignment**: 2
## <a href="#siflags" id="siflags"></a> `siflags`: `u16`
Flags provided to [`sock_send`](#sock_send). As there are currently no flags
defined, it must be set to zero.
- **Size**: 2
- **Alignment**: 2
## <a href="#sdflags" id="sdflags"></a> `sdflags`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#sdflags)
Which channels on a socket to shut down.
- **Size**: 1
- **Alignment**: 1
## <a href="#preopentype" id="preopentype"></a> `preopentype`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#preopentype)
Identifiers for preopened capabilities.
- **Size**: 1
- **Alignment**: 1
## <a href="#prestat_dir" id="prestat_dir"></a> `prestat_dir`: [`Record`](https://hackmd.io/@q/wasi-preview1-api-types#prestat_dir)
The contents of a [`prestat`](#prestat) when type is [`preopentype::dir`](#preopentype.dir).
- **Size**: 4
- **Alignment**: 4
## <a href="#prestat" id="prestat"></a> `prestat`: [`Variant`](https://hackmd.io/@q/wasi-preview1-api-types#prestat)
Information about a pre-opened capability.
- **Size**: 8
- **Alignment**: 4