Skip to content
Snippets Groups Projects
Commit 8015878a authored by Marat Safin's avatar Marat Safin
Browse files

use static variable for gmtime

parent 2b21dca5
No related branches found
No related tags found
1 merge request!112add gmtime and difftime
//! time implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html
#![no_std]
#![feature(const_fn)]
extern crate platform;
......@@ -34,23 +35,22 @@ pub struct tm {
pub tm_zone: *const c_char,
}
impl Default for tm {
fn default() -> tm {
tm {
tm_sec: 0,
tm_min: 0,
tm_hour: 0,
tm_mday: 0,
tm_mon: 0,
tm_year: 0,
tm_wday: 0,
tm_yday: 0,
tm_isdst: 0,
tm_gmtoff: 0,
tm_zone: UTC,
}
}
}
unsafe impl Sync for tm {}
// The C Standard says that localtime and gmtime return the same pointer.
static mut TM: tm = tm {
tm_sec: 0,
tm_min: 0,
tm_hour: 0,
tm_mday: 0,
tm_mon: 0,
tm_year: 0,
tm_wday: 0,
tm_yday: 0,
tm_isdst: 0,
tm_gmtoff: 0,
tm_zone: UTC,
};
#[repr(C)]
pub struct itimerspec {
......@@ -112,8 +112,7 @@ pub extern "C" fn getdate(string: *const c_char) -> tm {
#[no_mangle]
pub extern "C" fn gmtime(timer: *const time_t) -> *mut tm {
let mut result: tm = Default::default();
return gmtime_r(timer, &mut result);
unsafe { gmtime_r(timer, &mut TM) }
}
#[no_mangle]
......
......@@ -9,6 +9,14 @@ int main(int argc, char** argv) {
.tm_wday = 4, .tm_yday = 0, .tm_isdst = 0, .tm_gmtoff = 0, .tm_zone = "UTC" };
tm *info = gmtime(&a);
if (info->tm_sec != expected.tm_sec || info->tm_min != expected.tm_min ||
info->tm_hour != expected.tm_hour || info->tm_mday != expected.tm_mday ||
info->tm_year != expected.tm_year || info->tm_wday != expected.tm_wday ||
info->tm_yday != expected.tm_yday || info->tm_isdst != expected.tm_isdst ||
info->tm_gmtoff != expected.tm_gmtoff || strcmp(info->tm_zone, expected.tm_zone) != 0) {
exit(1);
}
if (info->tm_sec != expected.tm_sec || info->tm_min != expected.tm_min ||
info->tm_hour != expected.tm_hour || info->tm_mday != expected.tm_mday ||
info->tm_year != expected.tm_year || info->tm_wday != expected.tm_wday ||
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment