From efcc232de1d52ace900a1e345dce9a28602e4612 Mon Sep 17 00:00:00 2001 From: Ticki Date: Tue, 8 Mar 2016 11:27:53 +0100 Subject: [PATCH] 32-bit support --- src/size.rs | 16 ++++++++++++++-- src/termios.rs | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/size.rs b/src/size.rs index 695a241..0ace53d 100644 --- a/src/size.rs +++ b/src/size.rs @@ -12,18 +12,30 @@ struct TermSize { _y: c_ushort, } +// Since attributes on non-item statements is not stable yet, we use a function. +#[cfg(target_pointer_width = "64")] +fn tiocgwinsz() -> u64 { + use termios::TIOCGWINSZ; + TIOCGWINSZ as u64 +} +#[cfg(target_pointer_width = "32")] +fn tiocgwinsz() -> u32 { + use termios::TIOCGWINSZ; + TIOCGWINSZ as u32 +} + + /// Get the size of the terminal. #[cfg(not(target_os = "redox"))] pub fn terminal_size() -> Result<(usize, usize), TerminalError> { use libc::ioctl; use libc::STDOUT_FILENO; - use termios::TIOCGWINSZ; use std::mem; unsafe { let mut size: TermSize = mem::zeroed(); - if ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut size as *mut _) == 0 { + if ioctl(STDOUT_FILENO, tiocgwinsz(), &mut size as *mut _) == 0 { Ok((size.col as usize, size.row as usize)) } else { Err(TerminalError::TermSizeError) diff --git a/src/termios.rs b/src/termios.rs index 0e6adc4..c4f1869 100644 --- a/src/termios.rs +++ b/src/termios.rs @@ -1,10 +1,10 @@ use libc::{c_int, c_uint, c_uchar}; #[cfg(not(target_os = "macos"))] -pub const TIOCGWINSZ: u64 = 0x00005413; +pub const TIOCGWINSZ: usize = 0x00005413; #[cfg(target_os = "macos")] -pub const TIOCGWINSZ: u64 = 0x40087468; +pub const TIOCGWINSZ: usize = 0x40087468; extern { pub fn tcgetattr(filedes: c_int, termptr: *mut Termios) -> c_int;