diff options
-rw-r--r-- | src/sys/ioctl.rs | 44 | ||||
-rw-r--r-- | src/sys/mod.rs | 2 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/sys/ioctl.rs b/src/sys/ioctl.rs new file mode 100644 index 00000000..9cb47bda --- /dev/null +++ b/src/sys/ioctl.rs @@ -0,0 +1,44 @@ +use libc; +use errno::{SysResult, from_ffi}; +use fcntl::Fd; + +pub use self::ffi::Winsize; +pub use self::IoctlArg::*; + +mod ffi { + use libc::c_ushort; + + #[derive(Copy, Show)] + pub struct Winsize { + pub ws_row: c_ushort, + pub ws_col: c_ushort, + pub ws_xpixel: c_ushort, + pub ws_ypixel: c_ushort, + } + + #[cfg(target_os = "macos")] + pub mod os { + use libc::c_ulong; + pub const TIOCGWINSZ: c_ulong = 0x40087468; + } + + #[cfg(target_os = "linux")] + pub mod os { + use libc::c_int; + pub const TIOCGWINSZ: c_int = 0x5413; + } +} + +pub enum IoctlArg<'a> { + TIOCGWINSZ(&'a mut Winsize) +} + +pub fn ioctl(fd: Fd, arg: IoctlArg) -> SysResult<()> { + match arg { + TIOCGWINSZ(&mut ref winsize) => { + from_ffi(unsafe { + libc::funcs::bsd44::ioctl(fd, ffi::os::TIOCGWINSZ, winsize) + }) + } + } +} diff --git a/src/sys/mod.rs b/src/sys/mod.rs index cd87124a..56104834 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -8,6 +8,8 @@ pub mod event; #[cfg(target_os = "linux")] pub mod eventfd; +pub mod ioctl; + pub mod signal; pub mod socket; |