1 // This file is automatically generated, DO NOT EDIT
2 //
3 // To regenerate this file run the `crates/generate-raw` command
4 
5 use core::mem::MaybeUninit;
6 
7 pub use crate::error::Error;
8 pub type Result<T, E = Error> = core::result::Result<T, E>;
9 pub type Size = usize;
10 pub type Filesize = u64;
11 pub type Timestamp = u64;
12 pub type Clockid = u32;
13 /// The clock measuring real time. Time value zero corresponds with
14 /// 1970-01-01T00:00:00Z.
15 pub const CLOCKID_REALTIME: Clockid = 0;
16 /// The store-wide monotonic clock, which is defined as a clock measuring
17 /// real time, whose value cannot be adjusted and which cannot have negative
18 /// clock jumps. The epoch of this clock is undefined. The absolute time
19 /// value of this clock therefore has no meaning.
20 pub const CLOCKID_MONOTONIC: Clockid = 1;
21 /// The CPU-time clock associated with the current process.
22 pub const CLOCKID_PROCESS_CPUTIME_ID: Clockid = 2;
23 /// The CPU-time clock associated with the current thread.
24 pub const CLOCKID_THREAD_CPUTIME_ID: Clockid = 3;
25 pub type Errno = u16;
26 /// No error occurred. System call completed successfully.
27 pub const ERRNO_SUCCESS: Errno = 0;
28 /// Argument list too long.
29 pub const ERRNO_2BIG: Errno = 1;
30 /// Permission denied.
31 pub const ERRNO_ACCES: Errno = 2;
32 /// Address in use.
33 pub const ERRNO_ADDRINUSE: Errno = 3;
34 /// Address not available.
35 pub const ERRNO_ADDRNOTAVAIL: Errno = 4;
36 /// Address family not supported.
37 pub const ERRNO_AFNOSUPPORT: Errno = 5;
38 /// Resource unavailable, or operation would block.
39 pub const ERRNO_AGAIN: Errno = 6;
40 /// Connection already in progress.
41 pub const ERRNO_ALREADY: Errno = 7;
42 /// Bad file descriptor.
43 pub const ERRNO_BADF: Errno = 8;
44 /// Bad message.
45 pub const ERRNO_BADMSG: Errno = 9;
46 /// Device or resource busy.
47 pub const ERRNO_BUSY: Errno = 10;
48 /// Operation canceled.
49 pub const ERRNO_CANCELED: Errno = 11;
50 /// No child processes.
51 pub const ERRNO_CHILD: Errno = 12;
52 /// Connection aborted.
53 pub const ERRNO_CONNABORTED: Errno = 13;
54 /// Connection refused.
55 pub const ERRNO_CONNREFUSED: Errno = 14;
56 /// Connection reset.
57 pub const ERRNO_CONNRESET: Errno = 15;
58 /// Resource deadlock would occur.
59 pub const ERRNO_DEADLK: Errno = 16;
60 /// Destination address required.
61 pub const ERRNO_DESTADDRREQ: Errno = 17;
62 /// Mathematics argument out of domain of function.
63 pub const ERRNO_DOM: Errno = 18;
64 /// Reserved.
65 pub const ERRNO_DQUOT: Errno = 19;
66 /// File exists.
67 pub const ERRNO_EXIST: Errno = 20;
68 /// Bad address.
69 pub const ERRNO_FAULT: Errno = 21;
70 /// File too large.
71 pub const ERRNO_FBIG: Errno = 22;
72 /// Host is unreachable.
73 pub const ERRNO_HOSTUNREACH: Errno = 23;
74 /// Identifier removed.
75 pub const ERRNO_IDRM: Errno = 24;
76 /// Illegal byte sequence.
77 pub const ERRNO_ILSEQ: Errno = 25;
78 /// Operation in progress.
79 pub const ERRNO_INPROGRESS: Errno = 26;
80 /// Interrupted function.
81 pub const ERRNO_INTR: Errno = 27;
82 /// Invalid argument.
83 pub const ERRNO_INVAL: Errno = 28;
84 /// I/O error.
85 pub const ERRNO_IO: Errno = 29;
86 /// Socket is connected.
87 pub const ERRNO_ISCONN: Errno = 30;
88 /// Is a directory.
89 pub const ERRNO_ISDIR: Errno = 31;
90 /// Too many levels of symbolic links.
91 pub const ERRNO_LOOP: Errno = 32;
92 /// File descriptor value too large.
93 pub const ERRNO_MFILE: Errno = 33;
94 /// Too many links.
95 pub const ERRNO_MLINK: Errno = 34;
96 /// Message too large.
97 pub const ERRNO_MSGSIZE: Errno = 35;
98 /// Reserved.
99 pub const ERRNO_MULTIHOP: Errno = 36;
100 /// Filename too long.
101 pub const ERRNO_NAMETOOLONG: Errno = 37;
102 /// Network is down.
103 pub const ERRNO_NETDOWN: Errno = 38;
104 /// Connection aborted by network.
105 pub const ERRNO_NETRESET: Errno = 39;
106 /// Network unreachable.
107 pub const ERRNO_NETUNREACH: Errno = 40;
108 /// Too many files open in system.
109 pub const ERRNO_NFILE: Errno = 41;
110 /// No buffer space available.
111 pub const ERRNO_NOBUFS: Errno = 42;
112 /// No such device.
113 pub const ERRNO_NODEV: Errno = 43;
114 /// No such file or directory.
115 pub const ERRNO_NOENT: Errno = 44;
116 /// Executable file format error.
117 pub const ERRNO_NOEXEC: Errno = 45;
118 /// No locks available.
119 pub const ERRNO_NOLCK: Errno = 46;
120 /// Reserved.
121 pub const ERRNO_NOLINK: Errno = 47;
122 /// Not enough space.
123 pub const ERRNO_NOMEM: Errno = 48;
124 /// No message of the desired type.
125 pub const ERRNO_NOMSG: Errno = 49;
126 /// Protocol not available.
127 pub const ERRNO_NOPROTOOPT: Errno = 50;
128 /// No space left on device.
129 pub const ERRNO_NOSPC: Errno = 51;
130 /// Function not supported.
131 pub const ERRNO_NOSYS: Errno = 52;
132 /// The socket is not connected.
133 pub const ERRNO_NOTCONN: Errno = 53;
134 /// Not a directory or a symbolic link to a directory.
135 pub const ERRNO_NOTDIR: Errno = 54;
136 /// Directory not empty.
137 pub const ERRNO_NOTEMPTY: Errno = 55;
138 /// State not recoverable.
139 pub const ERRNO_NOTRECOVERABLE: Errno = 56;
140 /// Not a socket.
141 pub const ERRNO_NOTSOCK: Errno = 57;
142 /// Not supported, or operation not supported on socket.
143 pub const ERRNO_NOTSUP: Errno = 58;
144 /// Inappropriate I/O control operation.
145 pub const ERRNO_NOTTY: Errno = 59;
146 /// No such device or address.
147 pub const ERRNO_NXIO: Errno = 60;
148 /// Value too large to be stored in data type.
149 pub const ERRNO_OVERFLOW: Errno = 61;
150 /// Previous owner died.
151 pub const ERRNO_OWNERDEAD: Errno = 62;
152 /// Operation not permitted.
153 pub const ERRNO_PERM: Errno = 63;
154 /// Broken pipe.
155 pub const ERRNO_PIPE: Errno = 64;
156 /// Protocol error.
157 pub const ERRNO_PROTO: Errno = 65;
158 /// Protocol not supported.
159 pub const ERRNO_PROTONOSUPPORT: Errno = 66;
160 /// Protocol wrong type for socket.
161 pub const ERRNO_PROTOTYPE: Errno = 67;
162 /// Result too large.
163 pub const ERRNO_RANGE: Errno = 68;
164 /// Read-only file system.
165 pub const ERRNO_ROFS: Errno = 69;
166 /// Invalid seek.
167 pub const ERRNO_SPIPE: Errno = 70;
168 /// No such process.
169 pub const ERRNO_SRCH: Errno = 71;
170 /// Reserved.
171 pub const ERRNO_STALE: Errno = 72;
172 /// Connection timed out.
173 pub const ERRNO_TIMEDOUT: Errno = 73;
174 /// Text file busy.
175 pub const ERRNO_TXTBSY: Errno = 74;
176 /// Cross-device link.
177 pub const ERRNO_XDEV: Errno = 75;
178 /// Extension: Capabilities insufficient.
179 pub const ERRNO_NOTCAPABLE: Errno = 76;
strerror(code: u16) -> &'static str180 pub(crate) fn strerror(code: u16) -> &'static str {
181     match code {
182         ERRNO_SUCCESS => "No error occurred. System call completed successfully.",
183         ERRNO_2BIG => "Argument list too long.",
184         ERRNO_ACCES => "Permission denied.",
185         ERRNO_ADDRINUSE => "Address in use.",
186         ERRNO_ADDRNOTAVAIL => "Address not available.",
187         ERRNO_AFNOSUPPORT => "Address family not supported.",
188         ERRNO_AGAIN => "Resource unavailable, or operation would block.",
189         ERRNO_ALREADY => "Connection already in progress.",
190         ERRNO_BADF => "Bad file descriptor.",
191         ERRNO_BADMSG => "Bad message.",
192         ERRNO_BUSY => "Device or resource busy.",
193         ERRNO_CANCELED => "Operation canceled.",
194         ERRNO_CHILD => "No child processes.",
195         ERRNO_CONNABORTED => "Connection aborted.",
196         ERRNO_CONNREFUSED => "Connection refused.",
197         ERRNO_CONNRESET => "Connection reset.",
198         ERRNO_DEADLK => "Resource deadlock would occur.",
199         ERRNO_DESTADDRREQ => "Destination address required.",
200         ERRNO_DOM => "Mathematics argument out of domain of function.",
201         ERRNO_DQUOT => "Reserved.",
202         ERRNO_EXIST => "File exists.",
203         ERRNO_FAULT => "Bad address.",
204         ERRNO_FBIG => "File too large.",
205         ERRNO_HOSTUNREACH => "Host is unreachable.",
206         ERRNO_IDRM => "Identifier removed.",
207         ERRNO_ILSEQ => "Illegal byte sequence.",
208         ERRNO_INPROGRESS => "Operation in progress.",
209         ERRNO_INTR => "Interrupted function.",
210         ERRNO_INVAL => "Invalid argument.",
211         ERRNO_IO => "I/O error.",
212         ERRNO_ISCONN => "Socket is connected.",
213         ERRNO_ISDIR => "Is a directory.",
214         ERRNO_LOOP => "Too many levels of symbolic links.",
215         ERRNO_MFILE => "File descriptor value too large.",
216         ERRNO_MLINK => "Too many links.",
217         ERRNO_MSGSIZE => "Message too large.",
218         ERRNO_MULTIHOP => "Reserved.",
219         ERRNO_NAMETOOLONG => "Filename too long.",
220         ERRNO_NETDOWN => "Network is down.",
221         ERRNO_NETRESET => "Connection aborted by network.",
222         ERRNO_NETUNREACH => "Network unreachable.",
223         ERRNO_NFILE => "Too many files open in system.",
224         ERRNO_NOBUFS => "No buffer space available.",
225         ERRNO_NODEV => "No such device.",
226         ERRNO_NOENT => "No such file or directory.",
227         ERRNO_NOEXEC => "Executable file format error.",
228         ERRNO_NOLCK => "No locks available.",
229         ERRNO_NOLINK => "Reserved.",
230         ERRNO_NOMEM => "Not enough space.",
231         ERRNO_NOMSG => "No message of the desired type.",
232         ERRNO_NOPROTOOPT => "Protocol not available.",
233         ERRNO_NOSPC => "No space left on device.",
234         ERRNO_NOSYS => "Function not supported.",
235         ERRNO_NOTCONN => "The socket is not connected.",
236         ERRNO_NOTDIR => "Not a directory or a symbolic link to a directory.",
237         ERRNO_NOTEMPTY => "Directory not empty.",
238         ERRNO_NOTRECOVERABLE => "State not recoverable.",
239         ERRNO_NOTSOCK => "Not a socket.",
240         ERRNO_NOTSUP => "Not supported, or operation not supported on socket.",
241         ERRNO_NOTTY => "Inappropriate I/O control operation.",
242         ERRNO_NXIO => "No such device or address.",
243         ERRNO_OVERFLOW => "Value too large to be stored in data type.",
244         ERRNO_OWNERDEAD => "Previous owner died.",
245         ERRNO_PERM => "Operation not permitted.",
246         ERRNO_PIPE => "Broken pipe.",
247         ERRNO_PROTO => "Protocol error.",
248         ERRNO_PROTONOSUPPORT => "Protocol not supported.",
249         ERRNO_PROTOTYPE => "Protocol wrong type for socket.",
250         ERRNO_RANGE => "Result too large.",
251         ERRNO_ROFS => "Read-only file system.",
252         ERRNO_SPIPE => "Invalid seek.",
253         ERRNO_SRCH => "No such process.",
254         ERRNO_STALE => "Reserved.",
255         ERRNO_TIMEDOUT => "Connection timed out.",
256         ERRNO_TXTBSY => "Text file busy.",
257         ERRNO_XDEV => "Cross-device link.",
258         ERRNO_NOTCAPABLE => "Extension: Capabilities insufficient.",
259         _ => "Unknown error.",
260     }
261 }
262 pub type Rights = u64;
263 /// The right to invoke `fd_datasync`.
264 /// If `path_open` is set, includes the right to invoke
265 /// `path_open` with `fdflags::dsync`.
266 pub const RIGHTS_FD_DATASYNC: Rights = 0x1;
267 /// The right to invoke `fd_read` and `sock_recv`.
268 /// If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
269 pub const RIGHTS_FD_READ: Rights = 0x2;
270 /// The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
271 pub const RIGHTS_FD_SEEK: Rights = 0x4;
272 /// The right to invoke `fd_fdstat_set_flags`.
273 pub const RIGHTS_FD_FDSTAT_SET_FLAGS: Rights = 0x8;
274 /// The right to invoke `fd_sync`.
275 /// If `path_open` is set, includes the right to invoke
276 /// `path_open` with `fdflags::rsync` and `fdflags::dsync`.
277 pub const RIGHTS_FD_SYNC: Rights = 0x10;
278 /// The right to invoke `fd_seek` in such a way that the file offset
279 /// remains unaltered (i.e., `whence::cur` with offset zero), or to
280 /// invoke `fd_tell`.
281 pub const RIGHTS_FD_TELL: Rights = 0x20;
282 /// The right to invoke `fd_write` and `sock_send`.
283 /// If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
284 pub const RIGHTS_FD_WRITE: Rights = 0x40;
285 /// The right to invoke `fd_advise`.
286 pub const RIGHTS_FD_ADVISE: Rights = 0x80;
287 /// The right to invoke `fd_allocate`.
288 pub const RIGHTS_FD_ALLOCATE: Rights = 0x100;
289 /// The right to invoke `path_create_directory`.
290 pub const RIGHTS_PATH_CREATE_DIRECTORY: Rights = 0x200;
291 /// If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
292 pub const RIGHTS_PATH_CREATE_FILE: Rights = 0x400;
293 /// The right to invoke `path_link` with the file descriptor as the
294 /// source directory.
295 pub const RIGHTS_PATH_LINK_SOURCE: Rights = 0x800;
296 /// The right to invoke `path_link` with the file descriptor as the
297 /// target directory.
298 pub const RIGHTS_PATH_LINK_TARGET: Rights = 0x1000;
299 /// The right to invoke `path_open`.
300 pub const RIGHTS_PATH_OPEN: Rights = 0x2000;
301 /// The right to invoke `fd_readdir`.
302 pub const RIGHTS_FD_READDIR: Rights = 0x4000;
303 /// The right to invoke `path_readlink`.
304 pub const RIGHTS_PATH_READLINK: Rights = 0x8000;
305 /// The right to invoke `path_rename` with the file descriptor as the source directory.
306 pub const RIGHTS_PATH_RENAME_SOURCE: Rights = 0x10000;
307 /// The right to invoke `path_rename` with the file descriptor as the target directory.
308 pub const RIGHTS_PATH_RENAME_TARGET: Rights = 0x20000;
309 /// The right to invoke `path_filestat_get`.
310 pub const RIGHTS_PATH_FILESTAT_GET: Rights = 0x40000;
311 /// The right to change a file's size (there is no `path_filestat_set_size`).
312 /// If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`.
313 pub const RIGHTS_PATH_FILESTAT_SET_SIZE: Rights = 0x80000;
314 /// The right to invoke `path_filestat_set_times`.
315 pub const RIGHTS_PATH_FILESTAT_SET_TIMES: Rights = 0x100000;
316 /// The right to invoke `fd_filestat_get`.
317 pub const RIGHTS_FD_FILESTAT_GET: Rights = 0x200000;
318 /// The right to invoke `fd_filestat_set_size`.
319 pub const RIGHTS_FD_FILESTAT_SET_SIZE: Rights = 0x400000;
320 /// The right to invoke `fd_filestat_set_times`.
321 pub const RIGHTS_FD_FILESTAT_SET_TIMES: Rights = 0x800000;
322 /// The right to invoke `path_symlink`.
323 pub const RIGHTS_PATH_SYMLINK: Rights = 0x1000000;
324 /// The right to invoke `path_remove_directory`.
325 pub const RIGHTS_PATH_REMOVE_DIRECTORY: Rights = 0x2000000;
326 /// The right to invoke `path_unlink_file`.
327 pub const RIGHTS_PATH_UNLINK_FILE: Rights = 0x4000000;
328 /// If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
329 /// If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
330 pub const RIGHTS_POLL_FD_READWRITE: Rights = 0x8000000;
331 /// The right to invoke `sock_shutdown`.
332 pub const RIGHTS_SOCK_SHUTDOWN: Rights = 0x10000000;
333 pub type Fd = u32;
334 #[repr(C)]
335 #[derive(Copy, Clone, Debug)]
336 pub struct Iovec {
337     /// The address of the buffer to be filled.
338     pub buf: *mut u8,
339     /// The length of the buffer to be filled.
340     pub buf_len: Size,
341 }
342 #[repr(C)]
343 #[derive(Copy, Clone, Debug)]
344 pub struct Ciovec {
345     /// The address of the buffer to be written.
346     pub buf: *const u8,
347     /// The length of the buffer to be written.
348     pub buf_len: Size,
349 }
350 pub type IovecArray<'a> = &'a [Iovec];
351 pub type CiovecArray<'a> = &'a [Ciovec];
352 pub type Filedelta = i64;
353 pub type Whence = u8;
354 /// Seek relative to start-of-file.
355 pub const WHENCE_SET: Whence = 0;
356 /// Seek relative to current position.
357 pub const WHENCE_CUR: Whence = 1;
358 /// Seek relative to end-of-file.
359 pub const WHENCE_END: Whence = 2;
360 pub type Dircookie = u64;
361 pub type Dirnamlen = u32;
362 pub type Inode = u64;
363 pub type Filetype = u8;
364 /// The type of the file descriptor or file is unknown or is different from any of the other types specified.
365 pub const FILETYPE_UNKNOWN: Filetype = 0;
366 /// The file descriptor or file refers to a block device inode.
367 pub const FILETYPE_BLOCK_DEVICE: Filetype = 1;
368 /// The file descriptor or file refers to a character device inode.
369 pub const FILETYPE_CHARACTER_DEVICE: Filetype = 2;
370 /// The file descriptor or file refers to a directory inode.
371 pub const FILETYPE_DIRECTORY: Filetype = 3;
372 /// The file descriptor or file refers to a regular file inode.
373 pub const FILETYPE_REGULAR_FILE: Filetype = 4;
374 /// The file descriptor or file refers to a datagram socket.
375 pub const FILETYPE_SOCKET_DGRAM: Filetype = 5;
376 /// The file descriptor or file refers to a byte-stream socket.
377 pub const FILETYPE_SOCKET_STREAM: Filetype = 6;
378 /// The file refers to a symbolic link inode.
379 pub const FILETYPE_SYMBOLIC_LINK: Filetype = 7;
380 #[repr(C)]
381 #[derive(Copy, Clone, Debug)]
382 pub struct Dirent {
383     /// The offset of the next directory entry stored in this directory.
384     pub d_next: Dircookie,
385     /// The serial number of the file referred to by this directory entry.
386     pub d_ino: Inode,
387     /// The length of the name of the directory entry.
388     pub d_namlen: Dirnamlen,
389     /// The type of the file referred to by this directory entry.
390     pub d_type: Filetype,
391 }
392 pub type Advice = u8;
393 /// The application has no advice to give on its behavior with respect to the specified data.
394 pub const ADVICE_NORMAL: Advice = 0;
395 /// The application expects to access the specified data sequentially from lower offsets to higher offsets.
396 pub const ADVICE_SEQUENTIAL: Advice = 1;
397 /// The application expects to access the specified data in a random order.
398 pub const ADVICE_RANDOM: Advice = 2;
399 /// The application expects to access the specified data in the near future.
400 pub const ADVICE_WILLNEED: Advice = 3;
401 /// The application expects that it will not access the specified data in the near future.
402 pub const ADVICE_DONTNEED: Advice = 4;
403 /// The application expects to access the specified data once and then not reuse it thereafter.
404 pub const ADVICE_NOREUSE: Advice = 5;
405 pub type Fdflags = u16;
406 /// Append mode: Data written to the file is always appended to the file's end.
407 pub const FDFLAGS_APPEND: Fdflags = 0x1;
408 /// Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
409 pub const FDFLAGS_DSYNC: Fdflags = 0x2;
410 /// Non-blocking mode.
411 pub const FDFLAGS_NONBLOCK: Fdflags = 0x4;
412 /// Synchronized read I/O operations.
413 pub const FDFLAGS_RSYNC: Fdflags = 0x8;
414 /// Write according to synchronized I/O file integrity completion. In
415 /// addition to synchronizing the data stored in the file, the implementation
416 /// may also synchronously update the file's metadata.
417 pub const FDFLAGS_SYNC: Fdflags = 0x10;
418 #[repr(C)]
419 #[derive(Copy, Clone, Debug)]
420 pub struct Fdstat {
421     /// File type.
422     pub fs_filetype: Filetype,
423     /// File descriptor flags.
424     pub fs_flags: Fdflags,
425     /// Rights that apply to this file descriptor.
426     pub fs_rights_base: Rights,
427     /// Maximum set of rights that may be installed on new file descriptors that
428     /// are created through this file descriptor, e.g., through `path_open`.
429     pub fs_rights_inheriting: Rights,
430 }
431 pub type Device = u64;
432 pub type Fstflags = u16;
433 /// Adjust the last data access timestamp to the value stored in `filestat::atim`.
434 pub const FSTFLAGS_ATIM: Fstflags = 0x1;
435 /// Adjust the last data access timestamp to the time of clock `clockid::realtime`.
436 pub const FSTFLAGS_ATIM_NOW: Fstflags = 0x2;
437 /// Adjust the last data modification timestamp to the value stored in `filestat::mtim`.
438 pub const FSTFLAGS_MTIM: Fstflags = 0x4;
439 /// Adjust the last data modification timestamp to the time of clock `clockid::realtime`.
440 pub const FSTFLAGS_MTIM_NOW: Fstflags = 0x8;
441 pub type Lookupflags = u32;
442 /// As long as the resolved path corresponds to a symbolic link, it is expanded.
443 pub const LOOKUPFLAGS_SYMLINK_FOLLOW: Lookupflags = 0x1;
444 pub type Oflags = u16;
445 /// Create file if it does not exist.
446 pub const OFLAGS_CREAT: Oflags = 0x1;
447 /// Fail if not a directory.
448 pub const OFLAGS_DIRECTORY: Oflags = 0x2;
449 /// Fail if file already exists.
450 pub const OFLAGS_EXCL: Oflags = 0x4;
451 /// Truncate file to size 0.
452 pub const OFLAGS_TRUNC: Oflags = 0x8;
453 pub type Linkcount = u64;
454 #[repr(C)]
455 #[derive(Copy, Clone, Debug)]
456 pub struct Filestat {
457     /// Device ID of device containing the file.
458     pub dev: Device,
459     /// File serial number.
460     pub ino: Inode,
461     /// File type.
462     pub filetype: Filetype,
463     /// Number of hard links to the file.
464     pub nlink: Linkcount,
465     /// For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
466     pub size: Filesize,
467     /// Last data access timestamp.
468     pub atim: Timestamp,
469     /// Last data modification timestamp.
470     pub mtim: Timestamp,
471     /// Last file status change timestamp.
472     pub ctim: Timestamp,
473 }
474 pub type Userdata = u64;
475 pub type Eventtype = u8;
476 /// The time value of clock `subscription_clock::id` has
477 /// reached timestamp `subscription_clock::timeout`.
478 pub const EVENTTYPE_CLOCK: Eventtype = 0;
479 /// File descriptor `subscription_fd_readwrite::file_descriptor` has data
480 /// available for reading. This event always triggers for regular files.
481 pub const EVENTTYPE_FD_READ: Eventtype = 1;
482 /// File descriptor `subscription_fd_readwrite::file_descriptor` has capacity
483 /// available for writing. This event always triggers for regular files.
484 pub const EVENTTYPE_FD_WRITE: Eventtype = 2;
485 pub type Eventrwflags = u16;
486 /// The peer of this socket has closed or disconnected.
487 pub const EVENTRWFLAGS_FD_READWRITE_HANGUP: Eventrwflags = 0x1;
488 #[repr(C)]
489 #[derive(Copy, Clone, Debug)]
490 pub struct EventFdReadwrite {
491     /// The number of bytes available for reading or writing.
492     pub nbytes: Filesize,
493     /// The state of the file descriptor.
494     pub flags: Eventrwflags,
495 }
496 #[repr(C)]
497 #[derive(Copy, Clone, Debug)]
498 pub struct Event {
499     /// User-provided value that got attached to `subscription::userdata`.
500     pub userdata: Userdata,
501     /// If non-zero, an error that occurred while processing the subscription request.
502     pub error: Errno,
503     /// The type of event that occured
504     pub r#type: Eventtype,
505     /// The contents of the event, if it is an `eventtype::fd_read` or
506     /// `eventtype::fd_write`. `eventtype::clock` events ignore this field.
507     pub fd_readwrite: EventFdReadwrite,
508 }
509 pub type Subclockflags = u16;
510 /// If set, treat the timestamp provided in
511 /// `subscription_clock::timeout` as an absolute timestamp of clock
512 /// `subscription_clock::id`. If clear, treat the timestamp
513 /// provided in `subscription_clock::timeout` relative to the
514 /// current time value of clock `subscription_clock::id`.
515 pub const SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME: Subclockflags = 0x1;
516 #[repr(C)]
517 #[derive(Copy, Clone, Debug)]
518 pub struct SubscriptionClock {
519     /// The clock against which to compare the timestamp.
520     pub id: Clockid,
521     /// The absolute or relative timestamp.
522     pub timeout: Timestamp,
523     /// The amount of time that the implementation may wait additionally
524     /// to coalesce with other events.
525     pub precision: Timestamp,
526     /// Flags specifying whether the timeout is absolute or relative
527     pub flags: Subclockflags,
528 }
529 #[repr(C)]
530 #[derive(Copy, Clone, Debug)]
531 pub struct SubscriptionFdReadwrite {
532     /// The file descriptor on which to wait for it to become ready for reading or writing.
533     pub file_descriptor: Fd,
534 }
535 #[repr(C)]
536 #[derive(Copy, Clone)]
537 pub union SubscriptionUU {
538     pub clock: SubscriptionClock,
539     pub fd_read: SubscriptionFdReadwrite,
540     pub fd_write: SubscriptionFdReadwrite,
541 }
542 #[repr(C)]
543 #[derive(Copy, Clone)]
544 pub struct SubscriptionU {
545     pub tag: Eventtype,
546     pub u: SubscriptionUU,
547 }
548 
549 #[repr(C)]
550 #[derive(Copy, Clone)]
551 pub struct Subscription {
552     /// User-provided value that is attached to the subscription in the
553     /// implementation and returned through `event::userdata`.
554     pub userdata: Userdata,
555     /// The type of the event to which to subscribe, and its contents
556     pub u: SubscriptionU,
557 }
558 pub type Exitcode = u32;
559 pub type Signal = u8;
560 /// No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
561 /// so this value is reserved.
562 pub const SIGNAL_NONE: Signal = 0;
563 /// Hangup.
564 /// Action: Terminates the process.
565 pub const SIGNAL_HUP: Signal = 1;
566 /// Terminate interrupt signal.
567 /// Action: Terminates the process.
568 pub const SIGNAL_INT: Signal = 2;
569 /// Terminal quit signal.
570 /// Action: Terminates the process.
571 pub const SIGNAL_QUIT: Signal = 3;
572 /// Illegal instruction.
573 /// Action: Terminates the process.
574 pub const SIGNAL_ILL: Signal = 4;
575 /// Trace/breakpoint trap.
576 /// Action: Terminates the process.
577 pub const SIGNAL_TRAP: Signal = 5;
578 /// Process abort signal.
579 /// Action: Terminates the process.
580 pub const SIGNAL_ABRT: Signal = 6;
581 /// Access to an undefined portion of a memory object.
582 /// Action: Terminates the process.
583 pub const SIGNAL_BUS: Signal = 7;
584 /// Erroneous arithmetic operation.
585 /// Action: Terminates the process.
586 pub const SIGNAL_FPE: Signal = 8;
587 /// Kill.
588 /// Action: Terminates the process.
589 pub const SIGNAL_KILL: Signal = 9;
590 /// User-defined signal 1.
591 /// Action: Terminates the process.
592 pub const SIGNAL_USR1: Signal = 10;
593 /// Invalid memory reference.
594 /// Action: Terminates the process.
595 pub const SIGNAL_SEGV: Signal = 11;
596 /// User-defined signal 2.
597 /// Action: Terminates the process.
598 pub const SIGNAL_USR2: Signal = 12;
599 /// Write on a pipe with no one to read it.
600 /// Action: Ignored.
601 pub const SIGNAL_PIPE: Signal = 13;
602 /// Alarm clock.
603 /// Action: Terminates the process.
604 pub const SIGNAL_ALRM: Signal = 14;
605 /// Termination signal.
606 /// Action: Terminates the process.
607 pub const SIGNAL_TERM: Signal = 15;
608 /// Child process terminated, stopped, or continued.
609 /// Action: Ignored.
610 pub const SIGNAL_CHLD: Signal = 16;
611 /// Continue executing, if stopped.
612 /// Action: Continues executing, if stopped.
613 pub const SIGNAL_CONT: Signal = 17;
614 /// Stop executing.
615 /// Action: Stops executing.
616 pub const SIGNAL_STOP: Signal = 18;
617 /// Terminal stop signal.
618 /// Action: Stops executing.
619 pub const SIGNAL_TSTP: Signal = 19;
620 /// Background process attempting read.
621 /// Action: Stops executing.
622 pub const SIGNAL_TTIN: Signal = 20;
623 /// Background process attempting write.
624 /// Action: Stops executing.
625 pub const SIGNAL_TTOU: Signal = 21;
626 /// High bandwidth data is available at a socket.
627 /// Action: Ignored.
628 pub const SIGNAL_URG: Signal = 22;
629 /// CPU time limit exceeded.
630 /// Action: Terminates the process.
631 pub const SIGNAL_XCPU: Signal = 23;
632 /// File size limit exceeded.
633 /// Action: Terminates the process.
634 pub const SIGNAL_XFSZ: Signal = 24;
635 /// Virtual timer expired.
636 /// Action: Terminates the process.
637 pub const SIGNAL_VTALRM: Signal = 25;
638 /// Profiling timer expired.
639 /// Action: Terminates the process.
640 pub const SIGNAL_PROF: Signal = 26;
641 /// Window changed.
642 /// Action: Ignored.
643 pub const SIGNAL_WINCH: Signal = 27;
644 /// I/O possible.
645 /// Action: Terminates the process.
646 pub const SIGNAL_POLL: Signal = 28;
647 /// Power failure.
648 /// Action: Terminates the process.
649 pub const SIGNAL_PWR: Signal = 29;
650 /// Bad system call.
651 /// Action: Terminates the process.
652 pub const SIGNAL_SYS: Signal = 30;
653 pub type Riflags = u16;
654 /// Returns the message without removing it from the socket's receive queue.
655 pub const RIFLAGS_RECV_PEEK: Riflags = 0x1;
656 /// On byte-stream sockets, block until the full amount of data can be returned.
657 pub const RIFLAGS_RECV_WAITALL: Riflags = 0x2;
658 pub type Roflags = u16;
659 /// Returned by `sock_recv`: Message data has been truncated.
660 pub const ROFLAGS_RECV_DATA_TRUNCATED: Roflags = 0x1;
661 pub type Siflags = u16;
662 pub type Sdflags = u8;
663 /// Disables further receive operations.
664 pub const SDFLAGS_RD: Sdflags = 0x1;
665 /// Disables further send operations.
666 pub const SDFLAGS_WR: Sdflags = 0x2;
667 pub type Preopentype = u8;
668 /// A pre-opened directory.
669 pub const PREOPENTYPE_DIR: Preopentype = 0;
670 #[repr(C)]
671 #[derive(Copy, Clone, Debug)]
672 pub struct PrestatDir {
673     /// The length of the directory name for use with `fd_prestat_dir_name`.
674     pub pr_name_len: Size,
675 }
676 #[repr(C)]
677 #[derive(Copy, Clone)]
678 pub union PrestatU {
679     pub dir: PrestatDir,
680 }
681 #[repr(C)]
682 #[derive(Copy, Clone)]
683 pub struct Prestat {
684     pub tag: Preopentype,
685     pub u: PrestatU,
686 }
687 
688 /// Read command-line argument data.
689 /// The size of the array should match that returned by `args_sizes_get`
args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Result<()>690 pub unsafe fn args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Result<()> {
691     let rc = wasi_snapshot_preview1::args_get(argv, argv_buf);
692     if let Some(err) = Error::from_raw_error(rc) {
693         Err(err)
694     } else {
695         Ok(())
696     }
697 }
698 
699 /// Return command-line argument data sizes.
700 ///
701 /// ## Return
702 ///
703 /// * `argc` - The number of arguments.
704 /// * `argv_buf_size` - The size of the argument string data.
args_sizes_get() -> Result<(Size, Size)>705 pub unsafe fn args_sizes_get() -> Result<(Size, Size)> {
706     let mut argc = MaybeUninit::uninit();
707     let mut argv_buf_size = MaybeUninit::uninit();
708     let rc = wasi_snapshot_preview1::args_sizes_get(argc.as_mut_ptr(), argv_buf_size.as_mut_ptr());
709     if let Some(err) = Error::from_raw_error(rc) {
710         Err(err)
711     } else {
712         Ok((argc.assume_init(), argv_buf_size.assume_init()))
713     }
714 }
715 
716 /// Read environment variable data.
717 /// The sizes of the buffers should match that returned by `environ_sizes_get`.
environ_get(environ: *mut *mut u8, environ_buf: *mut u8) -> Result<()>718 pub unsafe fn environ_get(environ: *mut *mut u8, environ_buf: *mut u8) -> Result<()> {
719     let rc = wasi_snapshot_preview1::environ_get(environ, environ_buf);
720     if let Some(err) = Error::from_raw_error(rc) {
721         Err(err)
722     } else {
723         Ok(())
724     }
725 }
726 
727 /// Return environment variable data sizes.
728 ///
729 /// ## Return
730 ///
731 /// * `environc` - The number of environment variable arguments.
732 /// * `environ_buf_size` - The size of the environment variable data.
environ_sizes_get() -> Result<(Size, Size)>733 pub unsafe fn environ_sizes_get() -> Result<(Size, Size)> {
734     let mut environc = MaybeUninit::uninit();
735     let mut environ_buf_size = MaybeUninit::uninit();
736     let rc = wasi_snapshot_preview1::environ_sizes_get(
737         environc.as_mut_ptr(),
738         environ_buf_size.as_mut_ptr(),
739     );
740     if let Some(err) = Error::from_raw_error(rc) {
741         Err(err)
742     } else {
743         Ok((environc.assume_init(), environ_buf_size.assume_init()))
744     }
745 }
746 
747 /// Return the resolution of a clock.
748 /// Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
749 /// return `errno::inval`.
750 /// Note: This is similar to `clock_getres` in POSIX.
751 ///
752 /// ## Parameters
753 ///
754 /// * `id` - The clock for which to return the resolution.
755 ///
756 /// ## Return
757 ///
758 /// * `resolution` - The resolution of the clock.
clock_res_get(id: Clockid) -> Result<Timestamp>759 pub unsafe fn clock_res_get(id: Clockid) -> Result<Timestamp> {
760     let mut resolution = MaybeUninit::uninit();
761     let rc = wasi_snapshot_preview1::clock_res_get(id, resolution.as_mut_ptr());
762     if let Some(err) = Error::from_raw_error(rc) {
763         Err(err)
764     } else {
765         Ok(resolution.assume_init())
766     }
767 }
768 
769 /// Return the time value of a clock.
770 /// Note: This is similar to `clock_gettime` in POSIX.
771 ///
772 /// ## Parameters
773 ///
774 /// * `id` - The clock for which to return the time.
775 /// * `precision` - The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
776 ///
777 /// ## Return
778 ///
779 /// * `time` - The time value of the clock.
clock_time_get(id: Clockid, precision: Timestamp) -> Result<Timestamp>780 pub unsafe fn clock_time_get(id: Clockid, precision: Timestamp) -> Result<Timestamp> {
781     let mut time = MaybeUninit::uninit();
782     let rc = wasi_snapshot_preview1::clock_time_get(id, precision, time.as_mut_ptr());
783     if let Some(err) = Error::from_raw_error(rc) {
784         Err(err)
785     } else {
786         Ok(time.assume_init())
787     }
788 }
789 
790 /// Provide file advisory information on a file descriptor.
791 /// Note: This is similar to `posix_fadvise` in POSIX.
792 ///
793 /// ## Parameters
794 ///
795 /// * `offset` - The offset within the file to which the advisory applies.
796 /// * `len` - The length of the region to which the advisory applies.
797 /// * `advice` - The advice.
fd_advise(fd: Fd, offset: Filesize, len: Filesize, advice: Advice) -> Result<()>798 pub unsafe fn fd_advise(fd: Fd, offset: Filesize, len: Filesize, advice: Advice) -> Result<()> {
799     let rc = wasi_snapshot_preview1::fd_advise(fd, offset, len, advice);
800     if let Some(err) = Error::from_raw_error(rc) {
801         Err(err)
802     } else {
803         Ok(())
804     }
805 }
806 
807 /// Force the allocation of space in a file.
808 /// Note: This is similar to `posix_fallocate` in POSIX.
809 ///
810 /// ## Parameters
811 ///
812 /// * `offset` - The offset at which to start the allocation.
813 /// * `len` - The length of the area that is allocated.
fd_allocate(fd: Fd, offset: Filesize, len: Filesize) -> Result<()>814 pub unsafe fn fd_allocate(fd: Fd, offset: Filesize, len: Filesize) -> Result<()> {
815     let rc = wasi_snapshot_preview1::fd_allocate(fd, offset, len);
816     if let Some(err) = Error::from_raw_error(rc) {
817         Err(err)
818     } else {
819         Ok(())
820     }
821 }
822 
823 /// Close a file descriptor.
824 /// Note: This is similar to `close` in POSIX.
fd_close(fd: Fd) -> Result<()>825 pub unsafe fn fd_close(fd: Fd) -> Result<()> {
826     let rc = wasi_snapshot_preview1::fd_close(fd);
827     if let Some(err) = Error::from_raw_error(rc) {
828         Err(err)
829     } else {
830         Ok(())
831     }
832 }
833 
834 /// Synchronize the data of a file to disk.
835 /// Note: This is similar to `fdatasync` in POSIX.
fd_datasync(fd: Fd) -> Result<()>836 pub unsafe fn fd_datasync(fd: Fd) -> Result<()> {
837     let rc = wasi_snapshot_preview1::fd_datasync(fd);
838     if let Some(err) = Error::from_raw_error(rc) {
839         Err(err)
840     } else {
841         Ok(())
842     }
843 }
844 
845 /// Get the attributes of a file descriptor.
846 /// Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
847 ///
848 /// ## Return
849 ///
850 /// * `stat` - The buffer where the file descriptor's attributes are stored.
fd_fdstat_get(fd: Fd) -> Result<Fdstat>851 pub unsafe fn fd_fdstat_get(fd: Fd) -> Result<Fdstat> {
852     let mut stat = MaybeUninit::uninit();
853     let rc = wasi_snapshot_preview1::fd_fdstat_get(fd, stat.as_mut_ptr());
854     if let Some(err) = Error::from_raw_error(rc) {
855         Err(err)
856     } else {
857         Ok(stat.assume_init())
858     }
859 }
860 
861 /// Adjust the flags associated with a file descriptor.
862 /// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
863 ///
864 /// ## Parameters
865 ///
866 /// * `flags` - The desired values of the file descriptor flags.
fd_fdstat_set_flags(fd: Fd, flags: Fdflags) -> Result<()>867 pub unsafe fn fd_fdstat_set_flags(fd: Fd, flags: Fdflags) -> Result<()> {
868     let rc = wasi_snapshot_preview1::fd_fdstat_set_flags(fd, flags);
869     if let Some(err) = Error::from_raw_error(rc) {
870         Err(err)
871     } else {
872         Ok(())
873     }
874 }
875 
876 /// Adjust the rights associated with a file descriptor.
877 /// This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
878 ///
879 /// ## Parameters
880 ///
881 /// * `fs_rights_base` - The desired rights of the file descriptor.
fd_fdstat_set_rights( fd: Fd, fs_rights_base: Rights, fs_rights_inheriting: Rights, ) -> Result<()>882 pub unsafe fn fd_fdstat_set_rights(
883     fd: Fd,
884     fs_rights_base: Rights,
885     fs_rights_inheriting: Rights,
886 ) -> Result<()> {
887     let rc = wasi_snapshot_preview1::fd_fdstat_set_rights(fd, fs_rights_base, fs_rights_inheriting);
888     if let Some(err) = Error::from_raw_error(rc) {
889         Err(err)
890     } else {
891         Ok(())
892     }
893 }
894 
895 /// Return the attributes of an open file.
896 ///
897 /// ## Return
898 ///
899 /// * `buf` - The buffer where the file's attributes are stored.
fd_filestat_get(fd: Fd) -> Result<Filestat>900 pub unsafe fn fd_filestat_get(fd: Fd) -> Result<Filestat> {
901     let mut buf = MaybeUninit::uninit();
902     let rc = wasi_snapshot_preview1::fd_filestat_get(fd, buf.as_mut_ptr());
903     if let Some(err) = Error::from_raw_error(rc) {
904         Err(err)
905     } else {
906         Ok(buf.assume_init())
907     }
908 }
909 
910 /// Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
911 /// Note: This is similar to `ftruncate` in POSIX.
912 ///
913 /// ## Parameters
914 ///
915 /// * `size` - The desired file size.
fd_filestat_set_size(fd: Fd, size: Filesize) -> Result<()>916 pub unsafe fn fd_filestat_set_size(fd: Fd, size: Filesize) -> Result<()> {
917     let rc = wasi_snapshot_preview1::fd_filestat_set_size(fd, size);
918     if let Some(err) = Error::from_raw_error(rc) {
919         Err(err)
920     } else {
921         Ok(())
922     }
923 }
924 
925 /// Adjust the timestamps of an open file or directory.
926 /// Note: This is similar to `futimens` in POSIX.
927 ///
928 /// ## Parameters
929 ///
930 /// * `atim` - The desired values of the data access timestamp.
931 /// * `mtim` - The desired values of the data modification timestamp.
932 /// * `fst_flags` - A bitmask indicating which timestamps to adjust.
fd_filestat_set_times( fd: Fd, atim: Timestamp, mtim: Timestamp, fst_flags: Fstflags, ) -> Result<()>933 pub unsafe fn fd_filestat_set_times(
934     fd: Fd,
935     atim: Timestamp,
936     mtim: Timestamp,
937     fst_flags: Fstflags,
938 ) -> Result<()> {
939     let rc = wasi_snapshot_preview1::fd_filestat_set_times(fd, atim, mtim, fst_flags);
940     if let Some(err) = Error::from_raw_error(rc) {
941         Err(err)
942     } else {
943         Ok(())
944     }
945 }
946 
947 /// Read from a file descriptor, without using and updating the file descriptor's offset.
948 /// Note: This is similar to `preadv` in POSIX.
949 ///
950 /// ## Parameters
951 ///
952 /// * `iovs` - List of scatter/gather vectors in which to store data.
953 /// * `offset` - The offset within the file at which to read.
954 ///
955 /// ## Return
956 ///
957 /// * `nread` - The number of bytes read.
fd_pread(fd: Fd, iovs: IovecArray, offset: Filesize) -> Result<Size>958 pub unsafe fn fd_pread(fd: Fd, iovs: IovecArray, offset: Filesize) -> Result<Size> {
959     let mut nread = MaybeUninit::uninit();
960     let rc =
961         wasi_snapshot_preview1::fd_pread(fd, iovs.as_ptr(), iovs.len(), offset, nread.as_mut_ptr());
962     if let Some(err) = Error::from_raw_error(rc) {
963         Err(err)
964     } else {
965         Ok(nread.assume_init())
966     }
967 }
968 
969 /// Return a description of the given preopened file descriptor.
970 ///
971 /// ## Return
972 ///
973 /// * `buf` - The buffer where the description is stored.
fd_prestat_get(fd: Fd) -> Result<Prestat>974 pub unsafe fn fd_prestat_get(fd: Fd) -> Result<Prestat> {
975     let mut buf = MaybeUninit::uninit();
976     let rc = wasi_snapshot_preview1::fd_prestat_get(fd, buf.as_mut_ptr());
977     if let Some(err) = Error::from_raw_error(rc) {
978         Err(err)
979     } else {
980         Ok(buf.assume_init())
981     }
982 }
983 
984 /// Return a description of the given preopened file descriptor.
985 ///
986 /// ## Parameters
987 ///
988 /// * `path` - A buffer into which to write the preopened directory name.
fd_prestat_dir_name(fd: Fd, path: *mut u8, path_len: Size) -> Result<()>989 pub unsafe fn fd_prestat_dir_name(fd: Fd, path: *mut u8, path_len: Size) -> Result<()> {
990     let rc = wasi_snapshot_preview1::fd_prestat_dir_name(fd, path, path_len);
991     if let Some(err) = Error::from_raw_error(rc) {
992         Err(err)
993     } else {
994         Ok(())
995     }
996 }
997 
998 /// Write to a file descriptor, without using and updating the file descriptor's offset.
999 /// Note: This is similar to `pwritev` in POSIX.
1000 ///
1001 /// ## Parameters
1002 ///
1003 /// * `iovs` - List of scatter/gather vectors from which to retrieve data.
1004 /// * `offset` - The offset within the file at which to write.
1005 ///
1006 /// ## Return
1007 ///
1008 /// * `nwritten` - The number of bytes written.
fd_pwrite(fd: Fd, iovs: CiovecArray, offset: Filesize) -> Result<Size>1009 pub unsafe fn fd_pwrite(fd: Fd, iovs: CiovecArray, offset: Filesize) -> Result<Size> {
1010     let mut nwritten = MaybeUninit::uninit();
1011     let rc = wasi_snapshot_preview1::fd_pwrite(
1012         fd,
1013         iovs.as_ptr(),
1014         iovs.len(),
1015         offset,
1016         nwritten.as_mut_ptr(),
1017     );
1018     if let Some(err) = Error::from_raw_error(rc) {
1019         Err(err)
1020     } else {
1021         Ok(nwritten.assume_init())
1022     }
1023 }
1024 
1025 /// Read from a file descriptor.
1026 /// Note: This is similar to `readv` in POSIX.
1027 ///
1028 /// ## Parameters
1029 ///
1030 /// * `iovs` - List of scatter/gather vectors to which to store data.
1031 ///
1032 /// ## Return
1033 ///
1034 /// * `nread` - The number of bytes read.
fd_read(fd: Fd, iovs: IovecArray) -> Result<Size>1035 pub unsafe fn fd_read(fd: Fd, iovs: IovecArray) -> Result<Size> {
1036     let mut nread = MaybeUninit::uninit();
1037     let rc = wasi_snapshot_preview1::fd_read(fd, iovs.as_ptr(), iovs.len(), nread.as_mut_ptr());
1038     if let Some(err) = Error::from_raw_error(rc) {
1039         Err(err)
1040     } else {
1041         Ok(nread.assume_init())
1042     }
1043 }
1044 
1045 /// Read directory entries from a directory.
1046 /// When successful, the contents of the output buffer consist of a sequence of
1047 /// directory entries. Each directory entry consists of a dirent_t object,
1048 /// followed by dirent_t::d_namlen bytes holding the name of the directory
1049 /// entry.
1050 /// This function fills the output buffer as much as possible, potentially
1051 /// truncating the last directory entry. This allows the caller to grow its
1052 /// read buffer size in case it's too small to fit a single large directory
1053 /// entry, or skip the oversized directory entry.
1054 ///
1055 /// ## Parameters
1056 ///
1057 /// * `buf` - The buffer where directory entries are stored
1058 /// * `cookie` - The location within the directory to start reading
1059 ///
1060 /// ## Return
1061 ///
1062 /// * `bufused` - 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.
fd_readdir(fd: Fd, buf: *mut u8, buf_len: Size, cookie: Dircookie) -> Result<Size>1063 pub unsafe fn fd_readdir(fd: Fd, buf: *mut u8, buf_len: Size, cookie: Dircookie) -> Result<Size> {
1064     let mut bufused = MaybeUninit::uninit();
1065     let rc = wasi_snapshot_preview1::fd_readdir(fd, buf, buf_len, cookie, bufused.as_mut_ptr());
1066     if let Some(err) = Error::from_raw_error(rc) {
1067         Err(err)
1068     } else {
1069         Ok(bufused.assume_init())
1070     }
1071 }
1072 
1073 /// Atomically replace a file descriptor by renumbering another file descriptor.
1074 /// Due to the strong focus on thread safety, this environment does not provide
1075 /// a mechanism to duplicate or renumber a file descriptor to an arbitrary
1076 /// number, like `dup2()`. This would be prone to race conditions, as an actual
1077 /// file descriptor with the same number could be allocated by a different
1078 /// thread at the same time.
1079 /// This function provides a way to atomically renumber file descriptors, which
1080 /// would disappear if `dup2()` were to be removed entirely.
1081 ///
1082 /// ## Parameters
1083 ///
1084 /// * `to` - The file descriptor to overwrite.
fd_renumber(fd: Fd, to: Fd) -> Result<()>1085 pub unsafe fn fd_renumber(fd: Fd, to: Fd) -> Result<()> {
1086     let rc = wasi_snapshot_preview1::fd_renumber(fd, to);
1087     if let Some(err) = Error::from_raw_error(rc) {
1088         Err(err)
1089     } else {
1090         Ok(())
1091     }
1092 }
1093 
1094 /// Move the offset of a file descriptor.
1095 /// Note: This is similar to `lseek` in POSIX.
1096 ///
1097 /// ## Parameters
1098 ///
1099 /// * `offset` - The number of bytes to move.
1100 /// * `whence` - The base from which the offset is relative.
1101 ///
1102 /// ## Return
1103 ///
1104 /// * `newoffset` - The new offset of the file descriptor, relative to the start of the file.
fd_seek(fd: Fd, offset: Filedelta, whence: Whence) -> Result<Filesize>1105 pub unsafe fn fd_seek(fd: Fd, offset: Filedelta, whence: Whence) -> Result<Filesize> {
1106     let mut newoffset = MaybeUninit::uninit();
1107     let rc = wasi_snapshot_preview1::fd_seek(fd, offset, whence, newoffset.as_mut_ptr());
1108     if let Some(err) = Error::from_raw_error(rc) {
1109         Err(err)
1110     } else {
1111         Ok(newoffset.assume_init())
1112     }
1113 }
1114 
1115 /// Synchronize the data and metadata of a file to disk.
1116 /// Note: This is similar to `fsync` in POSIX.
fd_sync(fd: Fd) -> Result<()>1117 pub unsafe fn fd_sync(fd: Fd) -> Result<()> {
1118     let rc = wasi_snapshot_preview1::fd_sync(fd);
1119     if let Some(err) = Error::from_raw_error(rc) {
1120         Err(err)
1121     } else {
1122         Ok(())
1123     }
1124 }
1125 
1126 /// Return the current offset of a file descriptor.
1127 /// Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
1128 ///
1129 /// ## Return
1130 ///
1131 /// * `offset` - The current offset of the file descriptor, relative to the start of the file.
fd_tell(fd: Fd) -> Result<Filesize>1132 pub unsafe fn fd_tell(fd: Fd) -> Result<Filesize> {
1133     let mut offset = MaybeUninit::uninit();
1134     let rc = wasi_snapshot_preview1::fd_tell(fd, offset.as_mut_ptr());
1135     if let Some(err) = Error::from_raw_error(rc) {
1136         Err(err)
1137     } else {
1138         Ok(offset.assume_init())
1139     }
1140 }
1141 
1142 /// Write to a file descriptor.
1143 /// Note: This is similar to `writev` in POSIX.
1144 ///
1145 /// ## Parameters
1146 ///
1147 /// * `iovs` - List of scatter/gather vectors from which to retrieve data.
1148 ///
1149 /// ## Return
1150 ///
1151 /// * `nwritten` - The number of bytes written.
fd_write(fd: Fd, iovs: CiovecArray) -> Result<Size>1152 pub unsafe fn fd_write(fd: Fd, iovs: CiovecArray) -> Result<Size> {
1153     let mut nwritten = MaybeUninit::uninit();
1154     let rc = wasi_snapshot_preview1::fd_write(fd, iovs.as_ptr(), iovs.len(), nwritten.as_mut_ptr());
1155     if let Some(err) = Error::from_raw_error(rc) {
1156         Err(err)
1157     } else {
1158         Ok(nwritten.assume_init())
1159     }
1160 }
1161 
1162 /// Create a directory.
1163 /// Note: This is similar to `mkdirat` in POSIX.
1164 ///
1165 /// ## Parameters
1166 ///
1167 /// * `path` - The path at which to create the directory.
path_create_directory(fd: Fd, path: &str) -> Result<()>1168 pub unsafe fn path_create_directory(fd: Fd, path: &str) -> Result<()> {
1169     let rc = wasi_snapshot_preview1::path_create_directory(fd, path.as_ptr(), path.len());
1170     if let Some(err) = Error::from_raw_error(rc) {
1171         Err(err)
1172     } else {
1173         Ok(())
1174     }
1175 }
1176 
1177 /// Return the attributes of a file or directory.
1178 /// Note: This is similar to `stat` in POSIX.
1179 ///
1180 /// ## Parameters
1181 ///
1182 /// * `flags` - Flags determining the method of how the path is resolved.
1183 /// * `path` - The path of the file or directory to inspect.
1184 ///
1185 /// ## Return
1186 ///
1187 /// * `buf` - The buffer where the file's attributes are stored.
path_filestat_get(fd: Fd, flags: Lookupflags, path: &str) -> Result<Filestat>1188 pub unsafe fn path_filestat_get(fd: Fd, flags: Lookupflags, path: &str) -> Result<Filestat> {
1189     let mut buf = MaybeUninit::uninit();
1190     let rc = wasi_snapshot_preview1::path_filestat_get(
1191         fd,
1192         flags,
1193         path.as_ptr(),
1194         path.len(),
1195         buf.as_mut_ptr(),
1196     );
1197     if let Some(err) = Error::from_raw_error(rc) {
1198         Err(err)
1199     } else {
1200         Ok(buf.assume_init())
1201     }
1202 }
1203 
1204 /// Adjust the timestamps of a file or directory.
1205 /// Note: This is similar to `utimensat` in POSIX.
1206 ///
1207 /// ## Parameters
1208 ///
1209 /// * `flags` - Flags determining the method of how the path is resolved.
1210 /// * `path` - The path of the file or directory to operate on.
1211 /// * `atim` - The desired values of the data access timestamp.
1212 /// * `mtim` - The desired values of the data modification timestamp.
1213 /// * `fst_flags` - A bitmask indicating which timestamps to adjust.
path_filestat_set_times( fd: Fd, flags: Lookupflags, path: &str, atim: Timestamp, mtim: Timestamp, fst_flags: Fstflags, ) -> Result<()>1214 pub unsafe fn path_filestat_set_times(
1215     fd: Fd,
1216     flags: Lookupflags,
1217     path: &str,
1218     atim: Timestamp,
1219     mtim: Timestamp,
1220     fst_flags: Fstflags,
1221 ) -> Result<()> {
1222     let rc = wasi_snapshot_preview1::path_filestat_set_times(
1223         fd,
1224         flags,
1225         path.as_ptr(),
1226         path.len(),
1227         atim,
1228         mtim,
1229         fst_flags,
1230     );
1231     if let Some(err) = Error::from_raw_error(rc) {
1232         Err(err)
1233     } else {
1234         Ok(())
1235     }
1236 }
1237 
1238 /// Create a hard link.
1239 /// Note: This is similar to `linkat` in POSIX.
1240 ///
1241 /// ## Parameters
1242 ///
1243 /// * `old_flags` - Flags determining the method of how the path is resolved.
1244 /// * `old_path` - The source path from which to link.
1245 /// * `new_fd` - The working directory at which the resolution of the new path starts.
1246 /// * `new_path` - The destination path at which to create the hard link.
path_link( old_fd: Fd, old_flags: Lookupflags, old_path: &str, new_fd: Fd, new_path: &str, ) -> Result<()>1247 pub unsafe fn path_link(
1248     old_fd: Fd,
1249     old_flags: Lookupflags,
1250     old_path: &str,
1251     new_fd: Fd,
1252     new_path: &str,
1253 ) -> Result<()> {
1254     let rc = wasi_snapshot_preview1::path_link(
1255         old_fd,
1256         old_flags,
1257         old_path.as_ptr(),
1258         old_path.len(),
1259         new_fd,
1260         new_path.as_ptr(),
1261         new_path.len(),
1262     );
1263     if let Some(err) = Error::from_raw_error(rc) {
1264         Err(err)
1265     } else {
1266         Ok(())
1267     }
1268 }
1269 
1270 /// Open a file or directory.
1271 /// The returned file descriptor is not guaranteed to be the lowest-numbered
1272 /// file descriptor not currently open; it is randomized to prevent
1273 /// applications from depending on making assumptions about indexes, since this
1274 /// is error-prone in multi-threaded contexts. The returned file descriptor is
1275 /// guaranteed to be less than 2**31.
1276 /// Note: This is similar to `openat` in POSIX.
1277 ///
1278 /// ## Parameters
1279 ///
1280 /// * `dirflags` - Flags determining the method of how the path is resolved.
1281 /// * `path` - The relative path of the file or directory to open, relative to the
1282 ///   `path_open::fd` directory.
1283 /// * `oflags` - The method by which to open the file.
1284 /// * `fs_rights_base` - The initial rights of the newly created file descriptor. The
1285 ///   implementation is allowed to return a file descriptor with fewer rights
1286 ///   than specified, if and only if those rights do not apply to the type of
1287 ///   file being opened.
1288 ///   The *base* rights are rights that will apply to operations using the file
1289 ///   descriptor itself, while the *inheriting* rights are rights that apply to
1290 ///   file descriptors derived from it.
1291 ///
1292 /// ## Return
1293 ///
1294 /// * `opened_fd` - The file descriptor of the file that has been opened.
path_open( fd: Fd, dirflags: Lookupflags, path: &str, oflags: Oflags, fs_rights_base: Rights, fs_rights_inherting: Rights, fdflags: Fdflags, ) -> Result<Fd>1295 pub unsafe fn path_open(
1296     fd: Fd,
1297     dirflags: Lookupflags,
1298     path: &str,
1299     oflags: Oflags,
1300     fs_rights_base: Rights,
1301     fs_rights_inherting: Rights,
1302     fdflags: Fdflags,
1303 ) -> Result<Fd> {
1304     let mut opened_fd = MaybeUninit::uninit();
1305     let rc = wasi_snapshot_preview1::path_open(
1306         fd,
1307         dirflags,
1308         path.as_ptr(),
1309         path.len(),
1310         oflags,
1311         fs_rights_base,
1312         fs_rights_inherting,
1313         fdflags,
1314         opened_fd.as_mut_ptr(),
1315     );
1316     if let Some(err) = Error::from_raw_error(rc) {
1317         Err(err)
1318     } else {
1319         Ok(opened_fd.assume_init())
1320     }
1321 }
1322 
1323 /// Read the contents of a symbolic link.
1324 /// Note: This is similar to `readlinkat` in POSIX.
1325 ///
1326 /// ## Parameters
1327 ///
1328 /// * `path` - The path of the symbolic link from which to read.
1329 /// * `buf` - The buffer to which to write the contents of the symbolic link.
1330 ///
1331 /// ## Return
1332 ///
1333 /// * `bufused` - The number of bytes placed in the buffer.
path_readlink(fd: Fd, path: &str, buf: *mut u8, buf_len: Size) -> Result<Size>1334 pub unsafe fn path_readlink(fd: Fd, path: &str, buf: *mut u8, buf_len: Size) -> Result<Size> {
1335     let mut bufused = MaybeUninit::uninit();
1336     let rc = wasi_snapshot_preview1::path_readlink(
1337         fd,
1338         path.as_ptr(),
1339         path.len(),
1340         buf,
1341         buf_len,
1342         bufused.as_mut_ptr(),
1343     );
1344     if let Some(err) = Error::from_raw_error(rc) {
1345         Err(err)
1346     } else {
1347         Ok(bufused.assume_init())
1348     }
1349 }
1350 
1351 /// Remove a directory.
1352 /// Return `errno::notempty` if the directory is not empty.
1353 /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
1354 ///
1355 /// ## Parameters
1356 ///
1357 /// * `path` - The path to a directory to remove.
path_remove_directory(fd: Fd, path: &str) -> Result<()>1358 pub unsafe fn path_remove_directory(fd: Fd, path: &str) -> Result<()> {
1359     let rc = wasi_snapshot_preview1::path_remove_directory(fd, path.as_ptr(), path.len());
1360     if let Some(err) = Error::from_raw_error(rc) {
1361         Err(err)
1362     } else {
1363         Ok(())
1364     }
1365 }
1366 
1367 /// Rename a file or directory.
1368 /// Note: This is similar to `renameat` in POSIX.
1369 ///
1370 /// ## Parameters
1371 ///
1372 /// * `old_path` - The source path of the file or directory to rename.
1373 /// * `new_fd` - The working directory at which the resolution of the new path starts.
1374 /// * `new_path` - The destination path to which to rename the file or directory.
path_rename(fd: Fd, old_path: &str, new_fd: Fd, new_path: &str) -> Result<()>1375 pub unsafe fn path_rename(fd: Fd, old_path: &str, new_fd: Fd, new_path: &str) -> Result<()> {
1376     let rc = wasi_snapshot_preview1::path_rename(
1377         fd,
1378         old_path.as_ptr(),
1379         old_path.len(),
1380         new_fd,
1381         new_path.as_ptr(),
1382         new_path.len(),
1383     );
1384     if let Some(err) = Error::from_raw_error(rc) {
1385         Err(err)
1386     } else {
1387         Ok(())
1388     }
1389 }
1390 
1391 /// Create a symbolic link.
1392 /// Note: This is similar to `symlinkat` in POSIX.
1393 ///
1394 /// ## Parameters
1395 ///
1396 /// * `old_path` - The contents of the symbolic link.
1397 /// * `new_path` - The destination path at which to create the symbolic link.
path_symlink(old_path: &str, fd: Fd, new_path: &str) -> Result<()>1398 pub unsafe fn path_symlink(old_path: &str, fd: Fd, new_path: &str) -> Result<()> {
1399     let rc = wasi_snapshot_preview1::path_symlink(
1400         old_path.as_ptr(),
1401         old_path.len(),
1402         fd,
1403         new_path.as_ptr(),
1404         new_path.len(),
1405     );
1406     if let Some(err) = Error::from_raw_error(rc) {
1407         Err(err)
1408     } else {
1409         Ok(())
1410     }
1411 }
1412 
1413 /// Unlink a file.
1414 /// Return `errno::isdir` if the path refers to a directory.
1415 /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
1416 ///
1417 /// ## Parameters
1418 ///
1419 /// * `path` - The path to a file to unlink.
path_unlink_file(fd: Fd, path: &str) -> Result<()>1420 pub unsafe fn path_unlink_file(fd: Fd, path: &str) -> Result<()> {
1421     let rc = wasi_snapshot_preview1::path_unlink_file(fd, path.as_ptr(), path.len());
1422     if let Some(err) = Error::from_raw_error(rc) {
1423         Err(err)
1424     } else {
1425         Ok(())
1426     }
1427 }
1428 
1429 /// Concurrently poll for the occurrence of a set of events.
1430 ///
1431 /// ## Parameters
1432 ///
1433 /// * `r#in` - The events to which to subscribe.
1434 /// * `out` - The events that have occurred.
1435 /// * `nsubscriptions` - Both the number of subscriptions and events.
1436 ///
1437 /// ## Return
1438 ///
1439 /// * `nevents` - The number of events stored.
poll_oneoff( r#in: *const Subscription, out: *mut Event, nsubscriptions: Size, ) -> Result<Size>1440 pub unsafe fn poll_oneoff(
1441     r#in: *const Subscription,
1442     out: *mut Event,
1443     nsubscriptions: Size,
1444 ) -> Result<Size> {
1445     let mut nevents = MaybeUninit::uninit();
1446     let rc = wasi_snapshot_preview1::poll_oneoff(r#in, out, nsubscriptions, nevents.as_mut_ptr());
1447     if let Some(err) = Error::from_raw_error(rc) {
1448         Err(err)
1449     } else {
1450         Ok(nevents.assume_init())
1451     }
1452 }
1453 
1454 /// Terminate the process normally. An exit code of 0 indicates successful
1455 /// termination of the program. The meanings of other values is dependent on
1456 /// the environment.
1457 ///
1458 /// ## Parameters
1459 ///
1460 /// * `rval` - The exit code returned by the process.
proc_exit(rval: Exitcode)1461 pub unsafe fn proc_exit(rval: Exitcode) {
1462     wasi_snapshot_preview1::proc_exit(rval);
1463 }
1464 
1465 /// Send a signal to the process of the calling thread.
1466 /// Note: This is similar to `raise` in POSIX.
1467 ///
1468 /// ## Parameters
1469 ///
1470 /// * `sig` - The signal condition to trigger.
proc_raise(sig: Signal) -> Result<()>1471 pub unsafe fn proc_raise(sig: Signal) -> Result<()> {
1472     let rc = wasi_snapshot_preview1::proc_raise(sig);
1473     if let Some(err) = Error::from_raw_error(rc) {
1474         Err(err)
1475     } else {
1476         Ok(())
1477     }
1478 }
1479 
1480 /// Temporarily yield execution of the calling thread.
1481 /// Note: This is similar to `sched_yield` in POSIX.
sched_yield() -> Result<()>1482 pub unsafe fn sched_yield() -> Result<()> {
1483     let rc = wasi_snapshot_preview1::sched_yield();
1484     if let Some(err) = Error::from_raw_error(rc) {
1485         Err(err)
1486     } else {
1487         Ok(())
1488     }
1489 }
1490 
1491 /// Write high-quality random data into a buffer.
1492 /// This function blocks when the implementation is unable to immediately
1493 /// provide sufficient high-quality random data.
1494 /// This function may execute slowly, so when large mounts of random data are
1495 /// required, it's advisable to use this function to seed a pseudo-random
1496 /// number generator, rather than to provide the random data directly.
1497 ///
1498 /// ## Parameters
1499 ///
1500 /// * `buf` - The buffer to fill with random data.
random_get(buf: *mut u8, buf_len: Size) -> Result<()>1501 pub unsafe fn random_get(buf: *mut u8, buf_len: Size) -> Result<()> {
1502     let rc = wasi_snapshot_preview1::random_get(buf, buf_len);
1503     if let Some(err) = Error::from_raw_error(rc) {
1504         Err(err)
1505     } else {
1506         Ok(())
1507     }
1508 }
1509 
1510 /// Receive a message from a socket.
1511 /// Note: This is similar to `recv` in POSIX, though it also supports reading
1512 /// the data into multiple buffers in the manner of `readv`.
1513 ///
1514 /// ## Parameters
1515 ///
1516 /// * `ri_data` - List of scatter/gather vectors to which to store data.
1517 /// * `ri_flags` - Message flags.
1518 ///
1519 /// ## Return
1520 ///
1521 /// * `ro_datalen` - Number of bytes stored in ri_data.
1522 /// * `ro_flags` - Message flags.
sock_recv(fd: Fd, ri_data: IovecArray, ri_flags: Riflags) -> Result<(Size, Roflags)>1523 pub unsafe fn sock_recv(fd: Fd, ri_data: IovecArray, ri_flags: Riflags) -> Result<(Size, Roflags)> {
1524     let mut ro_datalen = MaybeUninit::uninit();
1525     let mut ro_flags = MaybeUninit::uninit();
1526     let rc = wasi_snapshot_preview1::sock_recv(
1527         fd,
1528         ri_data.as_ptr(),
1529         ri_data.len(),
1530         ri_flags,
1531         ro_datalen.as_mut_ptr(),
1532         ro_flags.as_mut_ptr(),
1533     );
1534     if let Some(err) = Error::from_raw_error(rc) {
1535         Err(err)
1536     } else {
1537         Ok((ro_datalen.assume_init(), ro_flags.assume_init()))
1538     }
1539 }
1540 
1541 /// Send a message on a socket.
1542 /// Note: This is similar to `send` in POSIX, though it also supports writing
1543 /// the data from multiple buffers in the manner of `writev`.
1544 ///
1545 /// ## Parameters
1546 ///
1547 /// * `si_data` - List of scatter/gather vectors to which to retrieve data
1548 /// * `si_flags` - Message flags.
1549 ///
1550 /// ## Return
1551 ///
1552 /// * `so_datalen` - Number of bytes transmitted.
sock_send(fd: Fd, si_data: CiovecArray, si_flags: Siflags) -> Result<Size>1553 pub unsafe fn sock_send(fd: Fd, si_data: CiovecArray, si_flags: Siflags) -> Result<Size> {
1554     let mut so_datalen = MaybeUninit::uninit();
1555     let rc = wasi_snapshot_preview1::sock_send(
1556         fd,
1557         si_data.as_ptr(),
1558         si_data.len(),
1559         si_flags,
1560         so_datalen.as_mut_ptr(),
1561     );
1562     if let Some(err) = Error::from_raw_error(rc) {
1563         Err(err)
1564     } else {
1565         Ok(so_datalen.assume_init())
1566     }
1567 }
1568 
1569 /// Shut down socket send and receive channels.
1570 /// Note: This is similar to `shutdown` in POSIX.
1571 ///
1572 /// ## Parameters
1573 ///
1574 /// * `how` - Which channels on the socket to shut down.
sock_shutdown(fd: Fd, how: Sdflags) -> Result<()>1575 pub unsafe fn sock_shutdown(fd: Fd, how: Sdflags) -> Result<()> {
1576     let rc = wasi_snapshot_preview1::sock_shutdown(fd, how);
1577     if let Some(err) = Error::from_raw_error(rc) {
1578         Err(err)
1579     } else {
1580         Ok(())
1581     }
1582 }
1583 
1584 pub mod wasi_snapshot_preview1 {
1585     use super::*;
1586     #[link(wasm_import_module = "wasi_snapshot_preview1")]
1587     extern "C" {
1588         /// Read command-line argument data.
1589         /// The size of the array should match that returned by `args_sizes_get`
args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Errno1590         pub fn args_get(argv: *mut *mut u8, argv_buf: *mut u8) -> Errno;
1591         /// Return command-line argument data sizes.
args_sizes_get(argc: *mut Size, argv_buf_size: *mut Size) -> Errno1592         pub fn args_sizes_get(argc: *mut Size, argv_buf_size: *mut Size) -> Errno;
1593         /// Read environment variable data.
1594         /// The sizes of the buffers should match that returned by `environ_sizes_get`.
environ_get(environ: *mut *mut u8, environ_buf: *mut u8) -> Errno1595         pub fn environ_get(environ: *mut *mut u8, environ_buf: *mut u8) -> Errno;
1596         /// Return environment variable data sizes.
environ_sizes_get(environc: *mut Size, environ_buf_size: *mut Size) -> Errno1597         pub fn environ_sizes_get(environc: *mut Size, environ_buf_size: *mut Size) -> Errno;
1598         /// Return the resolution of a clock.
1599         /// Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
1600         /// return `errno::inval`.
1601         /// Note: This is similar to `clock_getres` in POSIX.
clock_res_get(id: Clockid, resolution: *mut Timestamp) -> Errno1602         pub fn clock_res_get(id: Clockid, resolution: *mut Timestamp) -> Errno;
1603         /// Return the time value of a clock.
1604         /// Note: This is similar to `clock_gettime` in POSIX.
clock_time_get(id: Clockid, precision: Timestamp, time: *mut Timestamp) -> Errno1605         pub fn clock_time_get(id: Clockid, precision: Timestamp, time: *mut Timestamp) -> Errno;
1606         /// Provide file advisory information on a file descriptor.
1607         /// Note: This is similar to `posix_fadvise` in POSIX.
fd_advise(fd: Fd, offset: Filesize, len: Filesize, advice: Advice) -> Errno1608         pub fn fd_advise(fd: Fd, offset: Filesize, len: Filesize, advice: Advice) -> Errno;
1609         /// Force the allocation of space in a file.
1610         /// Note: This is similar to `posix_fallocate` in POSIX.
fd_allocate(fd: Fd, offset: Filesize, len: Filesize) -> Errno1611         pub fn fd_allocate(fd: Fd, offset: Filesize, len: Filesize) -> Errno;
1612         /// Close a file descriptor.
1613         /// Note: This is similar to `close` in POSIX.
fd_close(fd: Fd) -> Errno1614         pub fn fd_close(fd: Fd) -> Errno;
1615         /// Synchronize the data of a file to disk.
1616         /// Note: This is similar to `fdatasync` in POSIX.
fd_datasync(fd: Fd) -> Errno1617         pub fn fd_datasync(fd: Fd) -> Errno;
1618         /// Get the attributes of a file descriptor.
1619         /// Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
fd_fdstat_get(fd: Fd, stat: *mut Fdstat) -> Errno1620         pub fn fd_fdstat_get(fd: Fd, stat: *mut Fdstat) -> Errno;
1621         /// Adjust the flags associated with a file descriptor.
1622         /// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
fd_fdstat_set_flags(fd: Fd, flags: Fdflags) -> Errno1623         pub fn fd_fdstat_set_flags(fd: Fd, flags: Fdflags) -> Errno;
1624         /// Adjust the rights associated with a file descriptor.
1625         /// This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
fd_fdstat_set_rights( fd: Fd, fs_rights_base: Rights, fs_rights_inheriting: Rights, ) -> Errno1626         pub fn fd_fdstat_set_rights(
1627             fd: Fd,
1628             fs_rights_base: Rights,
1629             fs_rights_inheriting: Rights,
1630         ) -> Errno;
1631         /// Return the attributes of an open file.
fd_filestat_get(fd: Fd, buf: *mut Filestat) -> Errno1632         pub fn fd_filestat_get(fd: Fd, buf: *mut Filestat) -> Errno;
1633         /// Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
1634         /// Note: This is similar to `ftruncate` in POSIX.
fd_filestat_set_size(fd: Fd, size: Filesize) -> Errno1635         pub fn fd_filestat_set_size(fd: Fd, size: Filesize) -> Errno;
1636         /// Adjust the timestamps of an open file or directory.
1637         /// Note: This is similar to `futimens` in POSIX.
fd_filestat_set_times( fd: Fd, atim: Timestamp, mtim: Timestamp, fst_flags: Fstflags, ) -> Errno1638         pub fn fd_filestat_set_times(
1639             fd: Fd,
1640             atim: Timestamp,
1641             mtim: Timestamp,
1642             fst_flags: Fstflags,
1643         ) -> Errno;
1644         /// Read from a file descriptor, without using and updating the file descriptor's offset.
1645         /// Note: This is similar to `preadv` in POSIX.
fd_pread( fd: Fd, iovs_ptr: *const Iovec, iovs_len: usize, offset: Filesize, nread: *mut Size, ) -> Errno1646         pub fn fd_pread(
1647             fd: Fd,
1648             iovs_ptr: *const Iovec,
1649             iovs_len: usize,
1650             offset: Filesize,
1651             nread: *mut Size,
1652         ) -> Errno;
1653         /// Return a description of the given preopened file descriptor.
fd_prestat_get(fd: Fd, buf: *mut Prestat) -> Errno1654         pub fn fd_prestat_get(fd: Fd, buf: *mut Prestat) -> Errno;
1655         /// Return a description of the given preopened file descriptor.
fd_prestat_dir_name(fd: Fd, path: *mut u8, path_len: Size) -> Errno1656         pub fn fd_prestat_dir_name(fd: Fd, path: *mut u8, path_len: Size) -> Errno;
1657         /// Write to a file descriptor, without using and updating the file descriptor's offset.
1658         /// Note: This is similar to `pwritev` in POSIX.
fd_pwrite( fd: Fd, iovs_ptr: *const Ciovec, iovs_len: usize, offset: Filesize, nwritten: *mut Size, ) -> Errno1659         pub fn fd_pwrite(
1660             fd: Fd,
1661             iovs_ptr: *const Ciovec,
1662             iovs_len: usize,
1663             offset: Filesize,
1664             nwritten: *mut Size,
1665         ) -> Errno;
1666         /// Read from a file descriptor.
1667         /// Note: This is similar to `readv` in POSIX.
fd_read(fd: Fd, iovs_ptr: *const Iovec, iovs_len: usize, nread: *mut Size) -> Errno1668         pub fn fd_read(fd: Fd, iovs_ptr: *const Iovec, iovs_len: usize, nread: *mut Size) -> Errno;
1669         /// Read directory entries from a directory.
1670         /// When successful, the contents of the output buffer consist of a sequence of
1671         /// directory entries. Each directory entry consists of a dirent_t object,
1672         /// followed by dirent_t::d_namlen bytes holding the name of the directory
1673         /// entry.
1674         /// This function fills the output buffer as much as possible, potentially
1675         /// truncating the last directory entry. This allows the caller to grow its
1676         /// read buffer size in case it's too small to fit a single large directory
1677         /// entry, or skip the oversized directory entry.
fd_readdir( fd: Fd, buf: *mut u8, buf_len: Size, cookie: Dircookie, bufused: *mut Size, ) -> Errno1678         pub fn fd_readdir(
1679             fd: Fd,
1680             buf: *mut u8,
1681             buf_len: Size,
1682             cookie: Dircookie,
1683             bufused: *mut Size,
1684         ) -> Errno;
1685         /// Atomically replace a file descriptor by renumbering another file descriptor.
1686         /// Due to the strong focus on thread safety, this environment does not provide
1687         /// a mechanism to duplicate or renumber a file descriptor to an arbitrary
1688         /// number, like `dup2()`. This would be prone to race conditions, as an actual
1689         /// file descriptor with the same number could be allocated by a different
1690         /// thread at the same time.
1691         /// This function provides a way to atomically renumber file descriptors, which
1692         /// would disappear if `dup2()` were to be removed entirely.
fd_renumber(fd: Fd, to: Fd) -> Errno1693         pub fn fd_renumber(fd: Fd, to: Fd) -> Errno;
1694         /// Move the offset of a file descriptor.
1695         /// Note: This is similar to `lseek` in POSIX.
fd_seek( fd: Fd, offset: Filedelta, whence: Whence, newoffset: *mut Filesize, ) -> Errno1696         pub fn fd_seek(
1697             fd: Fd,
1698             offset: Filedelta,
1699             whence: Whence,
1700             newoffset: *mut Filesize,
1701         ) -> Errno;
1702         /// Synchronize the data and metadata of a file to disk.
1703         /// Note: This is similar to `fsync` in POSIX.
fd_sync(fd: Fd) -> Errno1704         pub fn fd_sync(fd: Fd) -> Errno;
1705         /// Return the current offset of a file descriptor.
1706         /// Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
fd_tell(fd: Fd, offset: *mut Filesize) -> Errno1707         pub fn fd_tell(fd: Fd, offset: *mut Filesize) -> Errno;
1708         /// Write to a file descriptor.
1709         /// Note: This is similar to `writev` in POSIX.
fd_write( fd: Fd, iovs_ptr: *const Ciovec, iovs_len: usize, nwritten: *mut Size, ) -> Errno1710         pub fn fd_write(
1711             fd: Fd,
1712             iovs_ptr: *const Ciovec,
1713             iovs_len: usize,
1714             nwritten: *mut Size,
1715         ) -> Errno;
1716         /// Create a directory.
1717         /// Note: This is similar to `mkdirat` in POSIX.
path_create_directory(fd: Fd, path_ptr: *const u8, path_len: usize) -> Errno1718         pub fn path_create_directory(fd: Fd, path_ptr: *const u8, path_len: usize) -> Errno;
1719         /// Return the attributes of a file or directory.
1720         /// Note: This is similar to `stat` in POSIX.
path_filestat_get( fd: Fd, flags: Lookupflags, path_ptr: *const u8, path_len: usize, buf: *mut Filestat, ) -> Errno1721         pub fn path_filestat_get(
1722             fd: Fd,
1723             flags: Lookupflags,
1724             path_ptr: *const u8,
1725             path_len: usize,
1726             buf: *mut Filestat,
1727         ) -> Errno;
1728         /// Adjust the timestamps of a file or directory.
1729         /// Note: This is similar to `utimensat` in POSIX.
path_filestat_set_times( fd: Fd, flags: Lookupflags, path_ptr: *const u8, path_len: usize, atim: Timestamp, mtim: Timestamp, fst_flags: Fstflags, ) -> Errno1730         pub fn path_filestat_set_times(
1731             fd: Fd,
1732             flags: Lookupflags,
1733             path_ptr: *const u8,
1734             path_len: usize,
1735             atim: Timestamp,
1736             mtim: Timestamp,
1737             fst_flags: Fstflags,
1738         ) -> Errno;
1739         /// Create a hard link.
1740         /// Note: This is similar to `linkat` in POSIX.
path_link( old_fd: Fd, old_flags: Lookupflags, old_path_ptr: *const u8, old_path_len: usize, new_fd: Fd, new_path_ptr: *const u8, new_path_len: usize, ) -> Errno1741         pub fn path_link(
1742             old_fd: Fd,
1743             old_flags: Lookupflags,
1744             old_path_ptr: *const u8,
1745             old_path_len: usize,
1746             new_fd: Fd,
1747             new_path_ptr: *const u8,
1748             new_path_len: usize,
1749         ) -> Errno;
1750         /// Open a file or directory.
1751         /// The returned file descriptor is not guaranteed to be the lowest-numbered
1752         /// file descriptor not currently open; it is randomized to prevent
1753         /// applications from depending on making assumptions about indexes, since this
1754         /// is error-prone in multi-threaded contexts. The returned file descriptor is
1755         /// guaranteed to be less than 2**31.
1756         /// Note: This is similar to `openat` in POSIX.
path_open( fd: Fd, dirflags: Lookupflags, path_ptr: *const u8, path_len: usize, oflags: Oflags, fs_rights_base: Rights, fs_rights_inherting: Rights, fdflags: Fdflags, opened_fd: *mut Fd, ) -> Errno1757         pub fn path_open(
1758             fd: Fd,
1759             dirflags: Lookupflags,
1760             path_ptr: *const u8,
1761             path_len: usize,
1762             oflags: Oflags,
1763             fs_rights_base: Rights,
1764             fs_rights_inherting: Rights,
1765             fdflags: Fdflags,
1766             opened_fd: *mut Fd,
1767         ) -> Errno;
1768         /// Read the contents of a symbolic link.
1769         /// Note: This is similar to `readlinkat` in POSIX.
path_readlink( fd: Fd, path_ptr: *const u8, path_len: usize, buf: *mut u8, buf_len: Size, bufused: *mut Size, ) -> Errno1770         pub fn path_readlink(
1771             fd: Fd,
1772             path_ptr: *const u8,
1773             path_len: usize,
1774             buf: *mut u8,
1775             buf_len: Size,
1776             bufused: *mut Size,
1777         ) -> Errno;
1778         /// Remove a directory.
1779         /// Return `errno::notempty` if the directory is not empty.
1780         /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
path_remove_directory(fd: Fd, path_ptr: *const u8, path_len: usize) -> Errno1781         pub fn path_remove_directory(fd: Fd, path_ptr: *const u8, path_len: usize) -> Errno;
1782         /// Rename a file or directory.
1783         /// Note: This is similar to `renameat` in POSIX.
path_rename( fd: Fd, old_path_ptr: *const u8, old_path_len: usize, new_fd: Fd, new_path_ptr: *const u8, new_path_len: usize, ) -> Errno1784         pub fn path_rename(
1785             fd: Fd,
1786             old_path_ptr: *const u8,
1787             old_path_len: usize,
1788             new_fd: Fd,
1789             new_path_ptr: *const u8,
1790             new_path_len: usize,
1791         ) -> Errno;
1792         /// Create a symbolic link.
1793         /// Note: This is similar to `symlinkat` in POSIX.
path_symlink( old_path_ptr: *const u8, old_path_len: usize, fd: Fd, new_path_ptr: *const u8, new_path_len: usize, ) -> Errno1794         pub fn path_symlink(
1795             old_path_ptr: *const u8,
1796             old_path_len: usize,
1797             fd: Fd,
1798             new_path_ptr: *const u8,
1799             new_path_len: usize,
1800         ) -> Errno;
1801         /// Unlink a file.
1802         /// Return `errno::isdir` if the path refers to a directory.
1803         /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
path_unlink_file(fd: Fd, path_ptr: *const u8, path_len: usize) -> Errno1804         pub fn path_unlink_file(fd: Fd, path_ptr: *const u8, path_len: usize) -> Errno;
1805         /// Concurrently poll for the occurrence of a set of events.
poll_oneoff( r#in: *const Subscription, out: *mut Event, nsubscriptions: Size, nevents: *mut Size, ) -> Errno1806         pub fn poll_oneoff(
1807             r#in: *const Subscription,
1808             out: *mut Event,
1809             nsubscriptions: Size,
1810             nevents: *mut Size,
1811         ) -> Errno;
1812         /// Terminate the process normally. An exit code of 0 indicates successful
1813         /// termination of the program. The meanings of other values is dependent on
1814         /// the environment.
proc_exit(rval: Exitcode) -> !1815         pub fn proc_exit(rval: Exitcode) -> !;
1816         /// Send a signal to the process of the calling thread.
1817         /// Note: This is similar to `raise` in POSIX.
proc_raise(sig: Signal) -> Errno1818         pub fn proc_raise(sig: Signal) -> Errno;
1819         /// Temporarily yield execution of the calling thread.
1820         /// Note: This is similar to `sched_yield` in POSIX.
sched_yield() -> Errno1821         pub fn sched_yield() -> Errno;
1822         /// Write high-quality random data into a buffer.
1823         /// This function blocks when the implementation is unable to immediately
1824         /// provide sufficient high-quality random data.
1825         /// This function may execute slowly, so when large mounts of random data are
1826         /// required, it's advisable to use this function to seed a pseudo-random
1827         /// number generator, rather than to provide the random data directly.
random_get(buf: *mut u8, buf_len: Size) -> Errno1828         pub fn random_get(buf: *mut u8, buf_len: Size) -> Errno;
1829         /// Receive a message from a socket.
1830         /// Note: This is similar to `recv` in POSIX, though it also supports reading
1831         /// the data into multiple buffers in the manner of `readv`.
sock_recv( fd: Fd, ri_data_ptr: *const Iovec, ri_data_len: usize, ri_flags: Riflags, ro_datalen: *mut Size, ro_flags: *mut Roflags, ) -> Errno1832         pub fn sock_recv(
1833             fd: Fd,
1834             ri_data_ptr: *const Iovec,
1835             ri_data_len: usize,
1836             ri_flags: Riflags,
1837             ro_datalen: *mut Size,
1838             ro_flags: *mut Roflags,
1839         ) -> Errno;
1840         /// Send a message on a socket.
1841         /// Note: This is similar to `send` in POSIX, though it also supports writing
1842         /// the data from multiple buffers in the manner of `writev`.
sock_send( fd: Fd, si_data_ptr: *const Ciovec, si_data_len: usize, si_flags: Siflags, so_datalen: *mut Size, ) -> Errno1843         pub fn sock_send(
1844             fd: Fd,
1845             si_data_ptr: *const Ciovec,
1846             si_data_len: usize,
1847             si_flags: Siflags,
1848             so_datalen: *mut Size,
1849         ) -> Errno;
1850         /// Shut down socket send and receive channels.
1851         /// Note: This is similar to `shutdown` in POSIX.
sock_shutdown(fd: Fd, how: Sdflags) -> Errno1852         pub fn sock_shutdown(fd: Fd, how: Sdflags) -> Errno;
1853     }
1854 }
1855