1#include "libc.h" 2#include "time_impl.h" 3#include <errno.h> 4 5struct tm* __gmtime_r(const time_t* restrict, struct tm* restrict); 6 7struct tm* __localtime_r(const time_t* restrict t, struct tm* restrict tm) { 8 //TODO(kulakowski): remove when timezone lookup works 9 return __gmtime_r(t, tm); 10 11 /* Reject time_t values whose year would overflow int because 12 * __secs_to_zone cannot safely handle them. */ 13 if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) { 14 errno = EOVERFLOW; 15 return 0; 16 } 17 __secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone); 18 if (__secs_to_tm((long long)*t + tm->__tm_gmtoff, tm) < 0) { 19 errno = EOVERFLOW; 20 return 0; 21 } 22 return tm; 23} 24 25weak_alias(__localtime_r, localtime_r); 26