@@ -8,7 +8,11 @@ fn main() {
88 test_localtime_r_gmt ( ) ;
99 test_localtime_r_pst ( ) ;
1010 test_localtime_r_epoch ( ) ;
11- test_localtime_r_future ( ) ;
11+ // Architecture-specific tests
12+ #[ cfg( target_pointer_width = "32" ) ]
13+ test_localtime_r_future_32b ( ) ;
14+ #[ cfg( target_pointer_width = "64" ) ]
15+ test_localtime_r_future_64b ( ) ;
1216}
1317
1418/// Tests whether clock support exists at all
@@ -192,10 +196,14 @@ fn test_localtime_r_epoch() {
192196}
193197
194198// Future date test (testing large values)
195- fn test_localtime_r_future ( ) {
199+ #[ cfg( target_pointer_width = "64" ) ]
200+ fn test_localtime_r_future_64b ( ) {
196201 let key = "TZ" ;
197202 env:: set_var ( key, "GMT" ) ;
198- const TIME_SINCE_EPOCH : libc:: time_t = 2524608000 ; // 2050-01-01 00:00:00
203+
204+ // Using 2050-01-01 00:00:00 for 64-bit systems
205+ // value that's safe for 64-bit time_t
206+ const TIME_SINCE_EPOCH : libc:: time_t = 2524608000 ;
199207 let custom_time_ptr = & TIME_SINCE_EPOCH ;
200208 let mut tm = create_empty_tm ( ) ;
201209
@@ -206,7 +214,7 @@ fn test_localtime_r_future() {
206214 assert_eq ! ( tm. tm_hour, 0 ) ;
207215 assert_eq ! ( tm. tm_mday, 1 ) ;
208216 assert_eq ! ( tm. tm_mon, 0 ) ;
209- assert_eq ! ( tm. tm_year, 150 ) ;
217+ assert_eq ! ( tm. tm_year, 150 ) ; // 2050 - 1900
210218 assert_eq ! ( tm. tm_wday, 6 ) ; // Saturday
211219 assert_eq ! ( tm. tm_yday, 0 ) ;
212220 assert_eq ! ( tm. tm_isdst, -1 ) ;
@@ -227,3 +235,44 @@ fn test_localtime_r_future() {
227235 assert ! ( ptr:: eq( res, & mut tm) ) ;
228236 env:: remove_var ( key) ;
229237}
238+
239+ #[ cfg( target_pointer_width = "32" ) ]
240+ fn test_localtime_r_future_32b ( ) {
241+ let key = "TZ" ;
242+ env:: set_var ( key, "GMT" ) ;
243+
244+ // Using 2030-01-01 00:00:00 for 32-bit systems
245+ // Safe value within i32 range
246+ const TIME_SINCE_EPOCH : libc:: time_t = 1893456000 ;
247+ let custom_time_ptr = & TIME_SINCE_EPOCH ;
248+ let mut tm = create_empty_tm ( ) ;
249+
250+ let res = unsafe { libc:: localtime_r ( custom_time_ptr, & mut tm) } ;
251+
252+ // Verify 2030-01-01 00:00:00
253+ assert_eq ! ( tm. tm_sec, 0 ) ;
254+ assert_eq ! ( tm. tm_min, 0 ) ;
255+ assert_eq ! ( tm. tm_hour, 0 ) ;
256+ assert_eq ! ( tm. tm_mday, 1 ) ;
257+ assert_eq ! ( tm. tm_mon, 0 ) ;
258+ assert_eq ! ( tm. tm_year, 130 ) ; // 2030 - 1900
259+ assert_eq ! ( tm. tm_wday, 2 ) ; // Tuesday
260+ assert_eq ! ( tm. tm_yday, 0 ) ;
261+ assert_eq ! ( tm. tm_isdst, -1 ) ;
262+
263+ #[ cfg( any(
264+ target_os = "linux" ,
265+ target_os = "macos" ,
266+ target_os = "freebsd" ,
267+ target_os = "android"
268+ ) ) ]
269+ {
270+ assert_eq ! ( tm. tm_gmtoff, 0 ) ;
271+ unsafe {
272+ assert_eq ! ( std:: ffi:: CStr :: from_ptr( tm. tm_zone) . to_str( ) . unwrap( ) , "+00" ) ;
273+ }
274+ }
275+
276+ assert ! ( ptr:: eq( res, & mut tm) ) ;
277+ env:: remove_var ( key) ;
278+ }
0 commit comments