home *** CD-ROM | disk | FTP | other *** search
- /*
- Stuff 2.0.
-
- Checksum: 4047342816 (verify with "brik")
-
- (C) Copyright 1988 Rahul Dhesi. Permission is granted to copy and
- distribute this file in modified or unmodified form, whether for
- noncommercial or commercial use, provided (a) this copyright notice
- is preserved, (b) no attempt is made to restrict redistribution of
- this file, and (c) this file is not distributed as part of any
- collection whose redistribution is restricted by a compilation
- copyright.
- */
-
- #include "stuff.h"
- #include <stdio.h>
- #include <dos.h>
- #include <fcntl.h>
- #include <io.h>
- /*
- converts msdos format date/time into unix format
- */
-
- long mstonix (unsigned date, unsigned time)
- {
- int year, month, day, hour, min, sec, daycount;
- long longtime;
- /* no. of days to beginning of month for each month */
- static int dsboy[12] = { 0, 31, 59, 90, 120, 151, 181, 212,
- 243, 273, 304, 334};
-
- if (date == 0 && time == 0) /* special case! */
- return (0L);
-
- year = (((unsigned int) date >> 9) & 0x7f) + 1980;
- month = ((unsigned int) date >> 5) & 0x0f;
- day = date & 0x1f;
-
- hour = ((unsigned int) time >> 11)& 0x1f;
- min = ((unsigned int) time >> 5) & 0x3f;
- sec = ((unsigned int) time & 0x1f) * 2;
-
- /*
- DEBUG and leap year fixes thanks to Mark Alexander
- <uunet!amdahl!drivax!alexande>
- */
- #if 0
- #ifdef DEBUG
- printf ("mstonix: year=%d month=%d day=%d hour=%d min=%d sec=%d\n",
- year, month, day, hour, min, sec);
- #endif
- #endif
-
- /* Calculate days since 1970/01/01 */
- daycount = 365 * (year - 1970) + /* days due to whole years */
- (year - 1969) / 4 + /* days due to leap years */
- dsboy[month-1] + /* days since beginning of this year */
- day-1; /* days since beginning of month */
-
- if (year % 4 == 0 &&
- year % 400 != 0 && month >= 3) /* if this is a leap year and month */
- daycount++; /* is March or later, add a day */
-
- /* Knowing the days, we can find seconds */
- longtime = daycount * 24L * 60L * 60L +
- hour * 60L * 60L + min * 60 + sec;
- return (longtime);
- }
-
- /*
- gets system time
- */
- long systime(void)
- {
- struct date dateblk;
- struct time timeblk;
- getdate (&dateblk);
- gettime (&timeblk);
- return (dostounix (&dateblk, &timeblk));
- }
-
- /*
- compares file times
- */
- int cmptime (long utime, compare_pt choice, long value)
- {
- long diff;
- diff = (systime() - utime);
- if (choice == SAME && diff == value ||
- choice == BIGGER && diff > value ||
- choice == SMALLER && diff < value) {
- return (1);
- } else {
- return (0);
- }
- }
-
- /*
- returns file time in unix format
- */
- long filetime (char *fname)
- {
- union {
- struct ftime bits;
- struct {
- unsigned int time;
- unsigned int date;
- } words;
- } date_time;
-
- int h;
- h = _open (fname, O_RDONLY);
- if (h == -1)
- return (0L);
- getftime (h, &date_time.bits);
- close(h);
- return (mstonix (date_time.words.date, date_time.words.time));
- }
-
- int cmptime2 (long utime, compare_pt choice, long value)
- {
- if (choice == SAME && utime == value ||
- choice == BIGGER && utime > value ||
- choice == SMALLER && utime < value) {
- return (1);
- } else {
- return (0);
- }
- }
-