Fix a couple of issues spotted by alexcrichton.

See comments https://github.com/rust-lang/libc/pull/194.

Note on struct utsname: Neither using a constant, nor a conditional
macro seems to work, so I just created an ugly utsname with conditions
on each field. This should also fix the CI fallout. #[cfg] on macros
doesn't work?

As DragonFly only supports one platform, I merged  x86_64.rs into
dragonfly/mod.rs.
This commit is contained in:
Michael Neumann 2016-02-21 12:28:10 +01:00
parent a6a64d17a0
commit a09fe71617
6 changed files with 81 additions and 83 deletions

View File

@ -199,9 +199,6 @@ fn main() {
// OSX calls this something else
"sighandler_t" if bsdlike => "sig_t".to_string(),
// does not exist on DragonFly
"fflags_t" if dragonfly => "uint32_t".to_string(),
t if t.ends_with("_t") => t.to_string(),
// Windows uppercase structs don't have `struct` in front, there's a
@ -270,6 +267,7 @@ fn main() {
"mach_timebase_info_data_t" |
"float" |
"double" => true,
// uuid_t is a struct, not an integer.
"uuid_t" if dragonfly => true,
n if n.starts_with("pthread") => true,

View File

@ -1,17 +1,13 @@
cfg_if! {
if #[cfg(target_arch = "x86_64")] {
mod x86_64;
pub use self::x86_64::*;
} else {
// ...
}
}
pub type clock_t = u64;
pub type ino_t = u64;
pub type nlink_t = u32;
pub type blksize_t = i64;
pub type c_long = i64;
pub type c_ulong = u64;
pub type time_t = i64;
pub type suseconds_t = i64;
s! {
pub struct dirent {
pub d_fileno: ::ino_t,
@ -23,12 +19,12 @@ s! {
}
pub struct uuid {
time_low: u32,
time_mid: u16,
time_hi_and_version: u16,
clock_seq_hi_and_reserved: u8,
clock_seq_low: u8,
node: [u8; 6],
pub time_low: u32,
pub time_mid: u16,
pub time_hi_and_version: u16,
pub clock_seq_hi_and_reserved: u8,
pub clock_seq_low: u8,
pub node: [u8; 6],
}
pub struct statvfs {
@ -52,6 +48,31 @@ s! {
pub f_fsid_uuid: ::uuid_t,
pub f_uid_uuid: ::uuid_t,
}
pub struct stat {
pub st_ino: ::ino_t,
pub st_nlink: ::nlink_t,
pub st_dev: ::dev_t,
pub st_mode: ::mode_t,
pub st_padding1: ::uint16_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
pub st_atime: ::time_t,
pub st_atime_nsec: ::c_long,
pub st_mtime: ::time_t,
pub st_mtime_nsec: ::c_long,
pub st_ctime: ::time_t,
pub st_ctime_nsec: ::c_long,
pub st_size: ::off_t,
pub st_blocks: ::int64_t,
pub st_blksize: ::uint32_t,
pub st_flags: ::uint32_t,
pub st_gen: ::uint32_t,
pub st_lspare: ::int32_t,
pub st_qspare1: ::int64_t,
pub st_qspare2: ::int64_t,
}
}
pub type uuid_t = ::uuid;
@ -74,3 +95,9 @@ pub const RLIM_NLIMITS: ::rlim_t = 12;
pub const Q_GETQUOTA: ::c_int = 0x300;
pub const Q_SETQUOTA: ::c_int = 0x400;
extern {
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn clock_gettime(clk_id: ::c_ulong, tp: *mut ::timespec) -> ::c_int;
}

View File

@ -1,31 +0,0 @@
pub type c_long = i64;
pub type c_ulong = u64;
pub type time_t = i64;
pub type suseconds_t = i64;
s! {
pub struct stat {
pub st_ino: ::ino_t,
pub st_nlink: ::nlink_t,
pub st_dev: ::dev_t,
pub st_mode: ::mode_t,
pub st_padding1: ::uint16_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_rdev: ::dev_t,
pub st_atime: ::time_t,
pub st_atime_nsec: ::c_long,
pub st_mtime: ::time_t,
pub st_mtime_nsec: ::c_long,
pub st_ctime: ::time_t,
pub st_ctime_nsec: ::c_long,
pub st_size: ::off_t,
pub st_blocks: ::int64_t,
pub st_blksize: ::uint32_t,
pub st_flags: ::fflags_t,
pub st_gen: ::uint32_t,
pub st_lspare: ::int32_t,
pub st_qspare1: ::int64_t,
pub st_qspare2: ::int64_t,
}
}

View File

@ -1,15 +1,4 @@
cfg_if! {
if #[cfg(target_arch = "x86")] {
mod x86;
pub use self::x86::*;
} else if #[cfg(target_arch = "x86_64")] {
mod x86_64;
pub use self::x86_64::*;
} else {
// ...
}
}
pub type fflags_t = u32;
pub type clock_t = i32;
pub type ino_t = u32;
pub type nlink_t = u16;
@ -71,6 +60,11 @@ pub const POSIX_FADV_NOREUSE: ::c_int = 5;
extern {
pub fn __error() -> *mut ::c_int;
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t,
len: ::off_t) -> ::c_int;
pub fn posix_fadvise(fd: ::c_int, offset: ::off_t, len: ::off_t,
@ -78,3 +72,15 @@ extern {
pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int;
pub fn mkostemps(template: *mut ::c_char, suffixlen: ::c_int, flags: ::c_int) -> ::c_int;
}
cfg_if! {
if #[cfg(target_arch = "x86")] {
mod x86;
pub use self::x86::*;
} else if #[cfg(target_arch = "x86_64")] {
mod x86_64;
pub use self::x86_64::*;
} else {
// ...
}
}

View File

@ -1,6 +1,5 @@
pub type dev_t = u32;
pub type mode_t = u16;
pub type fflags_t = u32;
pub type pthread_attr_t = *mut ::c_void;
pub type rlim_t = i64;
pub type pthread_mutex_t = *mut ::c_void;
@ -563,12 +562,6 @@ extern {
mibp: *mut ::c_int,
sizep: *mut ::size_t)
-> ::c_int;
#[cfg(not(target_os = "dragonfly"))]
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
#[cfg(target_os = "dragonfly")]
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn shm_open(name: *const ::c_char, oflag: ::c_int, mode: ::mode_t)
-> ::c_int;
pub fn sysctl(name: *const ::c_int,
@ -584,11 +577,6 @@ extern {
newp: *const ::c_void,
newlen: ::size_t)
-> ::c_int;
#[cfg(not(target_os = "dragonfly"))]
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
#[cfg(target_os = "dragonfly")]
pub fn clock_gettime(clk_id: ::uint64_t, tp: *mut ::timespec) -> ::c_int;
pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char);
pub fn sched_setscheduler(pid: ::pid_t, policy: ::c_int, param: *const sched_param) -> ::c_int;
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;

View File

@ -10,11 +10,6 @@ pub type sa_family_t = u8;
pub type pthread_t = ::uintptr_t;
pub type nfds_t = ::c_uint;
#[cfg(not(target_os = "dragonfly"))]
macro_rules! utsname_len { () => (256) }
#[cfg(target_os = "dragonfly")]
macro_rules! utsname_len { () => (32) }
s! {
pub struct sockaddr {
pub sa_len: u8,
@ -90,11 +85,26 @@ s! {
}
pub struct utsname {
pub sysname: [::c_char; utsname_len!()],
pub nodename: [::c_char; utsname_len!()],
pub release: [::c_char; utsname_len!()],
pub version: [::c_char; utsname_len!()],
pub machine: [::c_char; utsname_len!()],
#[cfg(not(target_os = "dragonfly"))]
pub sysname: [::c_char; 256],
#[cfg(target_os = "dragonfly")]
pub sysname: [::c_char; 32],
#[cfg(not(target_os = "dragonfly"))]
pub nodename: [::c_char; 256],
#[cfg(target_os = "dragonfly")]
pub nodename: [::c_char; 32],
#[cfg(not(target_os = "dragonfly"))]
pub release: [::c_char; 256],
#[cfg(target_os = "dragonfly")]
pub release: [::c_char; 32],
#[cfg(not(target_os = "dragonfly"))]
pub version: [::c_char; 256],
#[cfg(target_os = "dragonfly")]
pub version: [::c_char; 32],
#[cfg(not(target_os = "dragonfly"))]
pub machine: [::c_char; 256],
#[cfg(target_os = "dragonfly")]
pub machine: [::c_char; 32],
}
pub struct msghdr {