Skip to content

Commit

Permalink
Implement the TIOCGWINSZ ioctl.
Browse files Browse the repository at this point in the history
This is a simple wrapper around `rustix::io::ioctl_tiocgwinsz`.
  • Loading branch information
sunfishcode committed Dec 1, 2021
1 parent d50d9b6 commit 1cf3702
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions c-scape/src/data/linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) const DT_LNK: u8 = 10;
pub(crate) const DT_SOCK: u8 = 12;

pub(crate) const TCGETS: c_long = 0x5401;
pub(crate) const TIOCGWINSZ: c_long = 0x5413;
pub(crate) const FIONBIO: c_long = 0x5421;

pub(crate) const ALIGNOF_MAXALIGN_T: usize = 16;
Expand Down
1 change: 1 addition & 0 deletions c-scape/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ constant!(DT_REG);
constant!(DT_LNK);
constant!(DT_SOCK);
constant!(TCGETS);
constant!(TIOCGWINSZ);
constant!(FIONBIO);
#[cfg(not(target_arch = "riscv64"))] // libc for riscv64 doesn't have max_align_t yet
constant_same_as!(
Expand Down
13 changes: 12 additions & 1 deletion c-scape/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ unsafe extern "C" fn ioctl(fd: c_int, request: c_long, mut args: ...) -> c_int {
let fd = BorrowedFd::borrow_raw_fd(fd);
match set_errno(rustix::io::ioctl_tcgets(&fd)) {
Some(x) => {
*args.arg::<*mut rustix::io::Termios>() = x;
args.arg::<*mut rustix::io::Termios>().write(x);
0
}
None => -1,
Expand All @@ -1508,6 +1508,17 @@ unsafe extern "C" fn ioctl(fd: c_int, request: c_long, mut args: ...) -> c_int {
None => -1,
}
}
data::TIOCGWINSZ => {
libc!(ioctl(fd, TIOCGWINSZ));
let fd = BorrowedFd::borrow_raw_fd(fd);
match set_errno(rustix::io::ioctl_tiocgwinsz(&fd)) {
Some(x) => {
args.arg::<*mut rustix::io::Winsize>().write(x);
0
}
None => -1,
}
}
_ => panic!("unrecognized ioctl({})", request),
}
}
Expand Down

0 comments on commit 1cf3702

Please sign in to comment.