mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 03:03:09 +00:00
WASI isatty
This commit is contained in:
parent
14e9c7d1f2
commit
b88bb93af3
@ -1522,7 +1522,7 @@ pub fn isatty(handle: fd_t) bool {
|
||||
return system.isatty(handle) != 0;
|
||||
}
|
||||
if (builtin.os == .wasi) {
|
||||
@compileError("TODO implement std.os.isatty for WASI");
|
||||
return system.isatty(handle);
|
||||
}
|
||||
if (builtin.os == .linux) {
|
||||
var wsz: linux.winsize = undefined;
|
||||
|
||||
@ -138,7 +138,7 @@ pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
|
||||
pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
|
||||
pub const FDFLAG_SYNC: fdflags_t = 0x0010;
|
||||
|
||||
const fdstat_t = extern struct {
|
||||
pub const fdstat_t = extern struct {
|
||||
fs_filetype: filetype_t,
|
||||
fs_flags: fdflags_t,
|
||||
fs_rights_base: rights_t,
|
||||
|
||||
@ -108,3 +108,22 @@ pub fn clock_gettime(clock_id: i32, tp: *timespec) errno_t {
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn isatty(fd: fd_t) bool {
|
||||
var statbuf: fdstat_t = undefined;
|
||||
const err = fd_fdstat_get(fd, &statbuf);
|
||||
if (err != 0) {
|
||||
// errno = err;
|
||||
return false;
|
||||
}
|
||||
|
||||
// A tty is a character device that we can't seek or tell on.
|
||||
if (statbuf.fs_filetype != FILETYPE_CHARACTER_DEVICE or
|
||||
(statbuf.fs_rights_base & (RIGHT_FD_SEEK | RIGHT_FD_TELL)) != 0)
|
||||
{
|
||||
// errno = ENOTTY;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user