From 4c58691372b6b074e61b2d5d37f2ce66e32f6381 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Sun, 13 Apr 1997 22:13:05 +0000 Subject: [PATCH] new file git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1571 ec53bebd-3082-4978-b11e-865c3cabbd6b --- admin/admin_locl.h | 25 +++++++++++++++++++++++++ lib/asn1/timegm.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 admin/admin_locl.h create mode 100644 lib/asn1/timegm.c diff --git a/admin/admin_locl.h b/admin/admin_locl.h new file mode 100644 index 000000000..8c1b9ff0f --- /dev/null +++ b/admin/admin_locl.h @@ -0,0 +1,25 @@ +/* + * $Id$ + */ + +#ifndef __ADMIN_LOCL_H__ +#define __ADMIN_LOCL_H__ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hdb.h" + + +#endif /* __ADMIN_LOCL_H__ */ diff --git a/lib/asn1/timegm.c b/lib/asn1/timegm.c new file mode 100644 index 000000000..af3240ffb --- /dev/null +++ b/lib/asn1/timegm.c @@ -0,0 +1,33 @@ +#include "asn1_locl.h" + +RCSID("$Id$"); + +static int +is_leap(unsigned y) +{ + return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); +} + +time_t +timegm (struct tm *tm) +{ + static const int ndays[2][12] ={ + {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, + {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; + time_t res = 0; + int i; + + for (i = 70; i < tm->tm_year; ++i) + res += is_leap(i) ? 366 : 365; + + for (i = 0; i < tm->tm_mon; ++i) + res += ndays[is_leap(tm->tm_year)][i]; + res += tm->tm_mday - 1; + res *= 24; + res += tm->tm_hour; + res *= 60; + res += tm->tm_min; + res *= 60; + res += tm->tm_sec; + return res; +}