| author | |
| committer | |
| log | b88bb93af3cf22f5a994100e037dbb4091144f0c |
| tree | 971dca551cc1a553579115c719e21e067a673fcb |
| parent | 14e9c7d1f2f9a1b583237626e6b834c8e86d6cf7 |
3 files changed, 21 insertions(+), 2 deletions(-)
lib/std/os.zig+1-1| ... | ... | @@ -1522,7 +1522,7 @@ pub fn isatty(handle: fd_t) bool { |
| 1522 | 1522 | return system.isatty(handle) != 0; |
| 1523 | 1523 | } |
| 1524 | 1524 | if (builtin.os == .wasi) { |
| 1525 | @compileError("TODO implement std.os.isatty for WASI"); | |
| 1525 | return system.isatty(handle); | |
| 1526 | 1526 | } |
| 1527 | 1527 | if (builtin.os == .linux) { |
| 1528 | 1528 | var wsz: linux.winsize = undefined; |
lib/std/os/bits/wasi.zig+1-1| ... | ... | @@ -138,7 +138,7 @@ pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004; |
| 138 | 138 | pub const FDFLAG_RSYNC: fdflags_t = 0x0008; |
| 139 | 139 | pub const FDFLAG_SYNC: fdflags_t = 0x0010; |
| 140 | 140 | |
| 141 | const fdstat_t = extern struct { | |
| 141 | pub const fdstat_t = extern struct { | |
| 142 | 142 | fs_filetype: filetype_t, |
| 143 | 143 | fs_flags: fdflags_t, |
| 144 | 144 | fs_rights_base: rights_t, |
lib/std/os/wasi.zig+19| ... | ... | @@ -108,3 +108,22 @@ pub fn clock_gettime(clock_id: i32, tp: *timespec) errno_t { |
| 108 | 108 | }; |
| 109 | 109 | return 0; |
| 110 | 110 | } |
| 111 | ||
| 112 | pub fn isatty(fd: fd_t) bool { | |
| 113 | var statbuf: fdstat_t = undefined; | |
| 114 | const err = fd_fdstat_get(fd, &statbuf); | |
| 115 | if (err != 0) { | |
| 116 | // errno = err; | |
| 117 | return false; | |
| 118 | } | |
| 119 | ||
| 120 | // A tty is a character device that we can't seek or tell on. | |
| 121 | if (statbuf.fs_filetype != FILETYPE_CHARACTER_DEVICE or | |
| 122 | (statbuf.fs_rights_base & (RIGHT_FD_SEEK | RIGHT_FD_TELL)) != 0) | |
| 123 | { | |
| 124 | // errno = ENOTTY; | |
| 125 | return false; | |
| 126 | } | |
| 127 | ||
| 128 | return true; | |
| 129 | } |