Skip to content

Commit 021159a

Browse files
committed
Merge pull request rust-lang#33 from alexcrichton/time
Add time bindings
2 parents 96450de + 568705e commit 021159a

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

libc-test/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ fn main() {
8282

8383
if android {
8484
cfg.header("arpa/inet.h");
85+
cfg.header("time64.h");
8586
} else if !windows {
8687
cfg.header("glob.h");
8788
cfg.header("ifaddrs.h");
@@ -232,6 +233,10 @@ fn main() {
232233
"dlerror" if android => true, // const-ness is added
233234
"dladdr" if musl => true, // const-ness only added recently
234235

236+
// OSX has 'struct tm *const' which we can't actually represent in
237+
// Rust, but is close enough to *mut
238+
"timegm" if apple => true,
239+
235240
_ => false,
236241
}
237242
});

src/unix/bsd/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ s! {
6666
pub struct fd_set {
6767
fds_bits: [i32; FD_SETSIZE / 32],
6868
}
69+
70+
pub struct tm {
71+
pub tm_sec: ::c_int,
72+
pub tm_min: ::c_int,
73+
pub tm_hour: ::c_int,
74+
pub tm_mday: ::c_int,
75+
pub tm_mon: ::c_int,
76+
pub tm_year: ::c_int,
77+
pub tm_wday: ::c_int,
78+
pub tm_yday: ::c_int,
79+
pub tm_isdst: ::c_int,
80+
pub tm_gmtoff: ::c_long,
81+
pub tm_zone: *mut ::c_char,
82+
}
6983
}
7084

7185
pub const FIOCLEX: ::c_ulong = 0x20006601;

src/unix/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ extern {
450450
res: *mut *mut addrinfo) -> ::c_int;
451451
pub fn freeaddrinfo(res: *mut addrinfo);
452452
pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
453+
454+
pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
455+
pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
456+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
457+
link_name = "mktime$UNIX2003")]
458+
pub fn mktime(tm: *mut tm) -> time_t;
453459
}
454460

455461
// TODO: get rid of this #[cfg(not(...))]
@@ -551,6 +557,7 @@ extern {
551557
offset: ::off_t,
552558
whence: ::c_int) -> ::c_int;
553559
pub fn ftello(stream: *mut ::FILE) -> ::off_t;
560+
pub fn timegm(tm: *mut ::tm) -> time_t;
554561
}
555562

556563
cfg_if! {

src/unix/notbsd/android/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub type socklen_t = i32;
1919
pub type pthread_t = c_long;
2020
pub type pthread_mutexattr_t = ::c_long;
2121
pub type sigset_t = c_ulong;
22+
pub type time64_t = i64;
2223

2324
s! {
2425
pub struct stat {
@@ -225,6 +226,7 @@ extern {
225226
serv: *mut ::c_char,
226227
sevlen: ::size_t,
227228
flags: ::c_int) -> ::c_int;
229+
pub fn timegm64(tm: *const ::tm) -> time64_t;
228230
}
229231

230232
cfg_if! {

src/unix/notbsd/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ s! {
7272
pub struct fd_set {
7373
fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE],
7474
}
75+
76+
pub struct tm {
77+
pub tm_sec: ::c_int,
78+
pub tm_min: ::c_int,
79+
pub tm_hour: ::c_int,
80+
pub tm_mday: ::c_int,
81+
pub tm_mon: ::c_int,
82+
pub tm_year: ::c_int,
83+
pub tm_wday: ::c_int,
84+
pub tm_yday: ::c_int,
85+
pub tm_isdst: ::c_int,
86+
pub tm_gmtoff: ::c_long,
87+
pub tm_zone: *const ::c_char,
88+
}
7589
}
7690

7791
// intentionally not public, only used for fd_set

0 commit comments

Comments
 (0)