Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/3/84; site maynard.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!mhuxn!mhuxr!ulysses!allegra!mit-eddie!genrad!panda!talcott!wjh12!maynard!campbell From: campbell@maynard.UUCP (Larry Campbell) Newsgroups: net.sources Subject: time(2) function for MS-DOS Message-ID: <127@maynard.UUCP> Date: Sun, 23-Jun-85 10:21:40 EDT Article-I.D.: maynard.127 Posted: Sun Jun 23 10:21:40 1985 Date-Received: Tue, 25-Jun-85 02:57:45 EDT Distribution: net Organization: The Boston Software Works Inc., Maynard, MA Lines: 65 Here's a little function that emulates the time(2) Unix system call under MS-DOS. It requires six little assembly language routines to return the various components of the date and time from DOS calls 2A (get date) and 2C (get time). These routines are called dos_day, dos_hour, etc. and are left as an exercise for the reader. /* * \usr\decusc\lib\time.c * * long time (long *result) * * Returns and stores seconds since midnight, 1 January 1970 * * Environment: MS-DOS version 2.xx or later * Language: Computer Innovations C86 version 2.10 * Author: Larry Campbell * Created: June 1, 1984 * Bugs: Stops working Dec. 31, 2004 */ static unsigned int days_in_year[] = /* starting with 1980 */ { 366, 365, 365, 365, 366, 365, 365, 365, 366, 365, 365, 365, 366, 365, 365, 365, 366, 365, 365, 365, 366, 365, 365, 365}, days_in_preceding_months[] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; long time (result) long *result; { unsigned int y, year, month, day, hour, minute, second, Days; unsigned long Time; year = dos_year (); month = dos_month (); day = dos_date (); hour = dos_hours (); minute = dos_minutes (); second = dos_seconds (); Days = 3652; /* days from 1-jan-70 to 1-jan-80 */ y = year - 1980; while (y-- > 0) Days += days_in_year[y]; if (month > 1) Days += days_in_preceding_months[month - 2]; if (month > 2 && (year & 0x3)) /* account for February in leap years */ Days++; Days += day; Time = second + (60L * (minute + 60L * hour)); Time = (86400L * Days) + Time; if (result) *result = Time; return (Time); }