| 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 | |
| 5 | const builtin = @import("builtin"); |
| 6 | const std = @import("../std.zig"); |
| 7 | |
| 8 | const wasi = std.os.wasi; |
| 9 | |
| 10 | pub const pid_t = i32; |
| 11 | pub const fd_t = wasi.fd_t; |
| 12 | pub const uid_t = u32; |
| 13 | pub const gid_t = u32; |
| 14 | pub const mode_t = u0; |
| 15 | pub const nlink_t = u64; |
| 16 | pub const ino_t = wasi.inode_t; |
| 17 | |
| 18 | pub const time_t = i64; |
| 19 | pub 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 | |
| 38 | pub const pollfd = extern struct { |
| 39 | fd: fd_t, |
| 40 | events: i16, |
| 41 | revents: i16 = undefined, |
| 42 | }; |
| 43 | |
| 44 | pub const rlimit_resource = void; |
| 45 | |
| 46 | pub const E = wasi.errno_t; |
| 47 | |
| 48 | pub const SIG = void; |
| 49 | pub const Sigaction = void; |
| 50 | |
| 51 | pub const PROT = void; |
| 52 | |
| 53 | pub const MCL = void; |
| 54 | |
| 55 | pub 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 | |
| 64 | pub const IFNAMESIZE = {}; |
| 65 | |
| 66 | pub const STDIN_FILENO = 0; |
| 67 | pub const STDOUT_FILENO = 1; |
| 68 | pub const STDERR_FILENO = 2; |
| 69 | |
| 70 | pub const PATH_MAX = 4096; |
| 71 | pub const IOV_MAX = 1024; |
| 72 | |
| 73 | pub const getrandom = {}; |
| 74 | |
| 75 | pub const mlock = {}; |
| 76 | pub const mlock2 = {}; |
| 77 | pub const munlock = {}; |
| 78 | pub const mlockall = {}; |
| 79 | pub const munlockall = {}; |
| 80 | |
| 81 | pub const cmsg_align = {}; |