Skip to content

Commit a09fe71

Browse files
committed
Fix a couple of issues spotted by alexcrichton.
See comments rust-lang/libc#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.
1 parent a6a64d1 commit a09fe71

File tree

6 files changed

+81
-83
lines changed

6 files changed

+81
-83
lines changed

libc-test/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ fn main() {
199199
// OSX calls this something else
200200
"sighandler_t" if bsdlike => "sig_t".to_string(),
201201

202-
// does not exist on DragonFly
203-
"fflags_t" if dragonfly => "uint32_t".to_string(),
204-
205202
t if t.ends_with("_t") => t.to_string(),
206203

207204
// Windows uppercase structs don't have `struct` in front, there's a
@@ -270,6 +267,7 @@ fn main() {
270267
"mach_timebase_info_data_t" |
271268
"float" |
272269
"double" => true,
270+
// uuid_t is a struct, not an integer.
273271
"uuid_t" if dragonfly => true,
274272
n if n.starts_with("pthread") => true,
275273

src/unix/bsd/freebsdlike/dragonfly/mod.rs

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
cfg_if! {
2-
if #[cfg(target_arch = "x86_64")] {
3-
mod x86_64;
4-
pub use self::x86_64::*;
5-
} else {
6-
// ...
7-
}
8-
}
9-
101
pub type clock_t = u64;
112
pub type ino_t = u64;
123
pub type nlink_t = u32;
134
pub type blksize_t = i64;
145

6+
pub type c_long = i64;
7+
pub type c_ulong = u64;
8+
pub type time_t = i64;
9+
pub type suseconds_t = i64;
10+
1511
s! {
1612
pub struct dirent {
1713
pub d_fileno: ::ino_t,
@@ -23,12 +19,12 @@ s! {
2319
}
2420

2521
pub struct uuid {
26-
time_low: u32,
27-
time_mid: u16,
28-
time_hi_and_version: u16,
29-
clock_seq_hi_and_reserved: u8,
30-
clock_seq_low: u8,
31-
node: [u8; 6],
22+
pub time_low: u32,
23+
pub time_mid: u16,
24+
pub time_hi_and_version: u16,
25+
pub clock_seq_hi_and_reserved: u8,
26+
pub clock_seq_low: u8,
27+
pub node: [u8; 6],
3228
}
3329

3430
pub struct statvfs {
@@ -52,6 +48,31 @@ s! {
5248
pub f_fsid_uuid: ::uuid_t,
5349
pub f_uid_uuid: ::uuid_t,
5450
}
51+
52+
pub struct stat {
53+
pub st_ino: ::ino_t,
54+
pub st_nlink: ::nlink_t,
55+
pub st_dev: ::dev_t,
56+
pub st_mode: ::mode_t,
57+
pub st_padding1: ::uint16_t,
58+
pub st_uid: ::uid_t,
59+
pub st_gid: ::gid_t,
60+
pub st_rdev: ::dev_t,
61+
pub st_atime: ::time_t,
62+
pub st_atime_nsec: ::c_long,
63+
pub st_mtime: ::time_t,
64+
pub st_mtime_nsec: ::c_long,
65+
pub st_ctime: ::time_t,
66+
pub st_ctime_nsec: ::c_long,
67+
pub st_size: ::off_t,
68+
pub st_blocks: ::int64_t,
69+
pub st_blksize: ::uint32_t,
70+
pub st_flags: ::uint32_t,
71+
pub st_gen: ::uint32_t,
72+
pub st_lspare: ::int32_t,
73+
pub st_qspare1: ::int64_t,
74+
pub st_qspare2: ::int64_t,
75+
}
5576
}
5677

5778
pub type uuid_t = ::uuid;
@@ -74,3 +95,9 @@ pub const RLIM_NLIMITS: ::rlim_t = 12;
7495

7596
pub const Q_GETQUOTA: ::c_int = 0x300;
7697
pub const Q_SETQUOTA: ::c_int = 0x400;
98+
99+
extern {
100+
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
101+
-> ::c_int;
102+
pub fn clock_gettime(clk_id: ::c_ulong, tp: *mut ::timespec) -> ::c_int;
103+
}

src/unix/bsd/freebsdlike/dragonfly/x86_64.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
cfg_if! {
2-
if #[cfg(target_arch = "x86")] {
3-
mod x86;
4-
pub use self::x86::*;
5-
} else if #[cfg(target_arch = "x86_64")] {
6-
mod x86_64;
7-
pub use self::x86_64::*;
8-
} else {
9-
// ...
10-
}
11-
}
12-
1+
pub type fflags_t = u32;
132
pub type clock_t = i32;
143
pub type ino_t = u32;
154
pub type nlink_t = u16;
@@ -71,10 +60,27 @@ pub const POSIX_FADV_NOREUSE: ::c_int = 5;
7160
extern {
7261
pub fn __error() -> *mut ::c_int;
7362

63+
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
64+
-> ::c_int;
65+
66+
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
67+
7468
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t,
7569
len: ::off_t) -> ::c_int;
7670
pub fn posix_fadvise(fd: ::c_int, offset: ::off_t, len: ::off_t,
7771
advise: ::c_int) -> ::c_int;
7872
pub fn mkostemp(template: *mut ::c_char, flags: ::c_int) -> ::c_int;
7973
pub fn mkostemps(template: *mut ::c_char, suffixlen: ::c_int, flags: ::c_int) -> ::c_int;
8074
}
75+
76+
cfg_if! {
77+
if #[cfg(target_arch = "x86")] {
78+
mod x86;
79+
pub use self::x86::*;
80+
} else if #[cfg(target_arch = "x86_64")] {
81+
mod x86_64;
82+
pub use self::x86_64::*;
83+
} else {
84+
// ...
85+
}
86+
}

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub type dev_t = u32;
22
pub type mode_t = u16;
3-
pub type fflags_t = u32;
43
pub type pthread_attr_t = *mut ::c_void;
54
pub type rlim_t = i64;
65
pub type pthread_mutex_t = *mut ::c_void;
@@ -563,12 +562,6 @@ extern {
563562
mibp: *mut ::c_int,
564563
sizep: *mut ::size_t)
565564
-> ::c_int;
566-
#[cfg(not(target_os = "dragonfly"))]
567-
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
568-
-> ::c_int;
569-
#[cfg(target_os = "dragonfly")]
570-
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
571-
-> ::c_int;
572565
pub fn shm_open(name: *const ::c_char, oflag: ::c_int, mode: ::mode_t)
573566
-> ::c_int;
574567
pub fn sysctl(name: *const ::c_int,
@@ -584,11 +577,6 @@ extern {
584577
newp: *const ::c_void,
585578
newlen: ::size_t)
586579
-> ::c_int;
587-
#[cfg(not(target_os = "dragonfly"))]
588-
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
589-
#[cfg(target_os = "dragonfly")]
590-
pub fn clock_gettime(clk_id: ::uint64_t, tp: *mut ::timespec) -> ::c_int;
591-
592580
pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char);
593581
pub fn sched_setscheduler(pid: ::pid_t, policy: ::c_int, param: *const sched_param) -> ::c_int;
594582
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;

src/unix/bsd/mod.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ pub type sa_family_t = u8;
1010
pub type pthread_t = ::uintptr_t;
1111
pub type nfds_t = ::c_uint;
1212

13-
#[cfg(not(target_os = "dragonfly"))]
14-
macro_rules! utsname_len { () => (256) }
15-
#[cfg(target_os = "dragonfly")]
16-
macro_rules! utsname_len { () => (32) }
17-
1813
s! {
1914
pub struct sockaddr {
2015
pub sa_len: u8,
@@ -90,11 +85,26 @@ s! {
9085
}
9186

9287
pub struct utsname {
93-
pub sysname: [::c_char; utsname_len!()],
94-
pub nodename: [::c_char; utsname_len!()],
95-
pub release: [::c_char; utsname_len!()],
96-
pub version: [::c_char; utsname_len!()],
97-
pub machine: [::c_char; utsname_len!()],
88+
#[cfg(not(target_os = "dragonfly"))]
89+
pub sysname: [::c_char; 256],
90+
#[cfg(target_os = "dragonfly")]
91+
pub sysname: [::c_char; 32],
92+
#[cfg(not(target_os = "dragonfly"))]
93+
pub nodename: [::c_char; 256],
94+
#[cfg(target_os = "dragonfly")]
95+
pub nodename: [::c_char; 32],
96+
#[cfg(not(target_os = "dragonfly"))]
97+
pub release: [::c_char; 256],
98+
#[cfg(target_os = "dragonfly")]
99+
pub release: [::c_char; 32],
100+
#[cfg(not(target_os = "dragonfly"))]
101+
pub version: [::c_char; 256],
102+
#[cfg(target_os = "dragonfly")]
103+
pub version: [::c_char; 32],
104+
#[cfg(not(target_os = "dragonfly"))]
105+
pub machine: [::c_char; 256],
106+
#[cfg(target_os = "dragonfly")]
107+
pub machine: [::c_char; 32],
98108
}
99109

100110
pub struct msghdr {

0 commit comments

Comments
 (0)