summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-11-03 14:18:52 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-11-04 14:18:07 -0800
commit568705e830b816047fc93a035448dfbb3eecdadc (patch)
tree9ab1d8de7ea0bda3ddbcb5c2501273a135526635
parent6d817ed05af919cc3dd5ea2889018eaa48d87ab9 (diff)
downloadrust-libc-568705e830b816047fc93a035448dfbb3eecdadc.tar.gz
Add time bindings
-rw-r--r--libc-test/build.rs5
-rw-r--r--src/unix/bsd/mod.rs14
-rw-r--r--src/unix/mod.rs7
-rw-r--r--src/unix/notbsd/android/mod.rs2
-rw-r--r--src/unix/notbsd/mod.rs14
5 files changed, 42 insertions, 0 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs
index ee68b64fd0..f1b1bd470d 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -82,6 +82,7 @@ fn main() {
if android {
cfg.header("arpa/inet.h");
+ cfg.header("time64.h");
} else if !windows {
cfg.header("glob.h");
cfg.header("ifaddrs.h");
@@ -232,6 +233,10 @@ fn main() {
"dlerror" if android => true, // const-ness is added
"dladdr" if musl => true, // const-ness only added recently
+ // OSX has 'struct tm *const' which we can't actually represent in
+ // Rust, but is close enough to *mut
+ "timegm" if apple => true,
+
_ => false,
}
});
diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs
index 03fe18c2ea..40b0ee704c 100644
--- a/src/unix/bsd/mod.rs
+++ b/src/unix/bsd/mod.rs
@@ -66,6 +66,20 @@ s! {
pub struct fd_set {
fds_bits: [i32; FD_SETSIZE / 32],
}
+
+ pub struct tm {
+ pub tm_sec: ::c_int,
+ pub tm_min: ::c_int,
+ pub tm_hour: ::c_int,
+ pub tm_mday: ::c_int,
+ pub tm_mon: ::c_int,
+ pub tm_year: ::c_int,
+ pub tm_wday: ::c_int,
+ pub tm_yday: ::c_int,
+ pub tm_isdst: ::c_int,
+ pub tm_gmtoff: ::c_long,
+ pub tm_zone: *mut ::c_char,
+ }
}
pub const FIOCLEX: ::c_ulong = 0x20006601;
diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index fb028971a5..b72e7916c7 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -446,6 +446,12 @@ extern {
res: *mut *mut addrinfo) -> ::c_int;
pub fn freeaddrinfo(res: *mut addrinfo);
pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
+
+ pub fn gmtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
+ pub fn localtime_r(time_p: *const time_t, result: *mut tm) -> *mut tm;
+ #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
+ link_name = "mktime$UNIX2003")]
+ pub fn mktime(tm: *mut tm) -> time_t;
}
// TODO: get rid of this #[cfg(not(...))]
@@ -547,6 +553,7 @@ extern {
offset: ::off_t,
whence: ::c_int) -> ::c_int;
pub fn ftello(stream: *mut ::FILE) -> ::off_t;
+ pub fn timegm(tm: *mut ::tm) -> time_t;
}
cfg_if! {
diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs
index 37678f4ebb..2cca05e457 100644
--- a/src/unix/notbsd/android/mod.rs
+++ b/src/unix/notbsd/android/mod.rs
@@ -19,6 +19,7 @@ pub type socklen_t = i32;
pub type pthread_t = c_long;
pub type pthread_mutexattr_t = ::c_long;
pub type sigset_t = c_ulong;
+pub type time64_t = i64;
s! {
pub struct stat {
@@ -225,6 +226,7 @@ extern {
serv: *mut ::c_char,
sevlen: ::size_t,
flags: ::c_int) -> ::c_int;
+ pub fn timegm64(tm: *const ::tm) -> time64_t;
}
cfg_if! {
diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs
index ed84bef247..cb4d0c0a30 100644
--- a/src/unix/notbsd/mod.rs
+++ b/src/unix/notbsd/mod.rs
@@ -72,6 +72,20 @@ s! {
pub struct fd_set {
fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE],
}
+
+ pub struct tm {
+ pub tm_sec: ::c_int,
+ pub tm_min: ::c_int,
+ pub tm_hour: ::c_int,
+ pub tm_mday: ::c_int,
+ pub tm_mon: ::c_int,
+ pub tm_year: ::c_int,
+ pub tm_wday: ::c_int,
+ pub tm_yday: ::c_int,
+ pub tm_isdst: ::c_int,
+ pub tm_gmtoff: ::c_long,
+ pub tm_zone: *const ::c_char,
+ }
}
// intentionally not public, only used for fd_set