diff options
| author | nofmal <ariaoverskies@gmail.com> | 2020-01-30 13:36:28 +0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-02-04 14:09:57 -0500 |
| commit | a697de3eac7fb4bb09e7f2aaee18c916a4eacc07 (patch) | |
| tree | 9a1829e3af21524d5ec957fdbeb80fc27bc3257c /lib/std/os.zig | |
| parent | 0fdcd5c4cb335fcb2d637b891e60094b7a34e2b5 (diff) | |
| download | zig-a697de3eac7fb4bb09e7f2aaee18c916a4eacc07.tar.gz zig-a697de3eac7fb4bb09e7f2aaee18c916a4eacc07.zip | |
Add basic linux termios implementation
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index a9c4a49f1f..302d8bfce5 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3327,3 +3327,35 @@ pub fn getrusage(who: i32) rusage { else => unreachable, } } + +pub const TermiosGetError = error{ + NotATerminal, +} || UnexpectedError; + +pub fn tcgetattr(handle: fd_t) TermiosGetError!termios { + var term: termios = undefined; + switch (errno(system.tcgetattr(handle, &term))) { + 0 => return term, + EBADF => unreachable, + ENOTTY => return error.NotATerminal, + else => |err| return unexpectedErrno(err), + } +} + +pub const TermiosSetError = TermiosGetError || error{ + ProcessOrphaned, +}; + +pub fn tcsetattr(handle: fd_t, optional_action: TCSA, termios_p: termios) TermiosSetError!void { + while (true) { + switch (errno(system.tcsetattr(handle, optional_action, &termios_p))) { + 0 => return, + EBADF => unreachable, + EINTR => continue, + EINVAL => unreachable, + ENOTTY => return error.NotATerminal, + EIO => return error.ProcessOrphaned, + else => |err| return unexpectedErrno(err), + } + } +} |
