diff options
author | Robert de Bath <rdebath@poboxes.com> | 1996-11-03 22:33:35 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:33:35 +0200 |
commit | c218c617b5be443b7968308506969ad2b726d73c (patch) | |
tree | 0051f396af56133d24fcf2ab757fabc78c1a09bf /libc/msdos/time.c | |
parent | 0936b9aeab611665645a4e6bafaded7ca76dd189 (diff) | |
parent | 0d2fbe9b1bd284ce2cad55be17e8f2c896031a25 (diff) | |
download | dev86-c218c617b5be443b7968308506969ad2b726d73c.tar.gz |
Import Dev86src-0.0.8.tar.gzv0.0.8
Diffstat (limited to 'libc/msdos/time.c')
-rw-r--r-- | libc/msdos/time.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/libc/msdos/time.c b/libc/msdos/time.c new file mode 100644 index 0000000..0a66da8 --- /dev/null +++ b/libc/msdos/time.c @@ -0,0 +1,63 @@ + +#include <time.h> + +static int mdays[13] = { 0,31,31+28,31+28+31,31+28+31+30, + 31+28+31+30+31,31+28+31+30+31+30,31+28+31+30+31+30+31, + 31+28+31+30+31+30+31+31,31+28+31+30+31+30+31+31+30, + 31+28+31+30+31+30+31+31+30+31,31+28+31+30+31+30+31+31+30+31+30, + 365 }; + +#define SECSPERHOUR (60*60) +#define SECSPERDAY (SECSPERHOUR*24L) + +/**************************************** + * Return the number of seconds that have elapsed since the start + * of 1970. + * Input: + * timer pointer to where to store result (or NULL) + * Output: + * *timer = result (unless timer == NULL) + * Returns: + * time + */ + +static long get_time(ah) +{ +#asm +#if !__FIST_ARG_IN_AX__ + mov bx,sp + mov ax,[bx+2] +#endif + mov ah,al + int $21 + mov ax,dx + mov dx,cx +#endasm +} + +time_t time(timer) +time_t *timer; +{ + unsigned day,month,year; + long rv; + time_t t; + + rv = get_time(0x2C); + rv >>= 8; t = (rv & 0xFF); + rv >>= 8; t += (rv & 0xFF)*60; + rv >>= 8; t += (rv & 0xFF)*3600; + + rv = get_time(0x2A); + day = (rv & 0xFF); + rv >>= 8; month = (rv & 0xFF) -1; + rv >>= 8; year = (rv & 0xFFFF) - 1970; + + if (month <= 1 || year & 3) /* if before Feb or not a leap year */ + day--; /* don't add day for leap year */ + day += mdays[month]; /* day in year */ + day += (year + 3) >> 2; /* add a day for each leap year */ + t += ((year * 365L) + day) * SECSPERDAY; + if (timer) + *timer = t; + return t; +} |