Merge branch 'ctime_r' into 'master'
Add test for ctime_r(), replace mem::uninitialized() See merge request redox-os/relibc!273
This commit is contained in:
+15
-2
@@ -141,9 +141,22 @@ pub unsafe extern "C" fn ctime(clock: *const time_t) -> *mut c_char {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ctime_r(clock: *const time_t, buf: *mut c_char) -> *mut c_char {
|
||||
let mut tm1: tm = core::mem::uninitialized();
|
||||
// Using MaybeUninit<tm> seems to cause a panic during the build process
|
||||
let mut tm1 = 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: core::ptr::null_mut(),
|
||||
};
|
||||
localtime_r(clock, &mut tm1);
|
||||
asctime_r(&mut tm1, buf)
|
||||
asctime_r(&tm1, buf)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -6,3 +6,4 @@ Year 70, Day of year: 0, Month 0, Day of month: 1, Day of week: 4, 0:0:0
|
||||
Year 70, Day of year: 0, Month 0, Day of month: 1, Day of week: 4, 0:0:1
|
||||
Year 118, Day of year: 193, Month 6, Day of month: 13, Day of week: 5, 4:9:10
|
||||
Fri Jul 13 06:03:43 2018
|
||||
Fri Jul 13 06:03:43 2018
|
||||
|
||||
@@ -17,4 +17,15 @@ int main(void) {
|
||||
|
||||
time_t input = 1531461823;
|
||||
fputs(ctime(&input), stdout); // Omit newline
|
||||
|
||||
char ctime_r_buffer[26];
|
||||
/* ctime_r() generally returns the address of the provided buffer,
|
||||
* but may return NULL upon error according to the spec. */
|
||||
char *ctime_r_result = ctime_r(&input, ctime_r_buffer);
|
||||
if (ctime_r_result == ctime_r_buffer) {
|
||||
fputs(ctime_r_result, stdout);
|
||||
}
|
||||
else {
|
||||
printf("Unexpected pointer from ctime_r: %p\n", ctime_r_result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user