aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c
diff options
context:
space:
mode:
Diffstat (limited to 'riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c')
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c
new file mode 100644
index 0000000..94b42e1
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c
@@ -0,0 +1,42 @@
+#include <unistd.h>
+#include <fcntl.h>
+#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);
+}