Skip to content

Commit 778dd31

Browse files
author
Mattis Marjak
committed
update libc to 0.2.2
1 parent 073cc85 commit 778dd31

File tree

10 files changed

+46
-34
lines changed

10 files changed

+46
-34
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ preadv_pwritev = []
2020
signalfd = []
2121

2222
[dependencies]
23-
libc = "0.1.12"
24-
bitflags = "0.3.2"
23+
libc = "0.2.2"
24+
bitflags = "0.3.3"
2525

2626
[dev-dependencies]
2727
rand = "0.3.8"

src/fcntl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub use self::ffi::flock;
1111
mod ffi {
1212
pub use libc::{open, fcntl};
1313
pub use self::os::*;
14-
pub use libc::funcs::bsd44::flock as libc_flock;
15-
pub use libc::consts::os::bsd44::{LOCK_SH, LOCK_EX, LOCK_NB, LOCK_UN};
14+
pub use libc::flock as libc_flock;
15+
pub use libc::{LOCK_SH, LOCK_EX, LOCK_NB, LOCK_UN};
1616

1717
#[cfg(any(target_os = "linux", target_os = "android"))]
1818
mod os {

src/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub mod unistd;
4343
*
4444
*/
4545

46-
use libc::{c_char, PATH_MAX};
46+
use libc::c_char;
4747
use std::{ptr, result};
4848
use std::ffi::CStr;
4949
use std::path::{Path, PathBuf};
@@ -52,6 +52,14 @@ use std::io;
5252
use std::fmt;
5353
use std::error;
5454

55+
#[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "bitrig", target_os = "macos", target_os = "ios"))]
56+
use libc::PATH_MAX;
57+
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "bitrig", target_os = "macos", target_os = "ios")))]
58+
const PATH_MAX: c_int = 1024;
59+
60+
61+
62+
5563
pub type Result<T> = result::Result<T, Error>;
5664

5765
#[derive(Clone, Copy, Debug, PartialEq)]

src/sys/quota.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub mod quota {
1515

1616
impl QuotaCmd {
1717
pub fn as_int(&self) -> c_int {
18-
((self.0 << 8) | (self.1 & 0x00ff)) as c_int
18+
((self.0 << 8) | (self.1 & 0x00ff)) as c_int
1919
}
2020
}
2121

@@ -97,7 +97,7 @@ fn quotactl<P: ?Sized + NixPath>(cmd: quota::QuotaCmd, special: Option<&P>, id:
9797
pub fn quotactl_on<P: ?Sized + NixPath>(which: quota::QuotaType, special: &P, format: quota::QuotaFmt, quota_file: &P) -> Result<()> {
9898
try!(quota_file.with_nix_path(|path| {
9999
let mut path_copy = path.to_bytes_with_nul().to_owned();
100-
let p: *mut i8 = path_copy.as_mut_ptr() as *mut i8;
100+
let p: *mut c_char = path_copy.as_mut_ptr() as *mut c_char;
101101
quotactl(quota::QuotaCmd(quota::Q_QUOTAON, which), Some(special), format as c_int, p)
102102
}))
103103
}

src/sys/signal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::mem;
77
use std::ptr;
88
use {Error, Result};
99

10-
pub use libc::consts::os::posix88::{
10+
pub use libc::{
1111
SIGHUP, // 1
1212
SIGINT, // 2
1313
SIGQUIT, // 3

src/sys/socket/addr.rs

+24-20
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,31 @@ impl fmt::Display for Ipv4Addr {
278278
#[derive(Clone, Copy)]
279279
pub struct Ipv6Addr(pub libc::in6_addr);
280280

281+
macro_rules! to_u8_array {
282+
($($num:ident),*) => {
283+
if cfg!(target_endian = "big") {
284+
[ $(($num>>8) as u8, ($num&0xff) as u8,)* ]
285+
} else {
286+
[ $(($num&0xff) as u8, ($num>>8) as u8,)* ]
287+
}
288+
}
289+
}
290+
291+
macro_rules! to_u16_array {
292+
($slf:ident, $($first:expr, $second:expr),*) => {
293+
if cfg!(target_endian = "big") {
294+
[$( (($slf.0.s6_addr[$first] as u16) << 8) + $slf.0.s6_addr[$second] as u16,)*]
295+
} else {
296+
[$( (($slf.0.s6_addr[$second] as u16) << 8) + $slf.0.s6_addr[$first] as u16,)*]
297+
}
298+
}
299+
}
300+
281301
impl Ipv6Addr {
282302
pub fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr {
283-
Ipv6Addr(libc::in6_addr {
284-
s6_addr: [
285-
a.to_be(),
286-
b.to_be(),
287-
c.to_be(),
288-
d.to_be(),
289-
e.to_be(),
290-
f.to_be(),
291-
g.to_be(),
292-
h.to_be(),
293-
]
294-
})
303+
let mut in6_addr_var: libc::in6_addr = unsafe{mem::uninitialized()};
304+
in6_addr_var.s6_addr = to_u8_array!(a,b,c,d,e,f,g,h);
305+
Ipv6Addr(in6_addr_var)
295306
}
296307

297308
pub fn from_std(std: &net::Ipv6Addr) -> Ipv6Addr {
@@ -301,14 +312,7 @@ impl Ipv6Addr {
301312

302313
/// Return the eight 16-bit segments that make up this address
303314
pub fn segments(&self) -> [u16; 8] {
304-
[u16::from_be(self.0.s6_addr[0]),
305-
u16::from_be(self.0.s6_addr[1]),
306-
u16::from_be(self.0.s6_addr[2]),
307-
u16::from_be(self.0.s6_addr[3]),
308-
u16::from_be(self.0.s6_addr[4]),
309-
u16::from_be(self.0.s6_addr[5]),
310-
u16::from_be(self.0.s6_addr[6]),
311-
u16::from_be(self.0.s6_addr[7])]
315+
to_u16_array!(self, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
312316
}
313317

314318
pub fn to_std(&self) -> net::Ipv6Addr {

src/unistd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::linux::*;
1515
mod ffi {
1616
use libc::{c_char, c_int, size_t};
1717
pub use libc::{close, read, write, pipe, ftruncate, unlink};
18-
pub use libc::funcs::posix88::unistd::{fork, getpid, getppid};
18+
pub use libc::{fork, getpid, getppid};
1919

2020
extern {
2121
// duplicate a file descriptor

test/sys/test_socket.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::Path;
44
use std::str::FromStr;
55
use std::os::unix::io::{AsRawFd, RawFd};
66
use ports::localhost;
7+
use libc::c_char;
78

89
#[test]
910
pub fn test_inetv4_addr_to_sock_addr() {
@@ -32,7 +33,7 @@ pub fn test_path_to_sock_addr() {
3233
let actual = Path::new("/foo/bar");
3334
let addr = UnixAddr::new(actual).unwrap();
3435

35-
let expect: &'static [i8] = unsafe { mem::transmute(&b"/foo/bar"[..]) };
36+
let expect: &'static [c_char] = unsafe { mem::transmute(&b"/foo/bar"[..]) };
3637
assert_eq!(&addr.0.sun_path[..8], expect);
3738

3839
assert_eq!(addr.path(), Some(actual));

test/sys/test_wait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use nix::unistd::*;
22
use nix::unistd::Fork::*;
33
use nix::sys::signal::*;
44
use nix::sys::wait::*;
5-
use libc::funcs::c95::stdlib::exit;
5+
use libc::exit;
66

77
#[test]
88
fn test_wait_signal() {

test/test_stat.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fs;
22
use std::str;
33

4-
use libc::consts::os::posix88;
4+
use libc::{S_IFMT, S_IFLNK};
55

66
use nix::sys::stat::{stat, fstat, lstat};
77

@@ -40,8 +40,7 @@ fn assert_lstat_results(stat_result: Result<FileStat>) {
4040
// st_mode is c_uint (u32 on Android) while S_IFMT is mode_t
4141
// (u16 on Android), and that will be a compile error.
4242
// On other platforms they are the same (either both are u16 or u32).
43-
assert!((stats.st_mode as usize) & (posix88::S_IFMT as usize)
44-
== posix88::S_IFLNK as usize); // should be a link
43+
assert!((stats.st_mode as usize) & (S_IFMT as usize) == S_IFLNK as usize); // should be a link
4544
assert!(stats.st_nlink == 1); // there links created, must be 1
4645
// uid could be 0 for the `root` user. This quite possible when
4746
// the tests are being run on a rooted Android device.

0 commit comments

Comments
 (0)