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