diff --git a/rules/time/tgt_refcount.rs b/rules/time/tgt_refcount.rs index 808c5e56..bd49d01c 100644 --- a/rules/time/tgt_refcount.rs +++ b/rules/time/tgt_refcount.rs @@ -63,6 +63,28 @@ fn f4(a0: Ptr<::libc::time_t>, a1: Ptr) -> Ptr { } } +fn f5(a0: Ptr<::libc::time_t>, a1: Ptr) -> Ptr { + let __res = a1.clone(); + match jiff::Timestamp::from_second(a0.read()) { + Ok(__ts) => { + let __dt = __ts.to_zoned(jiff::tz::TimeZone::system()); + let __info = __dt.time_zone().to_offset_info(__ts); + let __zone: Vec = __info.abbreviation().bytes().chain([0]).collect(); + let __isdst = if __info.dst().is_dst() { 1 } else { 0 }; + __res.with_mut(|__tm| { + *__tm = Tm::from_zoned(&__dt); + *__tm.tm_isdst.borrow_mut() = __isdst; + *__tm.tm_zone.borrow_mut() = Ptr::alloc_array(__zone.into_boxed_slice()); + }); + __res + } + Err(_) => { + libcc2rs::cpp2rust_errno().write(::libc::EOVERFLOW); + Ptr::null() + } + } +} + fn f6(a0: Ptr, a1: usize, a2: Ptr, a3: Ptr) -> usize { let __dt = a3.with(|__tm| __tm.to_civil()); let __text = match __dt { diff --git a/tests/unit/out/refcount/sys_time.rs b/tests/unit/out/refcount/sys_time.rs index dd18d962..a0f8ac7f 100644 --- a/tests/unit/out/refcount/sys_time.rs +++ b/tests/unit/out/refcount/sys_time.rs @@ -92,7 +92,57 @@ pub fn test_gmtime_r_2() { ({ print_tm_1(1721126096_i64) }); ({ print_tm_1(4102444800_i64) }); } -pub fn test_strftime_3() { +pub fn print_local_tm_3(t: i64) { + let t: Value = Rc::new(RefCell::new(t)); + let tm: Value = Rc::new(RefCell::new(Default::default())); + assert!( + (((!(({ + let __res = (tm.as_pointer()).clone(); + match jiff::Timestamp::from_second((t.as_pointer()).read()) { + Ok(__ts) => { + let __dt = __ts.to_zoned(jiff::tz::TimeZone::system()); + let __info = __dt.time_zone().to_offset_info(__ts); + let __zone: Vec = __info.abbreviation().bytes().chain([0]).collect(); + let __isdst = if __info.dst().is_dst() { 1 } else { 0 }; + __res.with_mut(|__tm| { + *__tm = Tm::from_zoned(&__dt); + *__tm.tm_isdst.borrow_mut() = __isdst; + *__tm.tm_zone.borrow_mut() = Ptr::alloc_array(__zone.into_boxed_slice()); + }); + __res + } + Err(_) => { + libcc2rs::cpp2rust_errno().write(::libc::EOVERFLOW); + Ptr::null() + } + } + }) + .is_null())) as i32) + != 0) + ); + println!( + "{}-{}-{} {}:{}:{} wday={} yday={} {} gmtoff={} isdst={}", + (*(*tm.borrow()).tm_year.borrow()), + (*(*tm.borrow()).tm_mon.borrow()), + (*(*tm.borrow()).tm_mday.borrow()), + (*(*tm.borrow()).tm_hour.borrow()), + (*(*tm.borrow()).tm_min.borrow()), + (*(*tm.borrow()).tm_sec.borrow()), + (*(*tm.borrow()).tm_wday.borrow()), + (*(*tm.borrow()).tm_yday.borrow()), + (*(*tm.borrow()).tm_zone.borrow()), + (*(*tm.borrow()).tm_gmtoff.borrow()), + (*(*tm.borrow()).tm_isdst.borrow()) + ); +} +pub fn test_localtime_r_4() { + ({ print_local_tm_3(0_i64) }); + ({ print_local_tm_3(951782400_i64) }); + ({ print_local_tm_3(1704067199_i64) }); + ({ print_local_tm_3(1721126096_i64) }); + ({ print_local_tm_3(1735689600_i64) }); +} +pub fn test_strftime_5() { let t: Value = Rc::new(RefCell::new(1721126096_i64)); let tm: Value = Rc::new(RefCell::new(Default::default())); assert!( @@ -263,6 +313,7 @@ pub fn main() { fn main_0() -> i32 { ({ test_time_0() }); ({ test_gmtime_r_2() }); - ({ test_strftime_3() }); + ({ test_localtime_r_4() }); + ({ test_strftime_5() }); return 0; } diff --git a/tests/unit/out/unsafe/sys_time.rs b/tests/unit/out/unsafe/sys_time.rs index bd511f1d..2bcfd93c 100644 --- a/tests/unit/out/unsafe/sys_time.rs +++ b/tests/unit/out/unsafe/sys_time.rs @@ -54,7 +54,42 @@ pub unsafe fn test_gmtime_r_2() { (unsafe { print_tm_1(1721126096_i64) }); (unsafe { print_tm_1(4102444800_i64) }); } -pub unsafe fn test_strftime_3() { +pub unsafe fn print_local_tm_3(mut t: i64) { + let mut tm: ::libc::tm = unsafe { std::mem::zeroed() }; + assert!( + (((!((libc::localtime_r( + (&mut t as *mut i64).cast_const(), + (&mut tm as *mut ::libc::tm) + )) + .is_null())) as i32) + != 0) + ); + printf( + (c"%d-%d-%d %d:%d:%d wday=%d yday=%d %s gmtoff=%ld isdst=%d\n" + .as_ptr() + .cast_mut()) + .cast_const() as *const i8, + tm.tm_year, + tm.tm_mon, + tm.tm_mday, + tm.tm_hour, + tm.tm_min, + tm.tm_sec, + tm.tm_wday, + tm.tm_yday, + tm.tm_zone, + tm.tm_gmtoff, + tm.tm_isdst, + ); +} +pub unsafe fn test_localtime_r_4() { + (unsafe { print_local_tm_3(0_i64) }); + (unsafe { print_local_tm_3(951782400_i64) }); + (unsafe { print_local_tm_3(1704067199_i64) }); + (unsafe { print_local_tm_3(1721126096_i64) }); + (unsafe { print_local_tm_3(1735689600_i64) }); +} +pub unsafe fn test_strftime_5() { let mut t: i64 = 1721126096_i64; let mut tm: ::libc::tm = unsafe { std::mem::zeroed() }; assert!( @@ -137,6 +172,7 @@ pub fn main() { unsafe fn main_0() -> i32 { (unsafe { test_time_0() }); (unsafe { test_gmtime_r_2() }); - (unsafe { test_strftime_3() }); + (unsafe { test_localtime_r_4() }); + (unsafe { test_strftime_5() }); return 0; } diff --git a/tests/unit/sys_time.c b/tests/unit/sys_time.c index daa3e01e..51983f43 100644 --- a/tests/unit/sys_time.c +++ b/tests/unit/sys_time.c @@ -34,6 +34,22 @@ static void test_gmtime_r(void) { print_tm(4102444800); } +static void print_local_tm(time_t t) { + struct tm tm; + assert(localtime_r(&t, &tm) != NULL); + printf("%d-%d-%d %d:%d:%d wday=%d yday=%d %s gmtoff=%ld isdst=%d\n", + tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, + tm.tm_wday, tm.tm_yday, tm.tm_zone, tm.tm_gmtoff, tm.tm_isdst); +} + +static void test_localtime_r(void) { + print_local_tm(0); + print_local_tm(951782400); + print_local_tm(1704067199); + print_local_tm(1721126096); + print_local_tm(1735689600); +} + static void test_strftime(void) { time_t t = 1721126096; struct tm tm; @@ -54,6 +70,7 @@ static void test_strftime(void) { int main(void) { test_time(); test_gmtime_r(); + test_localtime_r(); test_strftime(); return 0; }