1//! This exists to satisfy the `std.posix` interface for WASI w/o libc. Most of the stuff here is
2//! taken from wasi-libc, i.e. it is essentially made up from the perspective of pure WASI. This
3//! should be removed alongside `std.posix` eventually.
4
5const builtin = @import("builtin");
6const std = @import("../std.zig");
7
8const wasi = std.os.wasi;
9
10pub const pid_t = i32;
11pub const fd_t = wasi.fd_t;
12pub const uid_t = u32;
13pub const gid_t = u32;
14pub const mode_t = u0;
15pub const nlink_t = u64;
16pub const ino_t = wasi.inode_t;
17
18pub const time_t = i64;
19pub const timespec = extern struct {
20 sec: time_t,
21 nsec: c_long,
22
23 pub fn fromTimestamp(tm: wasi.timestamp_t) @This() {
24 const sec: wasi.timestamp_t = tm / 1_000_000_000;
25 const nsec = tm - sec * 1_000_000_000;
26 return .{
27 .sec = @as(time_t, @intCast(sec)),
28 .nsec = @as(isize, @intCast(nsec)),
29 };
30 }
31
32 pub fn toTimestamp(ts: @This()) wasi.timestamp_t {
33 return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) +
34 @as(wasi.timestamp_t, @intCast(ts.nsec));
35 }
36};
37
38pub const pollfd = extern struct {
39 fd: fd_t,
40 events: i16,
41 revents: i16 = undefined,
42};
43
44pub const rlimit_resource = void;
45
46pub const E = wasi.errno_t;
47
48pub const SIG = void;
49pub const Sigaction = void;
50
51pub const PROT = void;
52
53pub const MCL = void;
54
55pub const AT = struct {
56 pub const EACCESS = 0x0;
57 pub const SYMLINK_NOFOLLOW = 0x1;
58 pub const SYMLINK_FOLLOW = 0x2;
59 pub const REMOVEDIR = 0x4;
60
61 pub const FDCWD: fd_t = 3;
62};
63
64pub const IFNAMESIZE = {};
65
66pub const STDIN_FILENO = 0;
67pub const STDOUT_FILENO = 1;
68pub const STDERR_FILENO = 2;
69
70pub const PATH_MAX = 4096;
71pub const IOV_MAX = 1024;
72
73pub const getrandom = {};
74
75pub const mlock = {};
76pub const mlock2 = {};
77pub const munlock = {};
78pub const mlockall = {};
79pub const munlockall = {};
80
81pub const cmsg_align = {};