]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/headers/public/wasi/api.h
Correct minor typo in c_headers.rs (#166)
[wasi-libc.git] / libc-bottom-half / headers / public / wasi / api.h
1 /**
2 * THIS FILE IS AUTO-GENERATED from the following files:
3 * typenames.witx, wasi_snapshot_preview1.witx
4 *
5 * @file
6 * This file describes the [WASI] interface, consisting of functions, types,
7 * and defined values (macros).
8 *
9 * The interface described here is greatly inspired by [CloudABI]'s clean,
10 * thoughtfully-designed, capability-oriented, POSIX-style API.
11 *
12 * [CloudABI]: https://github.com/NuxiNL/cloudlibc
13 * [WASI]: https://github.com/WebAssembly/WASI/
14 */
15
16 #ifndef __wasi_api_h
17 #define __wasi_api_h
18
19 #ifndef __wasi__
20 #error <wasi/api.h> is only supported on WASI platforms.
21 #endif
22
23 #include <stddef.h>
24 #include <stdint.h>
25
26 _Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
27 _Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
28 _Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
29 _Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
30 _Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout");
31 _Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout");
32 _Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout");
33 _Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout");
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 // TODO: Encoding this in witx.
40 #define __WASI_DIRCOOKIE_START (UINT64_C(0))
41 typedef __SIZE_TYPE__ __wasi_size_t;
42
43 /**
44 * Non-negative file size or length of a region within a file.
45 */
46 typedef uint64_t __wasi_filesize_t;
47
48 /**
49 * Timestamp in nanoseconds.
50 */
51 typedef uint64_t __wasi_timestamp_t;
52
53 /**
54 * Identifiers for clocks.
55 */
56 typedef uint32_t __wasi_clockid_t;
57
58 /**
59 * The clock measuring real time. Time value zero corresponds with
60 * 1970-01-01T00:00:00Z.
61 */
62 #define __WASI_CLOCKID_REALTIME (UINT32_C(0))
63
64 /**
65 * The store-wide monotonic clock, which is defined as a clock measuring
66 * real time, whose value cannot be adjusted and which cannot have negative
67 * clock jumps. The epoch of this clock is undefined. The absolute time
68 * value of this clock therefore has no meaning.
69 */
70 #define __WASI_CLOCKID_MONOTONIC (UINT32_C(1))
71
72 /**
73 * The CPU-time clock associated with the current process.
74 */
75 #define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2))
76
77 /**
78 * The CPU-time clock associated with the current thread.
79 */
80 #define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3))
81
82 /**
83 * Error codes returned by functions.
84 * Not all of these error codes are returned by the functions provided by this
85 * API; some are used in higher-level library layers, and others are provided
86 * merely for alignment with POSIX.
87 */
88 typedef uint16_t __wasi_errno_t;
89
90 /**
91 * No error occurred. System call completed successfully.
92 */
93 #define __WASI_ERRNO_SUCCESS (UINT16_C(0))
94
95 /**
96 * Argument list too long.
97 */
98 #define __WASI_ERRNO_2BIG (UINT16_C(1))
99
100 /**
101 * Permission denied.
102 */
103 #define __WASI_ERRNO_ACCES (UINT16_C(2))
104
105 /**
106 * Address in use.
107 */
108 #define __WASI_ERRNO_ADDRINUSE (UINT16_C(3))
109
110 /**
111 * Address not available.
112 */
113 #define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4))
114
115 /**
116 * Address family not supported.
117 */
118 #define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5))
119
120 /**
121 * Resource unavailable, or operation would block.
122 */
123 #define __WASI_ERRNO_AGAIN (UINT16_C(6))
124
125 /**
126 * Connection already in progress.
127 */
128 #define __WASI_ERRNO_ALREADY (UINT16_C(7))
129
130 /**
131 * Bad file descriptor.
132 */
133 #define __WASI_ERRNO_BADF (UINT16_C(8))
134
135 /**
136 * Bad message.
137 */
138 #define __WASI_ERRNO_BADMSG (UINT16_C(9))
139
140 /**
141 * Device or resource busy.
142 */
143 #define __WASI_ERRNO_BUSY (UINT16_C(10))
144
145 /**
146 * Operation canceled.
147 */
148 #define __WASI_ERRNO_CANCELED (UINT16_C(11))
149
150 /**
151 * No child processes.
152 */
153 #define __WASI_ERRNO_CHILD (UINT16_C(12))
154
155 /**
156 * Connection aborted.
157 */
158 #define __WASI_ERRNO_CONNABORTED (UINT16_C(13))
159
160 /**
161 * Connection refused.
162 */
163 #define __WASI_ERRNO_CONNREFUSED (UINT16_C(14))
164
165 /**
166 * Connection reset.
167 */
168 #define __WASI_ERRNO_CONNRESET (UINT16_C(15))
169
170 /**
171 * Resource deadlock would occur.
172 */
173 #define __WASI_ERRNO_DEADLK (UINT16_C(16))
174
175 /**
176 * Destination address required.
177 */
178 #define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17))
179
180 /**
181 * Mathematics argument out of domain of function.
182 */
183 #define __WASI_ERRNO_DOM (UINT16_C(18))
184
185 /**
186 * Reserved.
187 */
188 #define __WASI_ERRNO_DQUOT (UINT16_C(19))
189
190 /**
191 * File exists.
192 */
193 #define __WASI_ERRNO_EXIST (UINT16_C(20))
194
195 /**
196 * Bad address.
197 */
198 #define __WASI_ERRNO_FAULT (UINT16_C(21))
199
200 /**
201 * File too large.
202 */
203 #define __WASI_ERRNO_FBIG (UINT16_C(22))
204
205 /**
206 * Host is unreachable.
207 */
208 #define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23))
209
210 /**
211 * Identifier removed.
212 */
213 #define __WASI_ERRNO_IDRM (UINT16_C(24))
214
215 /**
216 * Illegal byte sequence.
217 */
218 #define __WASI_ERRNO_ILSEQ (UINT16_C(25))
219
220 /**
221 * Operation in progress.
222 */
223 #define __WASI_ERRNO_INPROGRESS (UINT16_C(26))
224
225 /**
226 * Interrupted function.
227 */
228 #define __WASI_ERRNO_INTR (UINT16_C(27))
229
230 /**
231 * Invalid argument.
232 */
233 #define __WASI_ERRNO_INVAL (UINT16_C(28))
234
235 /**
236 * I/O error.
237 */
238 #define __WASI_ERRNO_IO (UINT16_C(29))
239
240 /**
241 * Socket is connected.
242 */
243 #define __WASI_ERRNO_ISCONN (UINT16_C(30))
244
245 /**
246 * Is a directory.
247 */
248 #define __WASI_ERRNO_ISDIR (UINT16_C(31))
249
250 /**
251 * Too many levels of symbolic links.
252 */
253 #define __WASI_ERRNO_LOOP (UINT16_C(32))
254
255 /**
256 * File descriptor value too large.
257 */
258 #define __WASI_ERRNO_MFILE (UINT16_C(33))
259
260 /**
261 * Too many links.
262 */
263 #define __WASI_ERRNO_MLINK (UINT16_C(34))
264
265 /**
266 * Message too large.
267 */
268 #define __WASI_ERRNO_MSGSIZE (UINT16_C(35))
269
270 /**
271 * Reserved.
272 */
273 #define __WASI_ERRNO_MULTIHOP (UINT16_C(36))
274
275 /**
276 * Filename too long.
277 */
278 #define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37))
279
280 /**
281 * Network is down.
282 */
283 #define __WASI_ERRNO_NETDOWN (UINT16_C(38))
284
285 /**
286 * Connection aborted by network.
287 */
288 #define __WASI_ERRNO_NETRESET (UINT16_C(39))
289
290 /**
291 * Network unreachable.
292 */
293 #define __WASI_ERRNO_NETUNREACH (UINT16_C(40))
294
295 /**
296 * Too many files open in system.
297 */
298 #define __WASI_ERRNO_NFILE (UINT16_C(41))
299
300 /**
301 * No buffer space available.
302 */
303 #define __WASI_ERRNO_NOBUFS (UINT16_C(42))
304
305 /**
306 * No such device.
307 */
308 #define __WASI_ERRNO_NODEV (UINT16_C(43))
309
310 /**
311 * No such file or directory.
312 */
313 #define __WASI_ERRNO_NOENT (UINT16_C(44))
314
315 /**
316 * Executable file format error.
317 */
318 #define __WASI_ERRNO_NOEXEC (UINT16_C(45))
319
320 /**
321 * No locks available.
322 */
323 #define __WASI_ERRNO_NOLCK (UINT16_C(46))
324
325 /**
326 * Reserved.
327 */
328 #define __WASI_ERRNO_NOLINK (UINT16_C(47))
329
330 /**
331 * Not enough space.
332 */
333 #define __WASI_ERRNO_NOMEM (UINT16_C(48))
334
335 /**
336 * No message of the desired type.
337 */
338 #define __WASI_ERRNO_NOMSG (UINT16_C(49))
339
340 /**
341 * Protocol not available.
342 */
343 #define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50))
344
345 /**
346 * No space left on device.
347 */
348 #define __WASI_ERRNO_NOSPC (UINT16_C(51))
349
350 /**
351 * Function not supported.
352 */
353 #define __WASI_ERRNO_NOSYS (UINT16_C(52))
354
355 /**
356 * The socket is not connected.
357 */
358 #define __WASI_ERRNO_NOTCONN (UINT16_C(53))
359
360 /**
361 * Not a directory or a symbolic link to a directory.
362 */
363 #define __WASI_ERRNO_NOTDIR (UINT16_C(54))
364
365 /**
366 * Directory not empty.
367 */
368 #define __WASI_ERRNO_NOTEMPTY (UINT16_C(55))
369
370 /**
371 * State not recoverable.
372 */
373 #define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56))
374
375 /**
376 * Not a socket.
377 */
378 #define __WASI_ERRNO_NOTSOCK (UINT16_C(57))
379
380 /**
381 * Not supported, or operation not supported on socket.
382 */
383 #define __WASI_ERRNO_NOTSUP (UINT16_C(58))
384
385 /**
386 * Inappropriate I/O control operation.
387 */
388 #define __WASI_ERRNO_NOTTY (UINT16_C(59))
389
390 /**
391 * No such device or address.
392 */
393 #define __WASI_ERRNO_NXIO (UINT16_C(60))
394
395 /**
396 * Value too large to be stored in data type.
397 */
398 #define __WASI_ERRNO_OVERFLOW (UINT16_C(61))
399
400 /**
401 * Previous owner died.
402 */
403 #define __WASI_ERRNO_OWNERDEAD (UINT16_C(62))
404
405 /**
406 * Operation not permitted.
407 */
408 #define __WASI_ERRNO_PERM (UINT16_C(63))
409
410 /**
411 * Broken pipe.
412 */
413 #define __WASI_ERRNO_PIPE (UINT16_C(64))
414
415 /**
416 * Protocol error.
417 */
418 #define __WASI_ERRNO_PROTO (UINT16_C(65))
419
420 /**
421 * Protocol not supported.
422 */
423 #define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66))
424
425 /**
426 * Protocol wrong type for socket.
427 */
428 #define __WASI_ERRNO_PROTOTYPE (UINT16_C(67))
429
430 /**
431 * Result too large.
432 */
433 #define __WASI_ERRNO_RANGE (UINT16_C(68))
434
435 /**
436 * Read-only file system.
437 */
438 #define __WASI_ERRNO_ROFS (UINT16_C(69))
439
440 /**
441 * Invalid seek.
442 */
443 #define __WASI_ERRNO_SPIPE (UINT16_C(70))
444
445 /**
446 * No such process.
447 */
448 #define __WASI_ERRNO_SRCH (UINT16_C(71))
449
450 /**
451 * Reserved.
452 */
453 #define __WASI_ERRNO_STALE (UINT16_C(72))
454
455 /**
456 * Connection timed out.
457 */
458 #define __WASI_ERRNO_TIMEDOUT (UINT16_C(73))
459
460 /**
461 * Text file busy.
462 */
463 #define __WASI_ERRNO_TXTBSY (UINT16_C(74))
464
465 /**
466 * Cross-device link.
467 */
468 #define __WASI_ERRNO_XDEV (UINT16_C(75))
469
470 /**
471 * Extension: Capabilities insufficient.
472 */
473 #define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76))
474
475 /**
476 * File descriptor rights, determining which actions may be performed.
477 */
478 typedef uint64_t __wasi_rights_t;
479
480 /**
481 * The right to invoke `fd_datasync`.
482 * If `path_open` is set, includes the right to invoke
483 * `path_open` with `fdflag::dsync`.
484 */
485 #define __WASI_RIGHTS_FD_DATASYNC (UINT64_C(1))
486
487 /**
488 * The right to invoke `fd_read` and `sock_recv`.
489 * If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
490 */
491 #define __WASI_RIGHTS_FD_READ (UINT64_C(2))
492
493 /**
494 * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
495 */
496 #define __WASI_RIGHTS_FD_SEEK (UINT64_C(4))
497
498 /**
499 * The right to invoke `fd_fdstat_set_flags`.
500 */
501 #define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS (UINT64_C(8))
502
503 /**
504 * The right to invoke `fd_sync`.
505 * If `path_open` is set, includes the right to invoke
506 * `path_open` with `fdflag::rsync` and `fdflag::dsync`.
507 */
508 #define __WASI_RIGHTS_FD_SYNC (UINT64_C(16))
509
510 /**
511 * The right to invoke `fd_seek` in such a way that the file offset
512 * remains unaltered (i.e., `WHENCE_CUR` with offset zero), or to
513 * invoke `fd_tell`.
514 */
515 #define __WASI_RIGHTS_FD_TELL (UINT64_C(32))
516
517 /**
518 * The right to invoke `fd_write` and `sock_send`.
519 * If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
520 */
521 #define __WASI_RIGHTS_FD_WRITE (UINT64_C(64))
522
523 /**
524 * The right to invoke `fd_advise`.
525 */
526 #define __WASI_RIGHTS_FD_ADVISE (UINT64_C(128))
527
528 /**
529 * The right to invoke `fd_allocate`.
530 */
531 #define __WASI_RIGHTS_FD_ALLOCATE (UINT64_C(256))
532
533 /**
534 * The right to invoke `path_create_directory`.
535 */
536 #define __WASI_RIGHTS_PATH_CREATE_DIRECTORY (UINT64_C(512))
537
538 /**
539 * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
540 */
541 #define __WASI_RIGHTS_PATH_CREATE_FILE (UINT64_C(1024))
542
543 /**
544 * The right to invoke `path_link` with the file descriptor as the
545 * source directory.
546 */
547 #define __WASI_RIGHTS_PATH_LINK_SOURCE (UINT64_C(2048))
548
549 /**
550 * The right to invoke `path_link` with the file descriptor as the
551 * target directory.
552 */
553 #define __WASI_RIGHTS_PATH_LINK_TARGET (UINT64_C(4096))
554
555 /**
556 * The right to invoke `path_open`.
557 */
558 #define __WASI_RIGHTS_PATH_OPEN (UINT64_C(8192))
559
560 /**
561 * The right to invoke `fd_readdir`.
562 */
563 #define __WASI_RIGHTS_FD_READDIR (UINT64_C(16384))
564
565 /**
566 * The right to invoke `path_readlink`.
567 */
568 #define __WASI_RIGHTS_PATH_READLINK (UINT64_C(32768))
569
570 /**
571 * The right to invoke `path_rename` with the file descriptor as the source directory.
572 */
573 #define __WASI_RIGHTS_PATH_RENAME_SOURCE (UINT64_C(65536))
574
575 /**
576 * The right to invoke `path_rename` with the file descriptor as the target directory.
577 */
578 #define __WASI_RIGHTS_PATH_RENAME_TARGET (UINT64_C(131072))
579
580 /**
581 * The right to invoke `path_filestat_get`.
582 */
583 #define __WASI_RIGHTS_PATH_FILESTAT_GET (UINT64_C(262144))
584
585 /**
586 * The right to change a file's size (there is no `path_filestat_set_size`).
587 * If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`.
588 */
589 #define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE (UINT64_C(524288))
590
591 /**
592 * The right to invoke `path_filestat_set_times`.
593 */
594 #define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES (UINT64_C(1048576))
595
596 /**
597 * The right to invoke `fd_filestat_get`.
598 */
599 #define __WASI_RIGHTS_FD_FILESTAT_GET (UINT64_C(2097152))
600
601 /**
602 * The right to invoke `fd_filestat_set_size`.
603 */
604 #define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE (UINT64_C(4194304))
605
606 /**
607 * The right to invoke `fd_filestat_set_times`.
608 */
609 #define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES (UINT64_C(8388608))
610
611 /**
612 * The right to invoke `path_symlink`.
613 */
614 #define __WASI_RIGHTS_PATH_SYMLINK (UINT64_C(16777216))
615
616 /**
617 * The right to invoke `path_remove_directory`.
618 */
619 #define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY (UINT64_C(33554432))
620
621 /**
622 * The right to invoke `path_unlink_file`.
623 */
624 #define __WASI_RIGHTS_PATH_UNLINK_FILE (UINT64_C(67108864))
625
626 /**
627 * If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
628 * If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
629 */
630 #define __WASI_RIGHTS_POLL_FD_READWRITE (UINT64_C(134217728))
631
632 /**
633 * The right to invoke `sock_shutdown`.
634 */
635 #define __WASI_RIGHTS_SOCK_SHUTDOWN (UINT64_C(268435456))
636
637 /**
638 * A file descriptor index.
639 */
640 typedef uint32_t __wasi_fd_t;
641
642 /**
643 * A region of memory for scatter/gather reads.
644 */
645 typedef struct __wasi_iovec_t {
646 /**
647 * The address of the buffer to be filled.
648 */
649 uint8_t * buf;
650
651 /**
652 * The length of the buffer to be filled.
653 */
654 __wasi_size_t buf_len;
655
656 } __wasi_iovec_t;
657
658 /**
659 * A region of memory for scatter/gather writes.
660 */
661 typedef struct __wasi_ciovec_t {
662 /**
663 * The address of the buffer to be written.
664 */
665 const uint8_t * buf;
666
667 /**
668 * The length of the buffer to be written.
669 */
670 __wasi_size_t buf_len;
671
672 } __wasi_ciovec_t;
673
674 /**
675 * Relative offset within a file.
676 */
677 typedef int64_t __wasi_filedelta_t;
678
679 /**
680 * The position relative to which to set the offset of the file descriptor.
681 */
682 typedef uint8_t __wasi_whence_t;
683
684 /**
685 * Seek relative to start-of-file.
686 */
687 #define __WASI_WHENCE_SET (UINT8_C(0))
688
689 /**
690 * Seek relative to current position.
691 */
692 #define __WASI_WHENCE_CUR (UINT8_C(1))
693
694 /**
695 * Seek relative to end-of-file.
696 */
697 #define __WASI_WHENCE_END (UINT8_C(2))
698
699 /**
700 * A reference to the offset of a directory entry.
701 *
702 * The value 0 signifies the start of the directory.
703 */
704 typedef uint64_t __wasi_dircookie_t;
705
706 /**
707 * The type for the $d_namlen field of $dirent.
708 */
709 typedef uint32_t __wasi_dirnamlen_t;
710
711 /**
712 * File serial number that is unique within its file system.
713 */
714 typedef uint64_t __wasi_inode_t;
715
716 /**
717 * The type of a file descriptor or file.
718 */
719 typedef uint8_t __wasi_filetype_t;
720
721 /**
722 * The type of the file descriptor or file is unknown or is different from any of the other types specified.
723 */
724 #define __WASI_FILETYPE_UNKNOWN (UINT8_C(0))
725
726 /**
727 * The file descriptor or file refers to a block device inode.
728 */
729 #define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1))
730
731 /**
732 * The file descriptor or file refers to a character device inode.
733 */
734 #define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2))
735
736 /**
737 * The file descriptor or file refers to a directory inode.
738 */
739 #define __WASI_FILETYPE_DIRECTORY (UINT8_C(3))
740
741 /**
742 * The file descriptor or file refers to a regular file inode.
743 */
744 #define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4))
745
746 /**
747 * The file descriptor or file refers to a datagram socket.
748 */
749 #define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5))
750
751 /**
752 * The file descriptor or file refers to a byte-stream socket.
753 */
754 #define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6))
755
756 /**
757 * The file refers to a symbolic link inode.
758 */
759 #define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7))
760
761 /**
762 * A directory entry.
763 */
764 typedef struct __wasi_dirent_t {
765 /**
766 * The offset of the next directory entry stored in this directory.
767 */
768 __wasi_dircookie_t d_next;
769
770 /**
771 * The serial number of the file referred to by this directory entry.
772 */
773 __wasi_inode_t d_ino;
774
775 /**
776 * The length of the name of the directory entry.
777 */
778 __wasi_dirnamlen_t d_namlen;
779
780 /**
781 * The type of the file referred to by this directory entry.
782 */
783 __wasi_filetype_t d_type;
784
785 } __wasi_dirent_t;
786
787 /**
788 * File or memory access pattern advisory information.
789 */
790 typedef uint8_t __wasi_advice_t;
791
792 /**
793 * The application has no advice to give on its behavior with respect to the specified data.
794 */
795 #define __WASI_ADVICE_NORMAL (UINT8_C(0))
796
797 /**
798 * The application expects to access the specified data sequentially from lower offsets to higher offsets.
799 */
800 #define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1))
801
802 /**
803 * The application expects to access the specified data in a random order.
804 */
805 #define __WASI_ADVICE_RANDOM (UINT8_C(2))
806
807 /**
808 * The application expects to access the specified data in the near future.
809 */
810 #define __WASI_ADVICE_WILLNEED (UINT8_C(3))
811
812 /**
813 * The application expects that it will not access the specified data in the near future.
814 */
815 #define __WASI_ADVICE_DONTNEED (UINT8_C(4))
816
817 /**
818 * The application expects to access the specified data once and then not reuse it thereafter.
819 */
820 #define __WASI_ADVICE_NOREUSE (UINT8_C(5))
821
822 /**
823 * File descriptor flags.
824 */
825 typedef uint16_t __wasi_fdflags_t;
826
827 /**
828 * Append mode: Data written to the file is always appended to the file's end.
829 */
830 #define __WASI_FDFLAGS_APPEND (UINT16_C(1))
831
832 /**
833 * Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
834 */
835 #define __WASI_FDFLAGS_DSYNC (UINT16_C(2))
836
837 /**
838 * Non-blocking mode.
839 */
840 #define __WASI_FDFLAGS_NONBLOCK (UINT16_C(4))
841
842 /**
843 * Synchronized read I/O operations.
844 */
845 #define __WASI_FDFLAGS_RSYNC (UINT16_C(8))
846
847 /**
848 * Write according to synchronized I/O file integrity completion. In
849 * addition to synchronizing the data stored in the file, the implementation
850 * may also synchronously update the file's metadata.
851 */
852 #define __WASI_FDFLAGS_SYNC (UINT16_C(16))
853
854 /**
855 * File descriptor attributes.
856 */
857 typedef struct __wasi_fdstat_t {
858 /**
859 * File type.
860 */
861 __wasi_filetype_t fs_filetype;
862
863 /**
864 * File descriptor flags.
865 */
866 __wasi_fdflags_t fs_flags;
867
868 /**
869 * Rights that apply to this file descriptor.
870 */
871 __wasi_rights_t fs_rights_base;
872
873 /**
874 * Maximum set of rights that may be installed on new file descriptors that
875 * are created through this file descriptor, e.g., through `path_open`.
876 */
877 __wasi_rights_t fs_rights_inheriting;
878
879 } __wasi_fdstat_t;
880
881 /**
882 * Identifier for a device containing a file system. Can be used in combination
883 * with `inode` to uniquely identify a file or directory in the filesystem.
884 */
885 typedef uint64_t __wasi_device_t;
886
887 /**
888 * Which file time attributes to adjust.
889 */
890 typedef uint16_t __wasi_fstflags_t;
891
892 /**
893 * Adjust the last data access timestamp to the value stored in `filestat::st_atim`.
894 */
895 #define __WASI_FSTFLAGS_ATIM (UINT16_C(1))
896
897 /**
898 * Adjust the last data access timestamp to the time of clock `clock::realtime`.
899 */
900 #define __WASI_FSTFLAGS_ATIM_NOW (UINT16_C(2))
901
902 /**
903 * Adjust the last data modification timestamp to the value stored in `filestat::st_mtim`.
904 */
905 #define __WASI_FSTFLAGS_MTIM (UINT16_C(4))
906
907 /**
908 * Adjust the last data modification timestamp to the time of clock `clock::realtime`.
909 */
910 #define __WASI_FSTFLAGS_MTIM_NOW (UINT16_C(8))
911
912 /**
913 * Flags determining the method of how paths are resolved.
914 */
915 typedef uint32_t __wasi_lookupflags_t;
916
917 /**
918 * As long as the resolved path corresponds to a symbolic link, it is expanded.
919 */
920 #define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW (UINT32_C(1))
921
922 /**
923 * Open flags used by `path_open`.
924 */
925 typedef uint16_t __wasi_oflags_t;
926
927 /**
928 * Create file if it does not exist.
929 */
930 #define __WASI_OFLAGS_CREAT (UINT16_C(1))
931
932 /**
933 * Fail if not a directory.
934 */
935 #define __WASI_OFLAGS_DIRECTORY (UINT16_C(2))
936
937 /**
938 * Fail if file already exists.
939 */
940 #define __WASI_OFLAGS_EXCL (UINT16_C(4))
941
942 /**
943 * Truncate file to size 0.
944 */
945 #define __WASI_OFLAGS_TRUNC (UINT16_C(8))
946
947 /**
948 * Number of hard links to an inode.
949 */
950 typedef uint64_t __wasi_linkcount_t;
951
952 /**
953 * File attributes.
954 */
955 typedef struct __wasi_filestat_t {
956 /**
957 * Device ID of device containing the file.
958 */
959 __wasi_device_t dev;
960
961 /**
962 * File serial number.
963 */
964 __wasi_inode_t ino;
965
966 /**
967 * File type.
968 */
969 __wasi_filetype_t filetype;
970
971 /**
972 * Number of hard links to the file.
973 */
974 __wasi_linkcount_t nlink;
975
976 /**
977 * For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
978 */
979 __wasi_filesize_t size;
980
981 /**
982 * Last data access timestamp.
983 */
984 __wasi_timestamp_t atim;
985
986 /**
987 * Last data modification timestamp.
988 */
989 __wasi_timestamp_t mtim;
990
991 /**
992 * Last file status change timestamp.
993 */
994 __wasi_timestamp_t ctim;
995
996 } __wasi_filestat_t;
997
998 /**
999 * User-provided value that may be attached to objects that is retained when
1000 * extracted from the implementation.
1001 */
1002 typedef uint64_t __wasi_userdata_t;
1003
1004 /**
1005 * Type of a subscription to an event or its occurrence.
1006 */
1007 typedef uint8_t __wasi_eventtype_t;
1008
1009 /**
1010 * The time value of clock `subscription::u.clock.clock_id` has
1011 * reached timestamp `subscription::u.clock.timeout`.
1012 */
1013 #define __WASI_EVENTTYPE_CLOCK (UINT8_C(0))
1014
1015 /**
1016 * File descriptor `subscription::u.fd_readwrite.fd` has data
1017 * available for reading. This event always triggers for regular files.
1018 */
1019 #define __WASI_EVENTTYPE_FD_READ (UINT8_C(1))
1020
1021 /**
1022 * File descriptor `subscription::u.fd_readwrite.fd` has capacity
1023 * available for writing. This event always triggers for regular files.
1024 */
1025 #define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2))
1026
1027 /**
1028 * The state of the file descriptor subscribed to with
1029 * `eventtype::fd_read` or `eventtype::fd_write`.
1030 */
1031 typedef uint16_t __wasi_eventrwflags_t;
1032
1033 /**
1034 * The peer of this socket has closed or disconnected.
1035 */
1036 #define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP (UINT16_C(1))
1037
1038 /**
1039 * The contents of an $event when type is `eventtype::fd_read` or
1040 * `eventtype::fd_write`.
1041 */
1042 typedef struct __wasi_event_fd_readwrite_t {
1043 /**
1044 * The number of bytes available for reading or writing.
1045 */
1046 __wasi_filesize_t nbytes;
1047
1048 /**
1049 * The state of the file descriptor.
1050 */
1051 __wasi_eventrwflags_t flags;
1052
1053 } __wasi_event_fd_readwrite_t;
1054
1055 /**
1056 * The contents of an $event.
1057 */
1058 typedef union __wasi_event_u_t {
1059 /**
1060 * When type is `eventtype::fd_read` or `eventtype::fd_write`:
1061 */
1062 __wasi_event_fd_readwrite_t fd_readwrite;
1063
1064 } __wasi_event_u_t;
1065
1066 /**
1067 * An event that occurred.
1068 */
1069 typedef struct __wasi_event_t {
1070 /**
1071 * User-provided value that got attached to `subscription::userdata`.
1072 */
1073 __wasi_userdata_t userdata;
1074
1075 /**
1076 * If non-zero, an error that occurred while processing the subscription request.
1077 */
1078 __wasi_errno_t error;
1079
1080 /**
1081 * The type of the event that occurred.
1082 */
1083 __wasi_eventtype_t type;
1084
1085 /**
1086 * The contents of the event.
1087 */
1088 __wasi_event_u_t u;
1089
1090 } __wasi_event_t;
1091
1092 /**
1093 * Flags determining how to interpret the timestamp provided in
1094 * `subscription::u.clock.timeout.`
1095 */
1096 typedef uint16_t __wasi_subclockflags_t;
1097
1098 /**
1099 * If set, treat the timestamp provided in
1100 * `subscription::u.clock.timeout` as an absolute timestamp of clock
1101 * `subscription::u.clock.clock_id.` If clear, treat the timestamp
1102 * provided in `subscription::u.clock.timeout` relative to the
1103 * current time value of clock `subscription::u.clock.clock_id.`
1104 */
1105 #define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME (UINT16_C(1))
1106
1107 /**
1108 * The contents of a $subscription when type is `eventtype::clock`.
1109 */
1110 typedef struct __wasi_subscription_clock_t {
1111 /**
1112 * The clock against which to compare the timestamp.
1113 */
1114 __wasi_clockid_t id;
1115
1116 /**
1117 * The absolute or relative timestamp.
1118 */
1119 __wasi_timestamp_t timeout;
1120
1121 /**
1122 * The amount of time that the implementation may wait additionally
1123 * to coalesce with other events.
1124 */
1125 __wasi_timestamp_t precision;
1126
1127 /**
1128 * Flags specifying whether the timeout is absolute or relative
1129 */
1130 __wasi_subclockflags_t flags;
1131
1132 } __wasi_subscription_clock_t;
1133
1134 /**
1135 * The contents of a $subscription when type is type is
1136 * `eventtype::fd_read` or `eventtype::fd_write`.
1137 */
1138 typedef struct __wasi_subscription_fd_readwrite_t {
1139 /**
1140 * The file descriptor on which to wait for it to become ready for reading or writing.
1141 */
1142 __wasi_fd_t file_descriptor;
1143
1144 } __wasi_subscription_fd_readwrite_t;
1145
1146 /**
1147 * The contents of a $subscription.
1148 */
1149 typedef union __wasi_subscription_u_t {
1150 /**
1151 * When type is `eventtype::clock`:
1152 */
1153 __wasi_subscription_clock_t clock;
1154
1155 /**
1156 * When type is `eventtype::fd_read` or `eventtype::fd_write`:
1157 */
1158 __wasi_subscription_fd_readwrite_t fd_readwrite;
1159
1160 } __wasi_subscription_u_t;
1161
1162 /**
1163 * Subscription to an event.
1164 */
1165 typedef struct __wasi_subscription_t {
1166 /**
1167 * User-provided value that is attached to the subscription in the
1168 * implementation and returned through `event::userdata`.
1169 */
1170 __wasi_userdata_t userdata;
1171
1172 /**
1173 * The type of the event to which to subscribe.
1174 */
1175 __wasi_eventtype_t type;
1176
1177 /**
1178 * The contents of the subscription.
1179 */
1180 __wasi_subscription_u_t u;
1181
1182 } __wasi_subscription_t;
1183
1184 /**
1185 * Exit code generated by a process when exiting.
1186 */
1187 typedef uint32_t __wasi_exitcode_t;
1188
1189 /**
1190 * Signal condition.
1191 */
1192 typedef uint8_t __wasi_signal_t;
1193
1194 /**
1195 * No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
1196 * so this value is reserved.
1197 */
1198 #define __WASI_SIGNAL_NONE (UINT8_C(0))
1199
1200 /**
1201 * Hangup.
1202 * Action: Terminates the process.
1203 */
1204 #define __WASI_SIGNAL_HUP (UINT8_C(1))
1205
1206 /**
1207 * Terminate interrupt signal.
1208 * Action: Terminates the process.
1209 */
1210 #define __WASI_SIGNAL_INT (UINT8_C(2))
1211
1212 /**
1213 * Terminal quit signal.
1214 * Action: Terminates the process.
1215 */
1216 #define __WASI_SIGNAL_QUIT (UINT8_C(3))
1217
1218 /**
1219 * Illegal instruction.
1220 * Action: Terminates the process.
1221 */
1222 #define __WASI_SIGNAL_ILL (UINT8_C(4))
1223
1224 /**
1225 * Trace/breakpoint trap.
1226 * Action: Terminates the process.
1227 */
1228 #define __WASI_SIGNAL_TRAP (UINT8_C(5))
1229
1230 /**
1231 * Process abort signal.
1232 * Action: Terminates the process.
1233 */
1234 #define __WASI_SIGNAL_ABRT (UINT8_C(6))
1235
1236 /**
1237 * Access to an undefined portion of a memory object.
1238 * Action: Terminates the process.
1239 */
1240 #define __WASI_SIGNAL_BUS (UINT8_C(7))
1241
1242 /**
1243 * Erroneous arithmetic operation.
1244 * Action: Terminates the process.
1245 */
1246 #define __WASI_SIGNAL_FPE (UINT8_C(8))
1247
1248 /**
1249 * Kill.
1250 * Action: Terminates the process.
1251 */
1252 #define __WASI_SIGNAL_KILL (UINT8_C(9))
1253
1254 /**
1255 * User-defined signal 1.
1256 * Action: Terminates the process.
1257 */
1258 #define __WASI_SIGNAL_USR1 (UINT8_C(10))
1259
1260 /**
1261 * Invalid memory reference.
1262 * Action: Terminates the process.
1263 */
1264 #define __WASI_SIGNAL_SEGV (UINT8_C(11))
1265
1266 /**
1267 * User-defined signal 2.
1268 * Action: Terminates the process.
1269 */
1270 #define __WASI_SIGNAL_USR2 (UINT8_C(12))
1271
1272 /**
1273 * Write on a pipe with no one to read it.
1274 * Action: Ignored.
1275 */
1276 #define __WASI_SIGNAL_PIPE (UINT8_C(13))
1277
1278 /**
1279 * Alarm clock.
1280 * Action: Terminates the process.
1281 */
1282 #define __WASI_SIGNAL_ALRM (UINT8_C(14))
1283
1284 /**
1285 * Termination signal.
1286 * Action: Terminates the process.
1287 */
1288 #define __WASI_SIGNAL_TERM (UINT8_C(15))
1289
1290 /**
1291 * Child process terminated, stopped, or continued.
1292 * Action: Ignored.
1293 */
1294 #define __WASI_SIGNAL_CHLD (UINT8_C(16))
1295
1296 /**
1297 * Continue executing, if stopped.
1298 * Action: Continues executing, if stopped.
1299 */
1300 #define __WASI_SIGNAL_CONT (UINT8_C(17))
1301
1302 /**
1303 * Stop executing.
1304 * Action: Stops executing.
1305 */
1306 #define __WASI_SIGNAL_STOP (UINT8_C(18))
1307
1308 /**
1309 * Terminal stop signal.
1310 * Action: Stops executing.
1311 */
1312 #define __WASI_SIGNAL_TSTP (UINT8_C(19))
1313
1314 /**
1315 * Background process attempting read.
1316 * Action: Stops executing.
1317 */
1318 #define __WASI_SIGNAL_TTIN (UINT8_C(20))
1319
1320 /**
1321 * Background process attempting write.
1322 * Action: Stops executing.
1323 */
1324 #define __WASI_SIGNAL_TTOU (UINT8_C(21))
1325
1326 /**
1327 * High bandwidth data is available at a socket.
1328 * Action: Ignored.
1329 */
1330 #define __WASI_SIGNAL_URG (UINT8_C(22))
1331
1332 /**
1333 * CPU time limit exceeded.
1334 * Action: Terminates the process.
1335 */
1336 #define __WASI_SIGNAL_XCPU (UINT8_C(23))
1337
1338 /**
1339 * File size limit exceeded.
1340 * Action: Terminates the process.
1341 */
1342 #define __WASI_SIGNAL_XFSZ (UINT8_C(24))
1343
1344 /**
1345 * Virtual timer expired.
1346 * Action: Terminates the process.
1347 */
1348 #define __WASI_SIGNAL_VTALRM (UINT8_C(25))
1349
1350 /**
1351 * Profiling timer expired.
1352 * Action: Terminates the process.
1353 */
1354 #define __WASI_SIGNAL_PROF (UINT8_C(26))
1355
1356 /**
1357 * Window changed.
1358 * Action: Ignored.
1359 */
1360 #define __WASI_SIGNAL_WINCH (UINT8_C(27))
1361
1362 /**
1363 * I/O possible.
1364 * Action: Terminates the process.
1365 */
1366 #define __WASI_SIGNAL_POLL (UINT8_C(28))
1367
1368 /**
1369 * Power failure.
1370 * Action: Terminates the process.
1371 */
1372 #define __WASI_SIGNAL_PWR (UINT8_C(29))
1373
1374 /**
1375 * Bad system call.
1376 * Action: Terminates the process.
1377 */
1378 #define __WASI_SIGNAL_SYS (UINT8_C(30))
1379
1380 /**
1381 * Flags provided to `sock_recv`.
1382 */
1383 typedef uint16_t __wasi_riflags_t;
1384
1385 /**
1386 * Returns the message without removing it from the socket's receive queue.
1387 */
1388 #define __WASI_RIFLAGS_RECV_PEEK (UINT16_C(1))
1389
1390 /**
1391 * On byte-stream sockets, block until the full amount of data can be returned.
1392 */
1393 #define __WASI_RIFLAGS_RECV_WAITALL (UINT16_C(2))
1394
1395 /**
1396 * Flags returned by `sock_recv`.
1397 */
1398 typedef uint16_t __wasi_roflags_t;
1399
1400 /**
1401 * Returned by `sock_recv`: Message data has been truncated.
1402 */
1403 #define __WASI_ROFLAGS_RECV_DATA_TRUNCATED (UINT16_C(1))
1404
1405 /**
1406 * Flags provided to `sock_send`. As there are currently no flags
1407 * defined, it must be set to zero.
1408 */
1409 typedef uint16_t __wasi_siflags_t;
1410
1411 /**
1412 * Which channels on a socket to shut down.
1413 */
1414 typedef uint8_t __wasi_sdflags_t;
1415
1416 /**
1417 * Disables further receive operations.
1418 */
1419 #define __WASI_SDFLAGS_RD (UINT8_C(1))
1420
1421 /**
1422 * Disables further send operations.
1423 */
1424 #define __WASI_SDFLAGS_WR (UINT8_C(2))
1425
1426 /**
1427 * Identifiers for preopened capabilities.
1428 */
1429 typedef uint8_t __wasi_preopentype_t;
1430
1431 /**
1432 * A pre-opened directory.
1433 */
1434 #define __WASI_PREOPENTYPE_DIR (UINT8_C(0))
1435
1436 /**
1437 * The contents of a $prestat when type is `preopentype::dir`.
1438 */
1439 typedef struct __wasi_prestat_dir_t {
1440 /**
1441 * The length of the directory name for use with `fd_prestat_dir_name`.
1442 */
1443 __wasi_size_t pr_name_len;
1444
1445 } __wasi_prestat_dir_t;
1446
1447 /**
1448 * The contents of an $prestat.
1449 */
1450 typedef union __wasi_prestat_u_t {
1451 /**
1452 * When type is `preopentype::dir`:
1453 */
1454 __wasi_prestat_dir_t dir;
1455
1456 } __wasi_prestat_u_t;
1457
1458 /**
1459 * Information about a pre-opened capability.
1460 */
1461 typedef struct __wasi_prestat_t {
1462 /**
1463 * The type of the pre-opened capability.
1464 */
1465 __wasi_preopentype_t pr_type;
1466
1467 /**
1468 * The contents of the information.
1469 */
1470 __wasi_prestat_u_t u;
1471
1472 } __wasi_prestat_t;
1473
1474 /**
1475 * @defgroup wasi_snapshot_preview1
1476 * @{
1477 */
1478
1479 /**
1480 * Read command-line argument data.
1481 * The size of the array should match that returned by `wasi_args_sizes_get()`
1482 */
1483 __wasi_errno_t __wasi_args_get(
1484 uint8_t * * argv,
1485
1486 uint8_t * argv_buf
1487 ) __attribute__((
1488 __import_module__("wasi_snapshot_preview1"),
1489 __import_name__("args_get"),
1490 __warn_unused_result__
1491 ));
1492
1493 /**
1494 * Return command-line argument data sizes.
1495 */
1496 __wasi_errno_t __wasi_args_sizes_get(
1497 /**
1498 * The number of arguments.
1499 */
1500 __wasi_size_t *argc,
1501 /**
1502 * The size of the argument string data.
1503 */
1504 __wasi_size_t *argv_buf_size
1505 ) __attribute__((
1506 __import_module__("wasi_snapshot_preview1"),
1507 __import_name__("args_sizes_get"),
1508 __warn_unused_result__
1509 ));
1510
1511 /**
1512 * Read environment variable data.
1513 * The sizes of the buffers should match that returned by `environ.sizes_get()`.
1514 */
1515 __wasi_errno_t __wasi_environ_get(
1516 uint8_t * * environ,
1517
1518 uint8_t * environ_buf
1519 ) __attribute__((
1520 __import_module__("wasi_snapshot_preview1"),
1521 __import_name__("environ_get"),
1522 __warn_unused_result__
1523 ));
1524
1525 /**
1526 * Return command-line argument data sizes.
1527 */
1528 __wasi_errno_t __wasi_environ_sizes_get(
1529 /**
1530 * The number of arguments.
1531 */
1532 __wasi_size_t *argc,
1533 /**
1534 * The size of the argument string data.
1535 */
1536 __wasi_size_t *argv_buf_size
1537 ) __attribute__((
1538 __import_module__("wasi_snapshot_preview1"),
1539 __import_name__("environ_sizes_get"),
1540 __warn_unused_result__
1541 ));
1542
1543 /**
1544 * Return the resolution of a clock.
1545 * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return `WASI_EINVAL`
1546 * Note: This is similar to `clock_getres` in POSIX.
1547 */
1548 __wasi_errno_t __wasi_clock_res_get(
1549 /**
1550 * The clock for which to return the resolution.
1551 */
1552 __wasi_clockid_t id,
1553
1554 /**
1555 * The resolution of the clock.
1556 */
1557 __wasi_timestamp_t *resolution
1558 ) __attribute__((
1559 __import_module__("wasi_snapshot_preview1"),
1560 __import_name__("clock_res_get"),
1561 __warn_unused_result__
1562 ));
1563
1564 /**
1565 * Return the time value of a clock.
1566 * Note: This is similar to `clock_gettime` in POSIX.
1567 */
1568 __wasi_errno_t __wasi_clock_time_get(
1569 /**
1570 * The clock for which to return the time.
1571 */
1572 __wasi_clockid_t id,
1573
1574 /**
1575 * The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
1576 */
1577 __wasi_timestamp_t precision,
1578
1579 /**
1580 * The time value of the clock.
1581 */
1582 __wasi_timestamp_t *time
1583 ) __attribute__((
1584 __import_module__("wasi_snapshot_preview1"),
1585 __import_name__("clock_time_get"),
1586 __warn_unused_result__
1587 ));
1588
1589 /**
1590 * Provide file advisory information on a file descriptor.
1591 * Note: This is similar to `posix_fadvise` in POSIX.
1592 */
1593 __wasi_errno_t __wasi_fd_advise(
1594 __wasi_fd_t fd,
1595
1596 /**
1597 * The offset within the file to which the advisory applies.
1598 */
1599 __wasi_filesize_t offset,
1600
1601 /**
1602 * The length of the region to which the advisory applies.
1603 */
1604 __wasi_filesize_t len,
1605
1606 /**
1607 * The advice.
1608 */
1609 __wasi_advice_t advice
1610 ) __attribute__((
1611 __import_module__("wasi_snapshot_preview1"),
1612 __import_name__("fd_advise"),
1613 __warn_unused_result__
1614 ));
1615
1616 /**
1617 * Force the allocation of space in a file.
1618 * Note: This is similar to `posix_fallocate` in POSIX.
1619 */
1620 __wasi_errno_t __wasi_fd_allocate(
1621 __wasi_fd_t fd,
1622
1623 /**
1624 * The offset at which to start the allocation.
1625 */
1626 __wasi_filesize_t offset,
1627
1628 /**
1629 * The length of the area that is allocated.
1630 */
1631 __wasi_filesize_t len
1632 ) __attribute__((
1633 __import_module__("wasi_snapshot_preview1"),
1634 __import_name__("fd_allocate"),
1635 __warn_unused_result__
1636 ));
1637
1638 /**
1639 * Close a file descriptor.
1640 * Note: This is similar to `close` in POSIX.
1641 */
1642 __wasi_errno_t __wasi_fd_close(
1643 __wasi_fd_t fd
1644 ) __attribute__((
1645 __import_module__("wasi_snapshot_preview1"),
1646 __import_name__("fd_close"),
1647 __warn_unused_result__
1648 ));
1649
1650 /**
1651 * Synchronize the data of a file to disk.
1652 * Note: This is similar to `fdatasync` in POSIX.
1653 */
1654 __wasi_errno_t __wasi_fd_datasync(
1655 __wasi_fd_t fd
1656 ) __attribute__((
1657 __import_module__("wasi_snapshot_preview1"),
1658 __import_name__("fd_datasync"),
1659 __warn_unused_result__
1660 ));
1661
1662 /**
1663 * Get the attributes of a file descriptor.
1664 * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
1665 */
1666 __wasi_errno_t __wasi_fd_fdstat_get(
1667 __wasi_fd_t fd,
1668
1669 /**
1670 * The buffer where the file descriptor's attributes are stored.
1671 */
1672 __wasi_fdstat_t *stat
1673 ) __attribute__((
1674 __import_module__("wasi_snapshot_preview1"),
1675 __import_name__("fd_fdstat_get"),
1676 __warn_unused_result__
1677 ));
1678
1679 /**
1680 * Adjust the flags associated with a file descriptor.
1681 * Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
1682 */
1683 __wasi_errno_t __wasi_fd_fdstat_set_flags(
1684 __wasi_fd_t fd,
1685
1686 /**
1687 * The desired values of the file descriptor flags.
1688 */
1689 __wasi_fdflags_t flags
1690 ) __attribute__((
1691 __import_module__("wasi_snapshot_preview1"),
1692 __import_name__("fd_fdstat_set_flags"),
1693 __warn_unused_result__
1694 ));
1695
1696 /**
1697 * Adjust the rights associated with a file descriptor.
1698 * This can only be used to remove rights, and returns `ENOTCAPABLE` if called in a way that would attempt to add rights
1699 */
1700 __wasi_errno_t __wasi_fd_fdstat_set_rights(
1701 __wasi_fd_t fd,
1702
1703 /**
1704 * The desired rights of the file descriptor.
1705 */
1706 __wasi_rights_t fs_rights_base,
1707
1708 __wasi_rights_t fs_rights_inheriting
1709 ) __attribute__((
1710 __import_module__("wasi_snapshot_preview1"),
1711 __import_name__("fd_fdstat_set_rights"),
1712 __warn_unused_result__
1713 ));
1714
1715 /**
1716 * Return the attributes of an open file.
1717 */
1718 __wasi_errno_t __wasi_fd_filestat_get(
1719 __wasi_fd_t fd,
1720
1721 /**
1722 * The buffer where the file's attributes are stored.
1723 */
1724 __wasi_filestat_t *buf
1725 ) __attribute__((
1726 __import_module__("wasi_snapshot_preview1"),
1727 __import_name__("fd_filestat_get"),
1728 __warn_unused_result__
1729 ));
1730
1731 /**
1732 * Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
1733 * Note: This is similar to `ftruncate` in POSIX.
1734 */
1735 __wasi_errno_t __wasi_fd_filestat_set_size(
1736 __wasi_fd_t fd,
1737
1738 /**
1739 * The desired file size.
1740 */
1741 __wasi_filesize_t size
1742 ) __attribute__((
1743 __import_module__("wasi_snapshot_preview1"),
1744 __import_name__("fd_filestat_set_size"),
1745 __warn_unused_result__
1746 ));
1747
1748 /**
1749 * Adjust the timestamps of an open file or directory.
1750 * Note: This is similar to `futimens` in POSIX.
1751 */
1752 __wasi_errno_t __wasi_fd_filestat_set_times(
1753 __wasi_fd_t fd,
1754
1755 /**
1756 * The desired values of the data access timestamp.
1757 */
1758 __wasi_timestamp_t atim,
1759
1760 /**
1761 * The desired values of the data modification timestamp.
1762 */
1763 __wasi_timestamp_t mtim,
1764
1765 /**
1766 * A bitmask indicating which timestamps to adjust.
1767 */
1768 __wasi_fstflags_t fst_flags
1769 ) __attribute__((
1770 __import_module__("wasi_snapshot_preview1"),
1771 __import_name__("fd_filestat_set_times"),
1772 __warn_unused_result__
1773 ));
1774
1775 /**
1776 * Read from a file descriptor, without using and updating the file descriptor's offset.
1777 * Note: This is similar to `preadv` in POSIX.
1778 */
1779 __wasi_errno_t __wasi_fd_pread(
1780 __wasi_fd_t fd,
1781
1782 /**
1783 * List of scatter/gather vectors in which to store data.
1784 */
1785 const __wasi_iovec_t *iovs,
1786
1787 /**
1788 * The length of the array pointed to by `iovs`.
1789 */
1790 size_t iovs_len,
1791
1792 /**
1793 * The offset within the file at which to read.
1794 */
1795 __wasi_filesize_t offset,
1796
1797 /**
1798 * The number of bytes read.
1799 */
1800 __wasi_size_t *nread
1801 ) __attribute__((
1802 __import_module__("wasi_snapshot_preview1"),
1803 __import_name__("fd_pread"),
1804 __warn_unused_result__
1805 ));
1806
1807 /**
1808 * Return a description of the given preopened file descriptor.
1809 */
1810 __wasi_errno_t __wasi_fd_prestat_get(
1811 __wasi_fd_t fd,
1812
1813 /**
1814 * The buffer where the description is stored.
1815 */
1816 __wasi_prestat_t *buf
1817 ) __attribute__((
1818 __import_module__("wasi_snapshot_preview1"),
1819 __import_name__("fd_prestat_get"),
1820 __warn_unused_result__
1821 ));
1822
1823 /**
1824 * Return a description of the given preopened file descriptor.
1825 */
1826 __wasi_errno_t __wasi_fd_prestat_dir_name(
1827 __wasi_fd_t fd,
1828
1829 /**
1830 * A buffer into which to write the preopened directory name.
1831 */
1832 uint8_t * path,
1833
1834 __wasi_size_t path_len
1835 ) __attribute__((
1836 __import_module__("wasi_snapshot_preview1"),
1837 __import_name__("fd_prestat_dir_name"),
1838 __warn_unused_result__
1839 ));
1840
1841 /**
1842 * Write to a file descriptor, without using and updating the file descriptor's offset.
1843 * Note: This is similar to `pwritev` in POSIX.
1844 */
1845 __wasi_errno_t __wasi_fd_pwrite(
1846 __wasi_fd_t fd,
1847
1848 /**
1849 * List of scatter/gather vectors from which to retrieve data.
1850 */
1851 const __wasi_ciovec_t *iovs,
1852
1853 /**
1854 * The length of the array pointed to by `iovs`.
1855 */
1856 size_t iovs_len,
1857
1858 /**
1859 * The offset within the file at which to write.
1860 */
1861 __wasi_filesize_t offset,
1862
1863 /**
1864 * The number of bytes written.
1865 */
1866 __wasi_size_t *nwritten
1867 ) __attribute__((
1868 __import_module__("wasi_snapshot_preview1"),
1869 __import_name__("fd_pwrite"),
1870 __warn_unused_result__
1871 ));
1872
1873 /**
1874 * Read from a file descriptor.
1875 * Note: This is similar to `readv` in POSIX.
1876 */
1877 __wasi_errno_t __wasi_fd_read(
1878 __wasi_fd_t fd,
1879
1880 /**
1881 * List of scatter/gather vectors to which to store data.
1882 */
1883 const __wasi_iovec_t *iovs,
1884
1885 /**
1886 * The length of the array pointed to by `iovs`.
1887 */
1888 size_t iovs_len,
1889
1890 /**
1891 * The number of bytes read.
1892 */
1893 __wasi_size_t *nread
1894 ) __attribute__((
1895 __import_module__("wasi_snapshot_preview1"),
1896 __import_name__("fd_read"),
1897 __warn_unused_result__
1898 ));
1899
1900 /**
1901 * Read directory entries from a directory.
1902 * When successful, the contents of the output buffer consist of a sequence of
1903 * directory entries. Each directory entry consists of a dirent_t object,
1904 * followed by dirent_t::d_namlen bytes holding the name of the directory
1905 * entry.
1906 * This function fills the output buffer as much as possible, potentially
1907 * truncating the last directory entry. This allows the caller to grow its
1908 * read buffer size in case it's too small to fit a single large directory
1909 * entry, or skip the oversized directory entry.
1910 */
1911 __wasi_errno_t __wasi_fd_readdir(
1912 __wasi_fd_t fd,
1913
1914 /**
1915 * The buffer where directory entries are stored
1916 */
1917 uint8_t * buf,
1918
1919 __wasi_size_t buf_len,
1920
1921 /**
1922 * The location within the directory to start reading
1923 */
1924 __wasi_dircookie_t cookie,
1925
1926 /**
1927 * 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.
1928 */
1929 __wasi_size_t *bufused
1930 ) __attribute__((
1931 __import_module__("wasi_snapshot_preview1"),
1932 __import_name__("fd_readdir"),
1933 __warn_unused_result__
1934 ));
1935
1936 /**
1937 * Atomically replace a file descriptor by renumbering another file descriptor.
1938 * Due to the strong focus on thread safety, this environment does not provide
1939 * a mechanism to duplicate or renumber a file descriptor to an arbitrary
1940 * number, like `dup2()`. This would be prone to race conditions, as an actual
1941 * file descriptor with the same number could be allocated by a different
1942 * thread at the same time.
1943 * This function provides a way to atomically renumber file descriptors, which
1944 * would disappear if `dup2()` were to be removed entirely.
1945 */
1946 __wasi_errno_t __wasi_fd_renumber(
1947 __wasi_fd_t fd,
1948
1949 /**
1950 * The file descriptor to overwrite.
1951 */
1952 __wasi_fd_t to
1953 ) __attribute__((
1954 __import_module__("wasi_snapshot_preview1"),
1955 __import_name__("fd_renumber"),
1956 __warn_unused_result__
1957 ));
1958
1959 /**
1960 * Move the offset of a file descriptor.
1961 * Note: This is similar to `lseek` in POSIX.
1962 */
1963 __wasi_errno_t __wasi_fd_seek(
1964 __wasi_fd_t fd,
1965
1966 /**
1967 * The number of bytes to move.
1968 */
1969 __wasi_filedelta_t offset,
1970
1971 /**
1972 * The base from which the offset is relative.
1973 */
1974 __wasi_whence_t whence,
1975
1976 /**
1977 * The new offset of the file descriptor, relative to the start of the file.
1978 */
1979 __wasi_filesize_t *newoffset
1980 ) __attribute__((
1981 __import_module__("wasi_snapshot_preview1"),
1982 __import_name__("fd_seek"),
1983 __warn_unused_result__
1984 ));
1985
1986 /**
1987 * Synchronize the data and metadata of a file to disk.
1988 * Note: This is similar to `fsync` in POSIX.
1989 */
1990 __wasi_errno_t __wasi_fd_sync(
1991 __wasi_fd_t fd
1992 ) __attribute__((
1993 __import_module__("wasi_snapshot_preview1"),
1994 __import_name__("fd_sync"),
1995 __warn_unused_result__
1996 ));
1997
1998 /**
1999 * Return the current offset of a file descriptor.
2000 * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
2001 */
2002 __wasi_errno_t __wasi_fd_tell(
2003 __wasi_fd_t fd,
2004
2005 /**
2006 * The current offset of the file descriptor, relative to the start of the file.
2007 */
2008 __wasi_filesize_t *offset
2009 ) __attribute__((
2010 __import_module__("wasi_snapshot_preview1"),
2011 __import_name__("fd_tell"),
2012 __warn_unused_result__
2013 ));
2014
2015 /**
2016 * Write to a file descriptor.
2017 * Note: This is similar to `writev` in POSIX.
2018 */
2019 __wasi_errno_t __wasi_fd_write(
2020 __wasi_fd_t fd,
2021
2022 /**
2023 * List of scatter/gather vectors from which to retrieve data.
2024 */
2025 const __wasi_ciovec_t *iovs,
2026
2027 /**
2028 * The length of the array pointed to by `iovs`.
2029 */
2030 size_t iovs_len,
2031
2032 /**
2033 * The number of bytes written.
2034 */
2035 __wasi_size_t *nwritten
2036 ) __attribute__((
2037 __import_module__("wasi_snapshot_preview1"),
2038 __import_name__("fd_write"),
2039 __warn_unused_result__
2040 ));
2041
2042 /**
2043 * Create a directory.
2044 * Note: This is similar to `mkdirat` in POSIX.
2045 */
2046 __wasi_errno_t __wasi_path_create_directory(
2047 __wasi_fd_t fd,
2048
2049 /**
2050 * The path at which to create the directory.
2051 */
2052 const char *path,
2053
2054 /**
2055 * The length of the buffer pointed to by `path`.
2056 */
2057 size_t path_len
2058 ) __attribute__((
2059 __import_module__("wasi_snapshot_preview1"),
2060 __import_name__("path_create_directory"),
2061 __warn_unused_result__
2062 ));
2063
2064 /**
2065 * Return the attributes of a file or directory.
2066 * Note: This is similar to `stat` in POSIX.
2067 */
2068 __wasi_errno_t __wasi_path_filestat_get(
2069 __wasi_fd_t fd,
2070
2071 /**
2072 * Flags determining the method of how the path is resolved.
2073 */
2074 __wasi_lookupflags_t flags,
2075
2076 /**
2077 * The path of the file or directory to inspect.
2078 */
2079 const char *path,
2080
2081 /**
2082 * The length of the buffer pointed to by `path`.
2083 */
2084 size_t path_len,
2085
2086 /**
2087 * The buffer where the file's attributes are stored.
2088 */
2089 __wasi_filestat_t *buf
2090 ) __attribute__((
2091 __import_module__("wasi_snapshot_preview1"),
2092 __import_name__("path_filestat_get"),
2093 __warn_unused_result__
2094 ));
2095
2096 /**
2097 * Adjust the timestamps of a file or directory.
2098 * Note: This is similar to `utimensat` in POSIX.
2099 */
2100 __wasi_errno_t __wasi_path_filestat_set_times(
2101 __wasi_fd_t fd,
2102
2103 /**
2104 * Flags determining the method of how the path is resolved.
2105 */
2106 __wasi_lookupflags_t flags,
2107
2108 /**
2109 * The path of the file or directory to operate on.
2110 */
2111 const char *path,
2112
2113 /**
2114 * The length of the buffer pointed to by `path`.
2115 */
2116 size_t path_len,
2117
2118 /**
2119 * The desired values of the data access timestamp.
2120 */
2121 __wasi_timestamp_t atim,
2122
2123 /**
2124 * The desired values of the data modification timestamp.
2125 */
2126 __wasi_timestamp_t mtim,
2127
2128 /**
2129 * A bitmask indicating which timestamps to adjust.
2130 */
2131 __wasi_fstflags_t fst_flags
2132 ) __attribute__((
2133 __import_module__("wasi_snapshot_preview1"),
2134 __import_name__("path_filestat_set_times"),
2135 __warn_unused_result__
2136 ));
2137
2138 /**
2139 * Create a hard link.
2140 * Note: This is similar to `linkat` in POSIX.
2141 */
2142 __wasi_errno_t __wasi_path_link(
2143 __wasi_fd_t old_fd,
2144
2145 /**
2146 * Flags determining the method of how the path is resolved.
2147 */
2148 __wasi_lookupflags_t old_flags,
2149
2150 /**
2151 * The source path from which to link.
2152 */
2153 const char *old_path,
2154
2155 /**
2156 * The length of the buffer pointed to by `old_path`.
2157 */
2158 size_t old_path_len,
2159
2160 /**
2161 * The working directory at which the resolution of the new path starts.
2162 */
2163 __wasi_fd_t new_fd,
2164
2165 /**
2166 * The destination path at which to create the hard link.
2167 */
2168 const char *new_path,
2169
2170 /**
2171 * The length of the buffer pointed to by `new_path`.
2172 */
2173 size_t new_path_len
2174 ) __attribute__((
2175 __import_module__("wasi_snapshot_preview1"),
2176 __import_name__("path_link"),
2177 __warn_unused_result__
2178 ));
2179
2180 /**
2181 * Open a file or directory.
2182 * The returned file descriptor is not guaranteed to be the lowest-numbered
2183 * file descriptor not currently open; it is randomized to prevent
2184 * applications from depending on making assumptions about indexes, since this
2185 * is error-prone in multi-threaded contexts. The returned file descriptor is
2186 * guaranteed to be less than 2**31.
2187 * Note: This is similar to `openat` in POSIX.
2188 */
2189 __wasi_errno_t __wasi_path_open(
2190 __wasi_fd_t fd,
2191
2192 /**
2193 * Flags determining the method of how the path is resolved.
2194 */
2195 __wasi_lookupflags_t dirflags,
2196
2197 /**
2198 * The relative path of the file or directory to open, relative to the
2199 * `dirfd` directory.
2200 */
2201 const char *path,
2202
2203 /**
2204 * The length of the buffer pointed to by `path`.
2205 */
2206 size_t path_len,
2207
2208 /**
2209 * The method by which to open the file.
2210 */
2211 __wasi_oflags_t oflags,
2212
2213 /**
2214 * The initial rights of the newly created file descriptor. The
2215 * implementation is allowed to return a file descriptor with fewer rights
2216 * than specified, if and only if those rights do not apply to the type of
2217 * file being opened.
2218 * The *base* rights are rights that will apply to operations using the file
2219 * descriptor itself, while the *inheriting* rights are rights that apply to
2220 * file descriptors derived from it.
2221 */
2222 __wasi_rights_t fs_rights_base,
2223
2224 __wasi_rights_t fs_rights_inherting,
2225
2226 __wasi_fdflags_t fdflags,
2227
2228 /**
2229 * The file descriptor of the file that has been opened.
2230 */
2231 __wasi_fd_t *opened_fd
2232 ) __attribute__((
2233 __import_module__("wasi_snapshot_preview1"),
2234 __import_name__("path_open"),
2235 __warn_unused_result__
2236 ));
2237
2238 /**
2239 * Read the contents of a symbolic link.
2240 * Note: This is similar to `readlinkat` in POSIX.
2241 */
2242 __wasi_errno_t __wasi_path_readlink(
2243 __wasi_fd_t fd,
2244
2245 /**
2246 * The path of the symbolic link from which to read.
2247 */
2248 const char *path,
2249
2250 /**
2251 * The length of the buffer pointed to by `path`.
2252 */
2253 size_t path_len,
2254
2255 /**
2256 * The buffer to which to write the contents of the symbolic link.
2257 */
2258 uint8_t * buf,
2259
2260 __wasi_size_t buf_len,
2261
2262 /**
2263 * The number of bytes placed in the buffer.
2264 */
2265 __wasi_size_t *bufused
2266 ) __attribute__((
2267 __import_module__("wasi_snapshot_preview1"),
2268 __import_name__("path_readlink"),
2269 __warn_unused_result__
2270 ));
2271
2272 /**
2273 * Remove a directory.
2274 * Return `ENOTEMPTY` if the directory is not empty.
2275 * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
2276 */
2277 __wasi_errno_t __wasi_path_remove_directory(
2278 __wasi_fd_t fd,
2279
2280 /**
2281 * The path to a directory to remove.
2282 */
2283 const char *path,
2284
2285 /**
2286 * The length of the buffer pointed to by `path`.
2287 */
2288 size_t path_len
2289 ) __attribute__((
2290 __import_module__("wasi_snapshot_preview1"),
2291 __import_name__("path_remove_directory"),
2292 __warn_unused_result__
2293 ));
2294
2295 /**
2296 * Rename a file or directory.
2297 * Note: This is similar to `renameat` in POSIX.
2298 */
2299 __wasi_errno_t __wasi_path_rename(
2300 __wasi_fd_t fd,
2301
2302 /**
2303 * The source path of the file or directory to rename.
2304 */
2305 const char *old_path,
2306
2307 /**
2308 * The length of the buffer pointed to by `old_path`.
2309 */
2310 size_t old_path_len,
2311
2312 /**
2313 * The working directory at which the resolution of the new path starts.
2314 */
2315 __wasi_fd_t new_fd,
2316
2317 /**
2318 * The destination path to which to rename the file or directory.
2319 */
2320 const char *new_path,
2321
2322 /**
2323 * The length of the buffer pointed to by `new_path`.
2324 */
2325 size_t new_path_len
2326 ) __attribute__((
2327 __import_module__("wasi_snapshot_preview1"),
2328 __import_name__("path_rename"),
2329 __warn_unused_result__
2330 ));
2331
2332 /**
2333 * Create a symbolic link.
2334 * Note: This is similar to `symlinkat` in POSIX.
2335 */
2336 __wasi_errno_t __wasi_path_symlink(
2337 /**
2338 * The contents of the symbolic link.
2339 */
2340 const char *old_path,
2341
2342 /**
2343 * The length of the buffer pointed to by `old_path`.
2344 */
2345 size_t old_path_len,
2346
2347 __wasi_fd_t fd,
2348
2349 /**
2350 * The destination path at which to create the symbolic link.
2351 */
2352 const char *new_path,
2353
2354 /**
2355 * The length of the buffer pointed to by `new_path`.
2356 */
2357 size_t new_path_len
2358 ) __attribute__((
2359 __import_module__("wasi_snapshot_preview1"),
2360 __import_name__("path_symlink"),
2361 __warn_unused_result__
2362 ));
2363
2364 /**
2365 * Unlink a file.
2366 * Return `EISDIR` if the path refers to a directory.
2367 * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
2368 */
2369 __wasi_errno_t __wasi_path_unlink_file(
2370 __wasi_fd_t fd,
2371
2372 /**
2373 * The path to a file to unlink.
2374 */
2375 const char *path,
2376
2377 /**
2378 * The length of the buffer pointed to by `path`.
2379 */
2380 size_t path_len
2381 ) __attribute__((
2382 __import_module__("wasi_snapshot_preview1"),
2383 __import_name__("path_unlink_file"),
2384 __warn_unused_result__
2385 ));
2386
2387 /**
2388 * Concurrently poll for the occurrence of a set of events.
2389 */
2390 __wasi_errno_t __wasi_poll_oneoff(
2391 /**
2392 * The events to which to subscribe.
2393 */
2394 const __wasi_subscription_t * in,
2395
2396 /**
2397 * The events that have occurred.
2398 */
2399 __wasi_event_t * out,
2400
2401 /**
2402 * Both the number of subscriptions and events.
2403 */
2404 __wasi_size_t nsubscriptions,
2405
2406 /**
2407 * The number of events stored.
2408 */
2409 __wasi_size_t *nevents
2410 ) __attribute__((
2411 __import_module__("wasi_snapshot_preview1"),
2412 __import_name__("poll_oneoff"),
2413 __warn_unused_result__
2414 ));
2415
2416 /**
2417 * Terminate the process normally. An exit code of 0 indicates successful
2418 * termination of the program. The meanings of other values is dependent on
2419 * the environment.
2420 */
2421 _Noreturn void __wasi_proc_exit(
2422 /**
2423 * The exit code returned by the process.
2424 */
2425 __wasi_exitcode_t rval
2426 ) __attribute__((
2427 __import_module__("wasi_snapshot_preview1"),
2428 __import_name__("proc_exit")));
2429
2430 /**
2431 * Send a signal to the process of the calling thread.
2432 * Note: This is similar to `raise` in POSIX.
2433 */
2434 __wasi_errno_t __wasi_proc_raise(
2435 /**
2436 * The signal condition to trigger.
2437 */
2438 __wasi_signal_t sig
2439 ) __attribute__((
2440 __import_module__("wasi_snapshot_preview1"),
2441 __import_name__("proc_raise"),
2442 __warn_unused_result__
2443 ));
2444
2445 /**
2446 * Temporarily yield execution of the calling thread.
2447 * Note: This is similar to `sched_yield` in POSIX.
2448 */
2449 __wasi_errno_t __wasi_sched_yield(
2450 void
2451 ) __attribute__((
2452 __import_module__("wasi_snapshot_preview1"),
2453 __import_name__("sched_yield"),
2454 __warn_unused_result__
2455 ));
2456
2457 /**
2458 * Write high-quality random data into a buffer.
2459 * This function blocks when the implementation is unable to immediately
2460 * provide sufficient high-quality random data.
2461 * This function may execute slowly, so when large mounts of random data are
2462 * required, it's advisable to use this function to seed a pseudo-random
2463 * number generator, rather than to provide the random data directly.
2464 */
2465 __wasi_errno_t __wasi_random_get(
2466 /**
2467 * The buffer to fill with random data.
2468 */
2469 uint8_t * buf,
2470
2471 __wasi_size_t buf_len
2472 ) __attribute__((
2473 __import_module__("wasi_snapshot_preview1"),
2474 __import_name__("random_get"),
2475 __warn_unused_result__
2476 ));
2477
2478 /**
2479 * Receive a message from a socket.
2480 * Note: This is similar to `recv` in POSIX, though it also supports reading
2481 * the data into multiple buffers in the manner of `readv`.
2482 */
2483 __wasi_errno_t __wasi_sock_recv(
2484 __wasi_fd_t fd,
2485
2486 /**
2487 * List of scatter/gather vectors to which to store data.
2488 */
2489 const __wasi_iovec_t *ri_data,
2490
2491 /**
2492 * The length of the array pointed to by `ri_data`.
2493 */
2494 size_t ri_data_len,
2495
2496 /**
2497 * Message flags.
2498 */
2499 __wasi_riflags_t ri_flags,
2500
2501 /**
2502 * Number of bytes stored in ri_data.
2503 */
2504 __wasi_size_t *ro_datalen,
2505 /**
2506 * Message flags.
2507 */
2508 __wasi_roflags_t *ro_flags
2509 ) __attribute__((
2510 __import_module__("wasi_snapshot_preview1"),
2511 __import_name__("sock_recv"),
2512 __warn_unused_result__
2513 ));
2514
2515 /**
2516 * Send a message on a socket.
2517 * Note: This is similar to `send` in POSIX, though it also supports writing
2518 * the data from multiple buffers in the manner of `writev`.
2519 */
2520 __wasi_errno_t __wasi_sock_send(
2521 __wasi_fd_t fd,
2522
2523 /**
2524 * List of scatter/gather vectors to which to retrieve data
2525 */
2526 const __wasi_ciovec_t *si_data,
2527
2528 /**
2529 * The length of the array pointed to by `si_data`.
2530 */
2531 size_t si_data_len,
2532
2533 /**
2534 * Message flags.
2535 */
2536 __wasi_siflags_t si_flags,
2537
2538 /**
2539 * Number of bytes transmitted.
2540 */
2541 __wasi_size_t *so_datalen
2542 ) __attribute__((
2543 __import_module__("wasi_snapshot_preview1"),
2544 __import_name__("sock_send"),
2545 __warn_unused_result__
2546 ));
2547
2548 /**
2549 * Shut down socket send and receive channels.
2550 * Note: This is similar to `shutdown` in POSIX.
2551 */
2552 __wasi_errno_t __wasi_sock_shutdown(
2553 __wasi_fd_t fd,
2554
2555 /**
2556 * Which channels on the socket to shut down.
2557 */
2558 __wasi_sdflags_t how
2559 ) __attribute__((
2560 __import_module__("wasi_snapshot_preview1"),
2561 __import_name__("sock_shutdown"),
2562 __warn_unused_result__
2563 ));
2564
2565 /** @} */
2566
2567 #ifdef __cplusplus
2568 }
2569 #endif
2570
2571 #endif