#include "krb.h"
#include <sys/types.h>
#include <time.h>
#include <sys/timeb.h>
#include <stdio.h>
#include <windows.h>
#include <dos.h>
#ifdef _WIN32
unsigned KRB4_32
win_time_gmt_unixsec (usecptr)
unsigned KRB4_32 *usecptr;
{
struct _timeb timeptr;
_ftime(&timeptr);
if (usecptr)
*usecptr = timeptr.millitm * 1000;
return timeptr.time + CONVERT_TIME_EPOCH;
}
#else
unsigned KRB4_32
win_time_gmt_unixsec (usecptr)
unsigned KRB4_32 *usecptr;
{
struct tm tm;
union _REGS inregs;
union _REGS outregs;
struct _timeb now;
time_t time;
_ftime(&now);
#if 0
if (usecptr)
*usecptr = now.millitm * 1000;
#endif
memset(&inregs, 0, sizeof(inregs));
inregs.h.ah = 2;
_int86(0x1a, &inregs, &outregs);
tm.tm_sec = 10 * ((outregs.h.dh & 0xF0) >> 4) + (outregs.h.dh & 0x0F);
tm.tm_min = 10 * ((outregs.h.cl & 0xF0) >> 4) + (outregs.h.cl & 0x0F);
tm.tm_hour = 10 * ((outregs.h.ch & 0xF0) >> 4) + (outregs.h.ch & 0x0F);
memset(&inregs, 0, sizeof(inregs));
inregs.h.ah = 4;
_int86(0x1a, &inregs, &outregs);
tm.tm_mday = 10 * ((outregs.h.dl & 0xF0) >> 4) + (outregs.h.dl & 0x0F);
tm.tm_mon = 10 * ((outregs.h.dh & 0xF0) >> 4) + (outregs.h.dh & 0x0F) - 1;
tm.tm_year = 10 * ((outregs.h.cl & 0xF0) >> 4) + (outregs.h.cl & 0x0F);
tm.tm_year += 100 * ((10 * (outregs.h.ch & 0xF0) >> 4)
+ (outregs.h.ch & 0x0F) - 19);
tm.tm_wday = 0;
tm.tm_yday = 0;
tm.tm_isdst = now.dstflag;
time = mktime(&tm);
if (usecptr)
*usecptr = 0;
return time + CONVERT_TIME_EPOCH;
}
#endif
static struct tm jan_1_70 = {0, 0, 0, 1, 0, 70};
static long epoch = 0;
static int epoch_set = 0;
long
win_time_get_epoch()
{
if (!epoch_set) {
epoch = - mktime (&jan_1_70);
epoch += timezone;
epoch_set = 1;
}
return epoch;
}