master
1#ifndef __wasi_libc_h
2#define __wasi_libc_h
3
4#include <__typedef_off_t.h>
5#include <__struct_timespec.h>
6#include <unistd.h>
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12struct stat;
13struct timespec;
14
15/// Populate libc's preopen tables. This is normally done automatically
16/// just before it's needed, however if you call `__wasi_fd_renumber` or
17/// `__wasi_fd_close` directly, and you need the preopens to be accurate
18/// afterward, you should call this before doing so.
19void __wasilibc_populate_preopens(void);
20
21/// Register the given pre-opened file descriptor under the given path.
22///
23/// This function does not take ownership of `prefix` (it makes its own copy).
24int __wasilibc_register_preopened_fd(int fd, const char *prefix);
25
26/// Renumber `fd` to `newfd`; similar to `dup2` but does a move rather than a
27/// copy.
28int __wasilibc_fd_renumber(int fd, int newfd)
29 __attribute__((__warn_unused_result__));
30
31/// Like `unlinkat`, but without depending on `__wasi_path_remove_directory`.
32int __wasilibc_unlinkat(int fd, const char *path)
33 __attribute__((__warn_unused_result__));
34
35/// An `*at` version of rmdir.
36int __wasilibc_rmdirat(int fd, const char *path)
37 __attribute__((__warn_unused_result__));
38
39/// Like `open`, but without the varargs in the signature.
40int __wasilibc_open_nomode(const char *path, int oflag);
41
42/// Like `openat`, but without the varargs in the signature.
43int __wasilibc_openat_nomode(int fd, const char *path, int oflag);
44
45/// Return the current file offset. Like `lseek(fd, 0, SEEK_CUR)`, but without
46/// depending on `lseek`.
47off_t __wasilibc_tell(int fd)
48 __attribute__((__warn_unused_result__));
49
50/* Non-`at` forms of various `*at` functions. */
51int __wasilibc_access(const char *pathname, int mode, int flags)
52 __attribute__((__warn_unused_result__));
53int __wasilibc_stat(const char *__restrict pathname, struct stat *__restrict statbuf, int flags)
54 __attribute__((__warn_unused_result__));
55int __wasilibc_utimens(const char *pathname, const struct timespec times[2], int flags)
56 __attribute__((__warn_unused_result__));
57int __wasilibc_link(const char *oldpath, const char *newpath, int flags)
58 __attribute__((__warn_unused_result__));
59int __wasilibc_link_oldat(int olddirfd, const char *oldpath, const char *newpath, int flags)
60 __attribute__((__warn_unused_result__));
61int __wasilibc_link_newat(const char *oldpath, int newdirfd, const char *newpath, int flags)
62 __attribute__((__warn_unused_result__));
63int __wasilibc_rename_oldat(int olddirfd, const char *oldpath, const char *newpath)
64 __attribute__((__warn_unused_result__));
65int __wasilibc_rename_newat(const char *oldpath, int newdirfd, const char *newpath)
66 __attribute__((__warn_unused_result__));
67
68/// Enable busywait in futex on current thread.
69void __wasilibc_enable_futex_busywait_on_current_thread(void);
70
71/// Fill a buffer with random bytes
72int __wasilibc_random(void* buffer, size_t len)
73 __attribute__((__warn_unused_result__));
74
75#ifdef __cplusplus
76}
77#endif
78
79#endif