Add basic linux termios implementation

This commit is contained in:
nofmal
2020-01-30 13:36:28 +07:00
committed by Andrew Kelley
parent 0fdcd5c4cb
commit a697de3eac
4 changed files with 116 additions and 0 deletions

View File

@@ -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),
}
}
}