localtm_from_ltm64.c (585B)
1 /* ISC license. */ 2 3 #include <skalibs/sysdeps.h> 4 #include <skalibs/bsdsnowflake.h> 5 #include <errno.h> 6 #include <time.h> 7 #include <skalibs/uint64.h> 8 #include <skalibs/tai.h> 9 #include <skalibs/djbtime.h> 10 11 int localtm_from_ltm64 (struct tm *l, uint64_t uu, int tzh) 12 { 13 time_t u ; 14 if (uu < TAI_MAGIC) return (errno = EINVAL, 0) ; 15 uu -= TAI_MAGIC ; 16 #if SKALIBS_SIZEOFTIME != 8 17 if (uu > 0xFFFFFFFFUL) return (errno = EOVERFLOW, 0) ; 18 #endif 19 u = (time_t)uu - !!(tzh & 2) ; 20 if (tzh & 1 ? !localtime_r(&u, l) : !gmtime_r(&u, l)) return 0 ; 21 if (tzh & 2) l->tm_sec++ ; 22 return 1 ; 23 }