#include #include #include "parselib.h" static struct state s; static int parse(unsigned char *x) {return (x[0]<<24) | (x[1]<<16) | (x[2]<<8) | x[3];} static time_t time_offset(time_t *t, int forward) { unsigned char *T = (unsigned char *)s.buffirst, *tmp,*x; size_t L = s.buflen; time_t i, k, res, tzh_timecnt; if (!T || L<44) return 0; tzh_timecnt = parse(T+32); tmp=T+44; x=tmp+tzh_timecnt*4; for (i=tzh_timecnt-1; 0<=i; --i) { k = parse(tmp+i*4); if (forward) if (*t < k) continue; res = parse(x +tzh_timecnt +6*(unsigned char)x[i]); if (forward) return res; else if (k+res <= *t) return -res; } return 0; } time_t get_tz(time_t *t, int forward) /*EXTRACT_INCL*/{ if (forward==-1) { __end_parse(&s); s.cur=0; return 0; } if (!s.cur) { __prepare_parse("/etc/localtime",&s); s.cur=1; } return time_offset(t,forward); }