Debian Codegraph @

third_party/rust/libc/src/wasi/mod.rs

raw
1 //! [wasi-libc](https://github.com/WebAssembly/wasi-libc) definitions.
2 //!
3 //! `wasi-libc` project provides multiple libraries including emulated features, but we list only
4 //! basic features with `libc.a` here.
5
6 use core::iter::Iterator;
7
8 use crate::prelude::*;
9
10 pub type intmax_t = i64;
11 pub type uintmax_t = u64;
12 pub type size_t = usize;
13 pub type ssize_t = isize;
14 pub type ptrdiff_t = isize;
15 pub type intptr_t = isize;
16 pub type uintptr_t = usize;
17 pub type off_t = i64;
18 pub type pid_t = i32;
19 pub type clock_t = c_longlong;
20 pub type time_t = c_longlong;
21 pub type ino_t = u64;
22 pub type sigset_t = c_uchar;
23 pub type suseconds_t = c_longlong;
24 pub type mode_t = u32;
25 pub type dev_t = u64;
26 pub type uid_t = u32;
27 pub type gid_t = u32;
28 pub type nlink_t = u64;
29 pub type blksize_t = c_long;
30 pub type blkcnt_t = i64;
31 pub type nfds_t = c_ulong;
32 pub type wchar_t = i32;
33 pub type nl_item = c_int;
34 pub type __wasi_rights_t = u64;
35 pub type locale_t = *mut __locale_struct;
36
37 s_no_extra_traits! {
38 #[repr(align(16))]
39 #[allow(missing_debug_implementations)]
40 pub struct max_align_t {
41 priv_: [f64; 4],
42 }
43 }
44
45 #[allow(missing_copy_implementations)]
46 #[cfg_attr(feature = "extra_traits", derive(Debug))]
47 pub enum FILE {}
48 #[allow(missing_copy_implementations)]
49 #[cfg_attr(feature = "extra_traits", derive(Debug))]
50 pub enum DIR {}
51 #[allow(missing_copy_implementations)]
52 #[cfg_attr(feature = "extra_traits", derive(Debug))]
53 pub enum __locale_struct {}
54
55 s_paren! {
56 // in wasi-libc clockid_t is const struct __clockid* (where __clockid is an opaque struct),
57 // but that's an implementation detail that we don't want to have to deal with
58 #[repr(transparent)]
59 #[allow(dead_code)]
60 pub struct clockid_t(*const u8);
61 }
62
63 unsafe impl Send for clockid_t {}
64 unsafe impl Sync for clockid_t {}
65
66 s! {
67 #[repr(align(8))]
68 pub struct fpos_t {
69 data: [u8; 16],
70 }
71
72 pub struct tm {
73 pub tm_sec: c_int,
74 pub tm_min: c_int,
75 pub tm_hour: c_int,
76 pub tm_mday: c_int,
77 pub tm_mon: c_int,
78 pub tm_year: c_int,
79 pub tm_wday: c_int,
80 pub tm_yday: c_int,
81 pub tm_isdst: c_int,
82 pub __tm_gmtoff: c_int,
83 pub __tm_zone: *const c_char,
84 pub __tm_nsec: c_int,
85 }
86
87 pub struct timeval {
88 pub tv_sec: time_t,
89 pub tv_usec: suseconds_t,
90 }
91
92 pub struct timespec {
93 pub tv_sec: time_t,
94 pub tv_nsec: c_long,
95 }
96
97 pub struct tms {
98 pub tms_utime: clock_t,
99 pub tms_stime: clock_t,
100 pub tms_cutime: clock_t,
101 pub tms_cstime: clock_t,
102 }
103
104 pub struct itimerspec {
105 pub it_interval: timespec,
106 pub it_value: timespec,
107 }
108
109 pub struct iovec {
110 pub iov_base: *mut c_void,
111 pub iov_len: size_t,
112 }
113
114 pub struct lconv {
115 pub decimal_point: *mut c_char,
116 pub thousands_sep: *mut c_char,
117 pub grouping: *mut c_char,
118 pub int_curr_symbol: *mut c_char,
119 pub currency_symbol: *mut c_char,
120 pub mon_decimal_point: *mut c_char,
121 pub mon_thousands_sep: *mut c_char,
122 pub mon_grouping: *mut c_char,
123 pub positive_sign: *mut c_char,
124 pub negative_sign: *mut c_char,
125 pub int_frac_digits: c_char,
126 pub frac_digits: c_char,
127 pub p_cs_precedes: c_char,
128 pub p_sep_by_space: c_char,
129 pub n_cs_precedes: c_char,
130 pub n_sep_by_space: c_char,
131 pub p_sign_posn: c_char,
132 pub n_sign_posn: c_char,
133 pub int_p_cs_precedes: c_char,
134 pub int_p_sep_by_space: c_char,
135 pub int_n_cs_precedes: c_char,
136 pub int_n_sep_by_space: c_char,
137 pub int_p_sign_posn: c_char,
138 pub int_n_sign_posn: c_char,
139 }
140
141 pub struct pollfd {
142 pub fd: c_int,
143 pub events: c_short,
144 pub revents: c_short,
145 }
146
147 pub struct rusage {
148 pub ru_utime: timeval,
149 pub ru_stime: timeval,
150 }
151
152 pub struct stat {
153 pub st_dev: dev_t,
154 pub st_ino: ino_t,
155 pub st_nlink: nlink_t,
156 pub st_mode: mode_t,
157 pub st_uid: uid_t,
158 pub st_gid: gid_t,
159 __pad0: c_uint,
160 pub st_rdev: dev_t,
161 pub st_size: off_t,
162 pub st_blksize: blksize_t,
163 pub st_blocks: blkcnt_t,
164 pub st_atim: timespec,
165 pub st_mtim: timespec,
166 pub st_ctim: timespec,
167 __reserved: [c_longlong; 3],
168 }
169
170 pub struct fd_set {
171 __nfds: usize,
172 __fds: [c_int; FD_SETSIZE as usize],
173 }
174 }
175
176 // Declare dirent outside of s! so that it doesn't implement Copy, Eq, Hash,
177 // etc., since it contains a flexible array member with a dynamic size.
178 #[repr(C)]
179 #[allow(missing_copy_implementations)]
180 #[cfg_attr(feature = "extra_traits", derive(Debug))]
181 pub struct dirent {
182 pub d_ino: ino_t,
183 pub d_type: c_uchar,
184 /// d_name is declared in WASI libc as a flexible array member, which
185 /// can't be directly expressed in Rust. As an imperfect workaround,
186 /// declare it as a zero-length array instead.
187 pub d_name: [c_char; 0],
188 }
189
190 pub const EXIT_SUCCESS: c_int = 0;
191 pub const EXIT_FAILURE: c_int = 1;
192 pub const STDIN_FILENO: c_int = 0;
193 pub const STDOUT_FILENO: c_int = 1;
194 pub const STDERR_FILENO: c_int = 2;
195 pub const SEEK_SET: c_int = 0;
196 pub const SEEK_CUR: c_int = 1;
197 pub const SEEK_END: c_int = 2;
198 pub const _IOFBF: c_int = 0;
199 pub const _IONBF: c_int = 2;
200 pub const _IOLBF: c_int = 1;
201 pub const F_GETFD: c_int = 1;
202 pub const F_SETFD: c_int = 2;
203 pub const F_GETFL: c_int = 3;
204 pub const F_SETFL: c_int = 4;
205 pub const FD_CLOEXEC: c_int = 1;
206 pub const FD_SETSIZE: size_t = 1024;
207 pub const O_APPEND: c_int = 0x0001;
208 pub const O_DSYNC: c_int = 0x0002;
209 pub const O_NONBLOCK: c_int = 0x0004;
210 pub const O_RSYNC: c_int = 0x0008;
211 pub const O_SYNC: c_int = 0x0010;
212 pub const O_CREAT: c_int = 0x0001 << 12;
213 pub const O_DIRECTORY: c_int = 0x0002 << 12;
214 pub const O_EXCL: c_int = 0x0004 << 12;
215 pub const O_TRUNC: c_int = 0x0008 << 12;
216 pub const O_NOFOLLOW: c_int = 0x01000000;
217 pub const O_EXEC: c_int = 0x02000000;
218 pub const O_RDONLY: c_int = 0x04000000;
219 pub const O_SEARCH: c_int = 0x08000000;
220 pub const O_WRONLY: c_int = 0x10000000;
221 pub const O_CLOEXEC: c_int = 0x0;
222 pub const O_RDWR: c_int = O_WRONLY | O_RDONLY;
223 pub const O_ACCMODE: c_int = O_EXEC | O_RDWR | O_SEARCH;
224 pub const O_NOCTTY: c_int = 0x0;
225 pub const POSIX_FADV_DONTNEED: c_int = 4;
226 pub const POSIX_FADV_NOREUSE: c_int = 5;
227 pub const POSIX_FADV_NORMAL: c_int = 0;
228 pub const POSIX_FADV_RANDOM: c_int = 2;
229 pub const POSIX_FADV_SEQUENTIAL: c_int = 1;
230 pub const POSIX_FADV_WILLNEED: c_int = 3;
231 pub const AT_FDCWD: c_int = -2;
232 pub const AT_EACCESS: c_int = 0x0;
233 pub const AT_SYMLINK_NOFOLLOW: c_int = 0x1;
234 pub const AT_SYMLINK_FOLLOW: c_int = 0x2;
235 pub const AT_REMOVEDIR: c_int = 0x4;
236 pub const UTIME_OMIT: c_long = 0xfffffffe;
237 pub const UTIME_NOW: c_long = 0xffffffff;
238 pub const S_IFIFO: mode_t = 0o1_0000;
239 pub const S_IFCHR: mode_t = 0o2_0000;
240 pub const S_IFBLK: mode_t = 0o6_0000;
241 pub const S_IFDIR: mode_t = 0o4_0000;
242 pub const S_IFREG: mode_t = 0o10_0000;
243 pub const S_IFLNK: mode_t = 0o12_0000;
244 pub const S_IFSOCK: mode_t = 0o14_0000;
245 pub const S_IFMT: mode_t = 0o17_0000;
246 pub const S_IRWXO: mode_t = 0o0007;
247 pub const S_IXOTH: mode_t = 0o0001;
248 pub const S_IWOTH: mode_t = 0o0002;
249 pub const S_IROTH: mode_t = 0o0004;
250 pub const S_IRWXG: mode_t = 0o0070;
251 pub const S_IXGRP: mode_t = 0o0010;
252 pub const S_IWGRP: mode_t = 0o0020;
253 pub const S_IRGRP: mode_t = 0o0040;
254 pub const S_IRWXU: mode_t = 0o0700;
255 pub const S_IXUSR: mode_t = 0o0100;
256 pub const S_IWUSR: mode_t = 0o0200;
257 pub const S_IRUSR: mode_t = 0o0400;
258 pub const S_ISVTX: mode_t = 0o1000;
259 pub const S_ISGID: mode_t = 0o2000;
260 pub const S_ISUID: mode_t = 0o4000;
261 pub const DT_UNKNOWN: u8 = 0;
262 pub const DT_BLK: u8 = 1;
263 pub const DT_CHR: u8 = 2;
264 pub const DT_DIR: u8 = 3;
265 pub const DT_REG: u8 = 4;
266 pub const DT_LNK: u8 = 7;
267 pub const FIONREAD: c_int = 1;
268 pub const FIONBIO: c_int = 2;
269 pub const F_OK: c_int = 0;
270 pub const R_OK: c_int = 4;
271 pub const W_OK: c_int = 2;
272 pub const X_OK: c_int = 1;
273 pub const POLLIN: c_short = 0x1;
274 pub const POLLOUT: c_short = 0x2;
275 pub const POLLERR: c_short = 0x1000;
276 pub const POLLHUP: c_short = 0x2000;
277 pub const POLLNVAL: c_short = 0x4000;
278 pub const POLLRDNORM: c_short = 0x1;
279 pub const POLLWRNORM: c_short = 0x2;
280
281 pub const E2BIG: c_int = 1;
282 pub const EACCES: c_int = 2;
283 pub const EADDRINUSE: c_int = 3;
284 pub const EADDRNOTAVAIL: c_int = 4;
285 pub const EAFNOSUPPORT: c_int = 5;
286 pub const EAGAIN: c_int = 6;
287 pub const EALREADY: c_int = 7;
288 pub const EBADF: c_int = 8;
289 pub const EBADMSG: c_int = 9;
290 pub const EBUSY: c_int = 10;
291 pub const ECANCELED: c_int = 11;
292 pub const ECHILD: c_int = 12;
293 pub const ECONNABORTED: c_int = 13;
294 pub const ECONNREFUSED: c_int = 14;
295 pub const ECONNRESET: c_int = 15;
296 pub const EDEADLK: c_int = 16;
297 pub const EDESTADDRREQ: c_int = 17;
298 pub const EDOM: c_int = 18;
299 pub const EDQUOT: c_int = 19;
300 pub const EEXIST: c_int = 20;
301 pub const EFAULT: c_int = 21;
302 pub const EFBIG: c_int = 22;
303 pub const EHOSTUNREACH: c_int = 23;
304 pub const EIDRM: c_int = 24;
305 pub const EILSEQ: c_int = 25;
306 pub const EINPROGRESS: c_int = 26;
307 pub const EINTR: c_int = 27;
308 pub const EINVAL: c_int = 28;
309 pub const EIO: c_int = 29;
310 pub const EISCONN: c_int = 30;
311 pub const EISDIR: c_int = 31;
312 pub const ELOOP: c_int = 32;
313 pub const EMFILE: c_int = 33;
314 pub const EMLINK: c_int = 34;
315 pub const EMSGSIZE: c_int = 35;
316 pub const EMULTIHOP: c_int = 36;
317 pub const ENAMETOOLONG: c_int = 37;
318 pub const ENETDOWN: c_int = 38;
319 pub const ENETRESET: c_int = 39;
320 pub const ENETUNREACH: c_int = 40;
321 pub const ENFILE: c_int = 41;
322 pub const ENOBUFS: c_int = 42;
323 pub const ENODEV: c_int = 43;
324 pub const ENOENT: c_int = 44;
325 pub const ENOEXEC: c_int = 45;
326 pub const ENOLCK: c_int = 46;
327 pub const ENOLINK: c_int = 47;
328 pub const ENOMEM: c_int = 48;
329 pub const ENOMSG: c_int = 49;
330 pub const ENOPROTOOPT: c_int = 50;
331 pub const ENOSPC: c_int = 51;
332 pub const ENOSYS: c_int = 52;
333 pub const ENOTCONN: c_int = 53;
334 pub const ENOTDIR: c_int = 54;
335 pub const ENOTEMPTY: c_int = 55;
336 pub const ENOTRECOVERABLE: c_int = 56;
337 pub const ENOTSOCK: c_int = 57;
338 pub const ENOTSUP: c_int = 58;
339 pub const ENOTTY: c_int = 59;
340 pub const ENXIO: c_int = 60;
341 pub const EOVERFLOW: c_int = 61;
342 pub const EOWNERDEAD: c_int = 62;
343 pub const EPERM: c_int = 63;
344 pub const EPIPE: c_int = 64;
345 pub const EPROTO: c_int = 65;
346 pub const EPROTONOSUPPORT: c_int = 66;
347 pub const EPROTOTYPE: c_int = 67;
348 pub const ERANGE: c_int = 68;
349 pub const EROFS: c_int = 69;
350 pub const ESPIPE: c_int = 70;
351 pub const ESRCH: c_int = 71;
352 pub const ESTALE: c_int = 72;
353 pub const ETIMEDOUT: c_int = 73;
354 pub const ETXTBSY: c_int = 74;
355 pub const EXDEV: c_int = 75;
356 pub const ENOTCAPABLE: c_int = 76;
357 pub const EOPNOTSUPP: c_int = ENOTSUP;
358 pub const EWOULDBLOCK: c_int = EAGAIN;
359
360 pub const _SC_PAGESIZE: c_int = 30;
361 pub const _SC_PAGE_SIZE: c_int = _SC_PAGESIZE;
362 pub const _SC_IOV_MAX: c_int = 60;
363 pub const _SC_SYMLOOP_MAX: c_int = 173;
364
365 cfg_if! {
366 if #[cfg(libc_ctest)] {
367 // skip these constants when this is active because `ctest` currently
368 // panics on parsing the constants below
369 } else {
370 // `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82
371 #[allow(unused_unsafe)]
372 pub static CLOCK_MONOTONIC: clockid_t =
373 unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_MONOTONIC)) };
374 #[allow(unused_unsafe)]
375 pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t =
376 unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) };
377 #[allow(unused_unsafe)]
378 pub static CLOCK_REALTIME: clockid_t =
379 unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_REALTIME)) };
380 #[allow(unused_unsafe)]
381 pub static CLOCK_THREAD_CPUTIME_ID: clockid_t =
382 unsafe { clockid_t(core::ptr::addr_of!(_CLOCK_THREAD_CPUTIME_ID)) };
383 }
384 }
385
386 pub const ABDAY_1: crate::nl_item = 0x20000;
387 pub const ABDAY_2: crate::nl_item = 0x20001;
388 pub const ABDAY_3: crate::nl_item = 0x20002;
389 pub const ABDAY_4: crate::nl_item = 0x20003;
390 pub const ABDAY_5: crate::nl_item = 0x20004;
391 pub const ABDAY_6: crate::nl_item = 0x20005;
392 pub const ABDAY_7: crate::nl_item = 0x20006;
393
394 pub const DAY_1: crate::nl_item = 0x20007;
395 pub const DAY_2: crate::nl_item = 0x20008;
396 pub const DAY_3: crate::nl_item = 0x20009;
397 pub const DAY_4: crate::nl_item = 0x2000A;
398 pub const DAY_5: crate::nl_item = 0x2000B;
399 pub const DAY_6: crate::nl_item = 0x2000C;
400 pub const DAY_7: crate::nl_item = 0x2000D;
401
402 pub const ABMON_1: crate::nl_item = 0x2000E;
403 pub const ABMON_2: crate::nl_item = 0x2000F;
404 pub const ABMON_3: crate::nl_item = 0x20010;
405 pub const ABMON_4: crate::nl_item = 0x20011;
406 pub const ABMON_5: crate::nl_item = 0x20012;
407 pub const ABMON_6: crate::nl_item = 0x20013;
408 pub const ABMON_7: crate::nl_item = 0x20014;
409 pub const ABMON_8: crate::nl_item = 0x20015;
410 pub const ABMON_9: crate::nl_item = 0x20016;
411 pub const ABMON_10: crate::nl_item = 0x20017;
412 pub const ABMON_11: crate::nl_item = 0x20018;
413 pub const ABMON_12: crate::nl_item = 0x20019;
414
415 pub const MON_1: crate::nl_item = 0x2001A;
416 pub const MON_2: crate::nl_item = 0x2001B;
417 pub const MON_3: crate::nl_item = 0x2001C;
418 pub const MON_4: crate::nl_item = 0x2001D;
419 pub const MON_5: crate::nl_item = 0x2001E;
420 pub const MON_6: crate::nl_item = 0x2001F;
421 pub const MON_7: crate::nl_item = 0x20020;
422 pub const MON_8: crate::nl_item = 0x20021;
423 pub const MON_9: crate::nl_item = 0x20022;
424 pub const MON_10: crate::nl_item = 0x20023;
425 pub const MON_11: crate::nl_item = 0x20024;
426 pub const MON_12: crate::nl_item = 0x20025;
427
428 pub const AM_STR: crate::nl_item = 0x20026;
429 pub const PM_STR: crate::nl_item = 0x20027;
430
431 pub const D_T_FMT: crate::nl_item = 0x20028;
432 pub const D_FMT: crate::nl_item = 0x20029;
433 pub const T_FMT: crate::nl_item = 0x2002A;
434 pub const T_FMT_AMPM: crate::nl_item = 0x2002B;
435
436 pub const ERA: crate::nl_item = 0x2002C;
437 pub const ERA_D_FMT: crate::nl_item = 0x2002E;
438 pub const ALT_DIGITS: crate::nl_item = 0x2002F;
439 pub const ERA_D_T_FMT: crate::nl_item = 0x20030;
440 pub const ERA_T_FMT: crate::nl_item = 0x20031;
441
442 pub const CODESET: crate::nl_item = 14;
443 pub const CRNCYSTR: crate::nl_item = 0x4000F;
444 pub const RADIXCHAR: crate::nl_item = 0x10000;
445 pub const THOUSEP: crate::nl_item = 0x10001;
446 pub const YESEXPR: crate::nl_item = 0x50000;
447 pub const NOEXPR: crate::nl_item = 0x50001;
448 pub const YESSTR: crate::nl_item = 0x50002;
449 pub const NOSTR: crate::nl_item = 0x50003;
450
451 f! {
452 pub fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
453 let set = &*set;
454 let n = set.__nfds;
455 return set.__fds[..n].iter().any(|p| *p == fd);
456 }
457
458 pub fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
459 let set = &mut *set;
460 let n = set.__nfds;
461 if !set.__fds[..n].iter().any(|p| *p == fd) {
462 set.__nfds = n + 1;
463 set.__fds[n] = fd;
464 }
465 }
466
467 pub fn FD_ZERO(set: *mut fd_set) -> () {
468 (*set).__nfds = 0;
469 return;
470 }
471 }
472
473 #[cfg_attr(
474 feature = "rustc-dep-of-std",
475 link(
476 name = "c",
477 kind = "static",
478 modifiers = "-bundle",
479 cfg(target_feature = "crt-static")
480 )
481 )]
482 #[cfg_attr(
483 feature = "rustc-dep-of-std",
484 link(name = "c", cfg(not(target_feature = "crt-static")))
485 )]
486 extern "C" {
487 pub fn _Exit(code: c_int) -> !;
488 pub fn _exit(code: c_int) -> !;
489 pub fn abort() -> !;
490 pub fn aligned_alloc(a: size_t, b: size_t) -> *mut c_void;
491 pub fn calloc(amt: size_t, amt2: size_t) -> *mut c_void;
492 pub fn exit(code: c_int) -> !;
493 pub fn free(ptr: *mut c_void);
494 pub fn getenv(s: *const c_char) -> *mut c_char;
495 pub fn malloc(amt: size_t) -> *mut c_void;
496 pub fn malloc_usable_size(ptr: *mut c_void) -> size_t;
497 pub fn sbrk(increment: intptr_t) -> *mut c_void;
498 pub fn rand() -> c_int;
499 pub fn read(fd: c_int, ptr: *mut c_void, size: size_t) -> ssize_t;
500 pub fn realloc(ptr: *mut c_void, amt: size_t) -> *mut c_void;
501 pub fn setenv(k: *const c_char, v: *const c_char, a: c_int) -> c_int;
502 pub fn unsetenv(k: *const c_char) -> c_int;
503 pub fn clearenv() -> c_int;
504 pub fn write(fd: c_int, ptr: *const c_void, size: size_t) -> ssize_t;
505 pub static mut environ: *mut *mut c_char;
506 pub fn fopen(a: *const c_char, b: *const c_char) -> *mut FILE;
507 pub fn freopen(a: *const c_char, b: *const c_char, f: *mut FILE) -> *mut FILE;
508 pub fn fclose(f: *mut FILE) -> c_int;
509 pub fn remove(a: *const c_char) -> c_int;
510 pub fn rename(a: *const c_char, b: *const c_char) -> c_int;
511 pub fn feof(f: *mut FILE) -> c_int;
512 pub fn ferror(f: *mut FILE) -> c_int;
513 pub fn fflush(f: *mut FILE) -> c_int;
514 pub fn clearerr(f: *mut FILE);
515 pub fn fseek(f: *mut FILE, b: c_long, c: c_int) -> c_int;
516 pub fn ftell(f: *mut FILE) -> c_long;
517 pub fn rewind(f: *mut FILE);
518 pub fn fgetpos(f: *mut FILE, pos: *mut fpos_t) -> c_int;
519 pub fn fsetpos(f: *mut FILE, pos: *const fpos_t) -> c_int;
520 pub fn fread(buf: *mut c_void, a: size_t, b: size_t, f: *mut FILE) -> size_t;
521 pub fn fwrite(buf: *const c_void, a: size_t, b: size_t, f: *mut FILE) -> size_t;
522 pub fn fgetc(f: *mut FILE) -> c_int;
523 pub fn getc(f: *mut FILE) -> c_int;
524 pub fn getchar() -> c_int;
525 pub fn ungetc(a: c_int, f: *mut FILE) -> c_int;
526 pub fn fputc(a: c_int, f: *mut FILE) -> c_int;
527 pub fn putc(a: c_int, f: *mut FILE) -> c_int;
528 pub fn putchar(a: c_int) -> c_int;
529 pub fn fputs(a: *const c_char, f: *mut FILE) -> c_int;
530 pub fn puts(a: *const c_char) -> c_int;
531 pub fn perror(a: *const c_char);
532 pub fn srand(a: c_uint);
533 pub fn atexit(a: extern "C" fn()) -> c_int;
534 pub fn at_quick_exit(a: extern "C" fn()) -> c_int;
535 pub fn quick_exit(a: c_int) -> !;
536 pub fn posix_memalign(a: *mut *mut c_void, b: size_t, c: size_t) -> c_int;
537 pub fn rand_r(a: *mut c_uint) -> c_int;
538 pub fn random() -> c_long;
539 pub fn srandom(a: c_uint);
540 pub fn putenv(a: *mut c_char) -> c_int;
541 pub fn clock() -> clock_t;
542 pub fn time(a: *mut time_t) -> time_t;
543 pub fn difftime(a: time_t, b: time_t) -> c_double;
544 pub fn mktime(a: *mut tm) -> time_t;
545 pub fn strftime(a: *mut c_char, b: size_t, c: *const c_char, d: *const tm) -> size_t;
546 pub fn gmtime(a: *const time_t) -> *mut tm;
547 pub fn gmtime_r(a: *const time_t, b: *mut tm) -> *mut tm;
548 pub fn localtime(a: *const time_t) -> *mut tm;
549 pub fn localtime_r(a: *const time_t, b: *mut tm) -> *mut tm;
550 pub fn asctime_r(a: *const tm, b: *mut c_char) -> *mut c_char;
551 pub fn ctime_r(a: *const time_t, b: *mut c_char) -> *mut c_char;
552
553 static _CLOCK_MONOTONIC: u8;
554 static _CLOCK_PROCESS_CPUTIME_ID: u8;
555 static _CLOCK_REALTIME: u8;
556 static _CLOCK_THREAD_CPUTIME_ID: u8;
557 pub fn nanosleep(a: *const timespec, b: *mut timespec) -> c_int;
558 pub fn clock_getres(a: clockid_t, b: *mut timespec) -> c_int;
559 pub fn clock_gettime(a: clockid_t, b: *mut timespec) -> c_int;
560 pub fn clock_nanosleep(a: clockid_t, a2: c_int, b: *const timespec, c: *mut timespec) -> c_int;
561
562 pub fn isalnum(c: c_int) -> c_int;
563 pub fn isalpha(c: c_int) -> c_int;
564 pub fn iscntrl(c: c_int) -> c_int;
565 pub fn isdigit(c: c_int) -> c_int;
566 pub fn isgraph(c: c_int) -> c_int;
567 pub fn islower(c: c_int) -> c_int;
568 pub fn isprint(c: c_int) -> c_int;
569 pub fn ispunct(c: c_int) -> c_int;
570 pub fn isspace(c: c_int) -> c_int;
571 pub fn isupper(c: c_int) -> c_int;
572 pub fn isxdigit(c: c_int) -> c_int;
573 pub fn isblank(c: c_int) -> c_int;
574 pub fn tolower(c: c_int) -> c_int;
575 pub fn toupper(c: c_int) -> c_int;
576 pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, size: size_t) -> c_int;
577 pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
578 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
579 pub fn atof(s: *const c_char) -> c_double;
580 pub fn atoi(s: *const c_char) -> c_int;
581 pub fn atol(s: *const c_char) -> c_long;
582 pub fn atoll(s: *const c_char) -> c_longlong;
583 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
584 pub fn strtof(s: *const c_char, endp: *mut *mut c_char) -> c_float;
585 pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long;
586 pub fn strtoll(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_longlong;
587 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong;
588 pub fn strtoull(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulonglong;
589
590 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
591 pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
592 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
593 pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
594 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
595 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
596 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
597 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
598 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
599 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
600 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
601 pub fn strdup(cs: *const c_char) -> *mut c_char;
602 pub fn strndup(cs: *const c_char, n: size_t) -> *mut c_char;
603 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
604 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
605 pub fn strcasecmp(s1: *const c_char, s2: *const c_char) -> c_int;
606 pub fn strncasecmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int;
607 pub fn strlen(cs: *const c_char) -> size_t;
608 pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
609 pub fn strerror(n: c_int) -> *mut c_char;
610 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
611 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
612
613 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
614 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
615 pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
616 pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
617 pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
618
619 pub fn fprintf(stream: *mut crate::FILE, format: *const c_char, ...) -> c_int;
620 pub fn printf(format: *const c_char, ...) -> c_int;
621 pub fn snprintf(s: *mut c_char, n: size_t, format: *const c_char, ...) -> c_int;
622 pub fn sprintf(s: *mut c_char, format: *const c_char, ...) -> c_int;
623 pub fn fscanf(stream: *mut crate::FILE, format: *const c_char, ...) -> c_int;
624 pub fn scanf(format: *const c_char, ...) -> c_int;
625 pub fn sscanf(s: *const c_char, format: *const c_char, ...) -> c_int;
626 pub fn getchar_unlocked() -> c_int;
627 pub fn putchar_unlocked(c: c_int) -> c_int;
628
629 pub fn shutdown(socket: c_int, how: c_int) -> c_int;
630 pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
631 pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int;
632 pub fn stat(path: *const c_char, buf: *mut stat) -> c_int;
633 pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut crate::FILE;
634 pub fn fileno(stream: *mut crate::FILE) -> c_int;
635 pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int;
636 pub fn creat(path: *const c_char, mode: mode_t) -> c_int;
637 pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;
638 pub fn opendir(dirname: *const c_char) -> *mut crate::DIR;
639 pub fn fdopendir(fd: c_int) -> *mut crate::DIR;
640 pub fn readdir(dirp: *mut crate::DIR) -> *mut crate::dirent;
641 pub fn closedir(dirp: *mut crate::DIR) -> c_int;
642 pub fn rewinddir(dirp: *mut crate::DIR);
643 pub fn dirfd(dirp: *mut crate::DIR) -> c_int;
644 pub fn seekdir(dirp: *mut crate::DIR, loc: c_long);
645 pub fn telldir(dirp: *mut crate::DIR) -> c_long;
646
647 pub fn openat(dirfd: c_int, pathname: *const c_char, flags: c_int, ...) -> c_int;
648 pub fn fstatat(dirfd: c_int, pathname: *const c_char, buf: *mut stat, flags: c_int) -> c_int;
649 pub fn linkat(
650 olddirfd: c_int,
651 oldpath: *const c_char,
652 newdirfd: c_int,
653 newpath: *const c_char,
654 flags: c_int,
655 ) -> c_int;
656 pub fn mkdirat(dirfd: c_int, pathname: *const c_char, mode: crate::mode_t) -> c_int;
657 pub fn readlinkat(
658 dirfd: c_int,
659 pathname: *const c_char,
660 buf: *mut c_char,
661 bufsiz: size_t,
662 ) -> ssize_t;
663 pub fn renameat(
664 olddirfd: c_int,
665 oldpath: *const c_char,
666 newdirfd: c_int,
667 newpath: *const c_char,
668 ) -> c_int;
669 pub fn symlinkat(target: *const c_char, newdirfd: c_int, linkpath: *const c_char) -> c_int;
670 pub fn unlinkat(dirfd: c_int, pathname: *const c_char, flags: c_int) -> c_int;
671
672 pub fn access(path: *const c_char, amode: c_int) -> c_int;
673 pub fn close(fd: c_int) -> c_int;
674 pub fn fpathconf(filedes: c_int, name: c_int) -> c_long;
675 pub fn getopt(argc: c_int, argv: *const *mut c_char, optstr: *const c_char) -> c_int;
676 pub fn isatty(fd: c_int) -> c_int;
677 pub fn link(src: *const c_char, dst: *const c_char) -> c_int;
678 pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
679 pub fn pathconf(path: *const c_char, name: c_int) -> c_long;
680 pub fn rmdir(path: *const c_char) -> c_int;
681 pub fn sleep(secs: c_uint) -> c_uint;
682 pub fn unlink(c: *const c_char) -> c_int;
683 pub fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t;
684 pub fn pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t;
685
686 pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int;
687
688 pub fn fsync(fd: c_int) -> c_int;
689 pub fn fdatasync(fd: c_int) -> c_int;
690
691 pub fn symlink(path1: *const c_char, path2: *const c_char) -> c_int;
692
693 pub fn truncate(path: *const c_char, length: off_t) -> c_int;
694 pub fn ftruncate(fd: c_int, length: off_t) -> c_int;
695
696 pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int;
697
698 pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int;
699 pub fn times(buf: *mut crate::tms) -> crate::clock_t;
700
701 pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int;
702
703 pub fn usleep(secs: c_uint) -> c_int;
704 pub fn send(socket: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t;
705 pub fn recv(socket: c_int, buf: *mut c_void, len: size_t, flags: c_int) -> ssize_t;
706 pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) -> c_int;
707 pub fn setlocale(category: c_int, locale: *const c_char) -> *mut c_char;
708 pub fn localeconv() -> *mut lconv;
709
710 pub fn readlink(path: *const c_char, buf: *mut c_char, bufsz: size_t) -> ssize_t;
711
712 pub fn timegm(tm: *mut crate::tm) -> time_t;
713
714 pub fn sysconf(name: c_int) -> c_long;
715
716 pub fn ioctl(fd: c_int, request: c_int, ...) -> c_int;
717
718 pub fn fseeko(stream: *mut crate::FILE, offset: off_t, whence: c_int) -> c_int;
719 pub fn ftello(stream: *mut crate::FILE) -> off_t;
720 pub fn posix_fallocate(fd: c_int, offset: off_t, len: off_t) -> c_int;
721
722 pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
723 pub fn getline(lineptr: *mut *mut c_char, n: *mut size_t, stream: *mut FILE) -> ssize_t;
724
725 pub fn faccessat(dirfd: c_int, pathname: *const c_char, mode: c_int, flags: c_int) -> c_int;
726 pub fn writev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
727 pub fn readv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t;
728 pub fn pwritev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off_t) -> ssize_t;
729 pub fn preadv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off_t) -> ssize_t;
730 pub fn posix_fadvise(fd: c_int, offset: off_t, len: off_t, advise: c_int) -> c_int;
731 pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int;
732 pub fn utimensat(
733 dirfd: c_int,
734 path: *const c_char,
735 times: *const crate::timespec,
736 flag: c_int,
737 ) -> c_int;
738 pub fn getentropy(buf: *mut c_void, buflen: size_t) -> c_int;
739 pub fn memrchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
740 pub fn abs(i: c_int) -> c_int;
741 pub fn labs(i: c_long) -> c_long;
742 pub fn duplocale(base: crate::locale_t) -> crate::locale_t;
743 pub fn freelocale(loc: crate::locale_t);
744 pub fn newlocale(mask: c_int, locale: *const c_char, base: crate::locale_t) -> crate::locale_t;
745 pub fn uselocale(loc: crate::locale_t) -> crate::locale_t;
746 pub fn sched_yield() -> c_int;
747 pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
748 pub fn chdir(dir: *const c_char) -> c_int;
749
750 pub fn nl_langinfo(item: crate::nl_item) -> *mut c_char;
751 pub fn nl_langinfo_l(item: crate::nl_item, loc: crate::locale_t) -> *mut c_char;
752
753 pub fn select(
754 nfds: c_int,
755 readfds: *mut fd_set,
756 writefds: *mut fd_set,
757 errorfds: *mut fd_set,
758 timeout: *const timeval,
759 ) -> c_int;
760
761 pub fn __wasilibc_register_preopened_fd(fd: c_int, path: *const c_char) -> c_int;
762 pub fn __wasilibc_fd_renumber(fd: c_int, newfd: c_int) -> c_int;
763 pub fn __wasilibc_unlinkat(fd: c_int, path: *const c_char) -> c_int;
764 pub fn __wasilibc_rmdirat(fd: c_int, path: *const c_char) -> c_int;
765 pub fn __wasilibc_find_relpath(
766 path: *const c_char,
767 abs_prefix: *mut *const c_char,
768 relative_path: *mut *mut c_char,
769 relative_path_len: usize,
770 ) -> c_int;
771 pub fn __wasilibc_tell(fd: c_int) -> off_t;
772 pub fn __wasilibc_nocwd___wasilibc_unlinkat(dirfd: c_int, path: *const c_char) -> c_int;
773 pub fn __wasilibc_nocwd___wasilibc_rmdirat(dirfd: c_int, path: *const c_char) -> c_int;
774 pub fn __wasilibc_nocwd_linkat(
775 olddirfd: c_int,
776 oldpath: *const c_char,
777 newdirfd: c_int,
778 newpath: *const c_char,
779 flags: c_int,
780 ) -> c_int;
781 pub fn __wasilibc_nocwd_symlinkat(
782 target: *const c_char,
783 dirfd: c_int,
784 path: *const c_char,
785 ) -> c_int;
786 pub fn __wasilibc_nocwd_readlinkat(
787 dirfd: c_int,
788 path: *const c_char,
789 buf: *mut c_char,
790 bufsize: usize,
791 ) -> isize;
792 pub fn __wasilibc_nocwd_faccessat(
793 dirfd: c_int,
794 path: *const c_char,
795 mode: c_int,
796 flags: c_int,
797 ) -> c_int;
798 pub fn __wasilibc_nocwd_renameat(
799 olddirfd: c_int,
800 oldpath: *const c_char,
801 newdirfd: c_int,
802 newpath: *const c_char,
803 ) -> c_int;
804 pub fn __wasilibc_nocwd_openat_nomode(dirfd: c_int, path: *const c_char, flags: c_int)
805 -> c_int;
806 pub fn __wasilibc_nocwd_fstatat(
807 dirfd: c_int,
808 path: *const c_char,
809 buf: *mut stat,
810 flags: c_int,
811 ) -> c_int;
812 pub fn __wasilibc_nocwd_mkdirat_nomode(dirfd: c_int, path: *const c_char) -> c_int;
813 pub fn __wasilibc_nocwd_utimensat(
814 dirfd: c_int,
815 path: *const c_char,
816 times: *const crate::timespec,
817 flags: c_int,
818 ) -> c_int;
819 pub fn __wasilibc_nocwd_opendirat(dirfd: c_int, path: *const c_char) -> *mut crate::DIR;
820 pub fn __wasilibc_access(pathname: *const c_char, mode: c_int, flags: c_int) -> c_int;
821 pub fn __wasilibc_stat(pathname: *const c_char, buf: *mut stat, flags: c_int) -> c_int;
822 pub fn __wasilibc_utimens(
823 pathname: *const c_char,
824 times: *const crate::timespec,
825 flags: c_int,
826 ) -> c_int;
827 pub fn __wasilibc_link(oldpath: *const c_char, newpath: *const c_char, flags: c_int) -> c_int;
828 pub fn __wasilibc_link_oldat(
829 olddirfd: c_int,
830 oldpath: *const c_char,
831 newpath: *const c_char,
832 flags: c_int,
833 ) -> c_int;
834 pub fn __wasilibc_link_newat(
835 oldpath: *const c_char,
836 newdirfd: c_int,
837 newpath: *const c_char,
838 flags: c_int,
839 ) -> c_int;
840 pub fn __wasilibc_rename_oldat(
841 olddirfd: c_int,
842 oldpath: *const c_char,
843 newpath: *const c_char,
844 ) -> c_int;
845 pub fn __wasilibc_rename_newat(
846 oldpath: *const c_char,
847 newdirfd: c_int,
848 newpath: *const c_char,
849 ) -> c_int;
850
851 pub fn arc4random() -> u32;
852 pub fn arc4random_buf(a: *mut c_void, b: size_t);
853 pub fn arc4random_uniform(a: u32) -> u32;
854
855 pub fn __errno_location() -> *mut c_int;
856 }
857
858 cfg_if! {
859 if #[cfg(target_env = "p2")] {
860 mod p2;
861 pub use self::p2::*;
862 }
863 }