diff options
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/fcntl.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 10 | ||||
-rw-r--r-- | src/sys/quota.rs | 4 | ||||
-rw-r--r-- | src/sys/signal.rs | 2 | ||||
-rw-r--r-- | src/sys/socket/addr.rs | 44 | ||||
-rw-r--r-- | src/unistd.rs | 3 | ||||
-rw-r--r-- | test/sys/test_socket.rs | 3 | ||||
-rw-r--r-- | test/sys/test_wait.rs | 2 | ||||
-rw-r--r-- | test/test_stat.rs | 5 |
10 files changed, 46 insertions, 35 deletions
@@ -20,8 +20,8 @@ preadv_pwritev = [] signalfd = [] [dependencies] -libc = "0.1.12" -bitflags = "0.3.2" +libc = "0.2.2" +bitflags = "0.3.3" [dev-dependencies] rand = "0.3.8" diff --git a/src/fcntl.rs b/src/fcntl.rs index 690872a5..9b2e686a 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -11,8 +11,8 @@ pub use self::ffi::flock; mod ffi { pub use libc::{open, fcntl}; pub use self::os::*; - pub use libc::funcs::bsd44::flock as libc_flock; - pub use libc::consts::os::bsd44::{LOCK_SH, LOCK_EX, LOCK_NB, LOCK_UN}; + pub use libc::flock as libc_flock; + pub use libc::{LOCK_SH, LOCK_EX, LOCK_NB, LOCK_UN}; #[cfg(any(target_os = "linux", target_os = "android"))] mod os { @@ -43,7 +43,7 @@ pub mod unistd; * */ -use libc::{c_char, PATH_MAX}; +use libc::c_char; use std::{ptr, result}; use std::ffi::CStr; use std::path::{Path, PathBuf}; @@ -52,6 +52,14 @@ use std::io; use std::fmt; use std::error; +#[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "bitrig", target_os = "macos", target_os = "ios"))] +use libc::PATH_MAX; +#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "bitrig", target_os = "macos", target_os = "ios")))] +const PATH_MAX: c_int = 1024; + + + + pub type Result<T> = result::Result<T, Error>; #[derive(Clone, Copy, Debug, PartialEq)] diff --git a/src/sys/quota.rs b/src/sys/quota.rs index 9b39c98e..199d08e2 100644 --- a/src/sys/quota.rs +++ b/src/sys/quota.rs @@ -15,7 +15,7 @@ pub mod quota { impl QuotaCmd { pub fn as_int(&self) -> c_int { - ((self.0 << 8) | (self.1 & 0x00ff)) as c_int + ((self.0 << 8) | (self.1 & 0x00ff)) as c_int } } @@ -97,7 +97,7 @@ fn quotactl<P: ?Sized + NixPath>(cmd: quota::QuotaCmd, special: Option<&P>, id: pub fn quotactl_on<P: ?Sized + NixPath>(which: quota::QuotaType, special: &P, format: quota::QuotaFmt, quota_file: &P) -> Result<()> { try!(quota_file.with_nix_path(|path| { let mut path_copy = path.to_bytes_with_nul().to_owned(); - let p: *mut i8 = path_copy.as_mut_ptr() as *mut i8; + let p: *mut c_char = path_copy.as_mut_ptr() as *mut c_char; quotactl(quota::QuotaCmd(quota::Q_QUOTAON, which), Some(special), format as c_int, p) })) } diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 93b63196..9cf99ba4 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -7,7 +7,7 @@ use std::mem; use std::ptr; use {Error, Result}; -pub use libc::consts::os::posix88::{ +pub use libc::{ SIGHUP, // 1 SIGINT, // 2 SIGQUIT, // 3 diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 9a37176b..943df26e 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -278,20 +278,31 @@ impl fmt::Display for Ipv4Addr { #[derive(Clone, Copy)] pub struct Ipv6Addr(pub libc::in6_addr); +macro_rules! to_u8_array { + ($($num:ident),*) => { + if cfg!(target_endian = "big") { + [ $(($num>>8) as u8, ($num&0xff) as u8,)* ] + } else { + [ $(($num&0xff) as u8, ($num>>8) as u8,)* ] + } + } +} + +macro_rules! to_u16_array { + ($slf:ident, $($first:expr, $second:expr),*) => { + if cfg!(target_endian = "big") { + [$( (($slf.0.s6_addr[$first] as u16) << 8) + $slf.0.s6_addr[$second] as u16,)*] + } else { + [$( (($slf.0.s6_addr[$second] as u16) << 8) + $slf.0.s6_addr[$first] as u16,)*] + } + } +} + impl Ipv6Addr { pub fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { - Ipv6Addr(libc::in6_addr { - s6_addr: [ - a.to_be(), - b.to_be(), - c.to_be(), - d.to_be(), - e.to_be(), - f.to_be(), - g.to_be(), - h.to_be(), - ] - }) + let mut in6_addr_var: libc::in6_addr = unsafe{mem::uninitialized()}; + in6_addr_var.s6_addr = to_u8_array!(a,b,c,d,e,f,g,h); + Ipv6Addr(in6_addr_var) } pub fn from_std(std: &net::Ipv6Addr) -> Ipv6Addr { @@ -301,14 +312,7 @@ impl Ipv6Addr { /// Return the eight 16-bit segments that make up this address pub fn segments(&self) -> [u16; 8] { - [u16::from_be(self.0.s6_addr[0]), - u16::from_be(self.0.s6_addr[1]), - u16::from_be(self.0.s6_addr[2]), - u16::from_be(self.0.s6_addr[3]), - u16::from_be(self.0.s6_addr[4]), - u16::from_be(self.0.s6_addr[5]), - u16::from_be(self.0.s6_addr[6]), - u16::from_be(self.0.s6_addr[7])] + to_u16_array!(self, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) } pub fn to_std(&self) -> net::Ipv6Addr { diff --git a/src/unistd.rs b/src/unistd.rs index ce755d62..506f0ef9 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -14,8 +14,7 @@ pub use self::linux::*; mod ffi { use libc::{c_char, c_int, size_t}; - pub use libc::{close, read, write, pipe, ftruncate, unlink, setpgid}; - pub use libc::funcs::posix88::unistd::{fork, getegid, geteuid, getgid, getpid, getppid, getuid}; + pub use libc::{fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid}; extern { // duplicate a file descriptor diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 945638cc..258cde07 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -4,6 +4,7 @@ use std::path::Path; use std::str::FromStr; use std::os::unix::io::{AsRawFd, RawFd}; use ports::localhost; +use libc::c_char; #[test] pub fn test_inetv4_addr_to_sock_addr() { @@ -32,7 +33,7 @@ pub fn test_path_to_sock_addr() { let actual = Path::new("/foo/bar"); let addr = UnixAddr::new(actual).unwrap(); - let expect: &'static [i8] = unsafe { mem::transmute(&b"/foo/bar"[..]) }; + let expect: &'static [c_char] = unsafe { mem::transmute(&b"/foo/bar"[..]) }; assert_eq!(&addr.0.sun_path[..8], expect); assert_eq!(addr.path(), Some(actual)); diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs index 51b0301a..01f63dd1 100644 --- a/test/sys/test_wait.rs +++ b/test/sys/test_wait.rs @@ -2,7 +2,7 @@ use nix::unistd::*; use nix::unistd::Fork::*; use nix::sys::signal::*; use nix::sys::wait::*; -use libc::funcs::c95::stdlib::exit; +use libc::exit; #[test] fn test_wait_signal() { diff --git a/test/test_stat.rs b/test/test_stat.rs index c567eb8e..4b22c296 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -2,7 +2,7 @@ use std::fs::File; use std::os::unix::fs::symlink; use std::os::unix::prelude::AsRawFd; -use libc::consts::os::posix88; +use libc::{S_IFMT, S_IFLNK}; use nix::sys::stat::{stat, fstat, lstat}; @@ -46,8 +46,7 @@ fn assert_lstat_results(stat_result: Result<FileStat>) { // st_mode is c_uint (u32 on Android) while S_IFMT is mode_t // (u16 on Android), and that will be a compile error. // On other platforms they are the same (either both are u16 or u32). - assert!((stats.st_mode as usize) & (posix88::S_IFMT as usize) - == posix88::S_IFLNK as usize); // should be a link + assert!((stats.st_mode as usize) & (S_IFMT as usize) == S_IFLNK as usize); // should be a link assert!(stats.st_nlink == 1); // there links created, must be 1 assert!(valid_uid_gid(stats)); // must be positive integers assert!(stats.st_size > 0); // size is > 0 because it points to another file |