Start using the libc crate from crates.io

This commit is contained in:
Ben S 2015-05-16 13:17:50 +01:00
parent 00ae71850b
commit 2594690aff
4 changed files with 17 additions and 22 deletions

17
Cargo.lock generated
View File

@ -6,7 +6,8 @@ dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"datetime 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "datetime 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.2.9 (git+https://github.com/alexcrichton/git2-rs.git)", "git2 0.2.10 (git+https://github.com/alexcrichton/git2-rs.git)",
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"locale 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "locale 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"natord 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "natord 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -53,13 +54,13 @@ dependencies = [
[[package]] [[package]]
name = "git2" name = "git2"
version = "0.2.9" version = "0.2.10"
source = "git+https://github.com/alexcrichton/git2-rs.git#3a5f0b5698c5203fa48e33094158990a2c53c979" source = "git+https://github.com/alexcrichton/git2-rs.git#f820ef645e2275c80c3009da770a5b6a9b5ce0f0"
dependencies = [ dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"libgit2-sys 0.2.12 (git+https://github.com/alexcrichton/git2-rs.git)", "libgit2-sys 0.2.13 (git+https://github.com/alexcrichton/git2-rs.git)",
"url 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -69,8 +70,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "libgit2-sys" name = "libgit2-sys"
version = "0.2.12" version = "0.2.13"
source = "git+https://github.com/alexcrichton/git2-rs.git#3a5f0b5698c5203fa48e33094158990a2c53c979" source = "git+https://github.com/alexcrichton/git2-rs.git#f820ef645e2275c80c3009da770a5b6a9b5ce0f0"
dependencies = [ dependencies = [
"libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"libssh2-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "libssh2-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
@ -232,7 +233,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "url" name = "url"
version = "0.2.33" version = "0.2.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -11,6 +11,7 @@ ansi_term = "0.5.0"
bitflags = "0.1" bitflags = "0.1"
datetime = "0.1.3" datetime = "0.1.3"
getopts = "0.2.1" getopts = "0.2.1"
libc = "*"
locale = "0.1.2" locale = "0.1.2"
natord = "1.0.7" natord = "1.0.7"
num_cpus = "*" num_cpus = "*"

View File

@ -1,9 +1,10 @@
#![feature(collections, convert, core, exit_status, file_type, fs_ext, fs_mode)] #![feature(collections, convert, core, exit_status, file_type, fs_ext, fs_mode)]
#![feature(libc, metadata_ext, raw_ext, scoped, symlink_metadata)] #![feature(metadata_ext, raw_ext, scoped, symlink_metadata)]
extern crate ansi_term; extern crate ansi_term;
extern crate datetime; extern crate datetime;
extern crate getopts; extern crate getopts;
extern crate libc;
extern crate locale; extern crate locale;
extern crate natord; extern crate natord;
extern crate num_cpus; extern crate num_cpus;
@ -12,7 +13,6 @@ extern crate pad;
extern crate users; extern crate users;
extern crate unicode_width; extern crate unicode_width;
#[cfg(feature="git")] #[cfg(feature="git")]
extern crate git2; extern crate git2;

View File

@ -1,19 +1,12 @@
mod c { mod c {
#![allow(non_camel_case_types)] pub use libc::{c_int, c_ushort, c_ulong, STDOUT_FILENO};
extern crate libc;
pub use self::libc::{
c_int,
c_ushort,
c_ulong,
STDOUT_FILENO,
};
use std::mem::zeroed; use std::mem::zeroed;
// Getting the terminal size is done using an ioctl command that // Getting the terminal size is done using an ioctl command that
// takes the file handle to the terminal (which in our case is // takes the file handle to the terminal (which in our case is
// stdout), and populates a structure with the values. // stdout), and populates a structure with the values.
pub struct winsize { pub struct Winsize {
pub ws_row: c_ushort, pub ws_row: c_ushort,
pub ws_col: c_ushort, pub ws_col: c_ushort,
} }
@ -30,9 +23,9 @@ mod c {
pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
} }
pub unsafe fn dimensions() -> winsize { pub unsafe fn dimensions() -> Winsize {
let mut window: winsize = zeroed(); let mut window: Winsize = zeroed();
ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut window as *mut winsize); ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut window as *mut Winsize);
window window
} }
} }