home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / local / gettod.c < prev    next >
Text File  |  1992-03-15  |  1KB  |  47 lines

  1. #define INCL_DOSDATETIME
  2. #include <os2.h>
  3. #include <sys/time.h>
  4. #include <time.h>
  5. #include <errno.h>
  6.  
  7. ULONG Dos32GetDateTime() asm ("Dos32GetDateTime");
  8.  
  9. int gettimeofday (struct timeval *tp, struct timezone *tzp)
  10. {
  11.    ULONG rc;
  12.    DATETIME dt;
  13.    struct tm tim;
  14. printf ("entering gettod\n"); fflush(0);   
  15.    rc = Dos32GetDateTime (&dt);
  16.  
  17.    if (rc) {
  18.       errno = 0;
  19.       return (-1);
  20.    }
  21.  
  22.    tim.tm_sec = dt.seconds;        /* seconds after the minute [0-60] */
  23.    tim.tm_min = dt.minutes;        /* minutes after the hour [0-59] */
  24.    tim.tm_hour = dt.hours;            /* hours since midnight [0-23] */
  25.    tim.tm_mday = dt.day;            /* day of the month [1-31] */
  26.    tim.tm_mon = dt.month;            /* months since January [0-11] */
  27.    tim.tm_year = dt.year - 1900;        /* years since 1900 */
  28.    tim.tm_wday = dt.weekday;        /* days since Sunday [0-6] */
  29.    tim.tm_yday = 0;                    /* days since January 1 [0-365] */
  30.    tim.tm_isdst = 0;                /* Daylight Savings Time flag */
  31.    tim.tm_gmtoff = 0;                /* offset from CUT in seconds */
  32.    *tim.tm_zone = 0;                /* timezone abbreviation */
  33.  
  34.    if (tp) {
  35.       tp -> tv_sec = mktime (&tim);
  36.       tp -> tv_usec = dt.hundredths * 10000;
  37.    }
  38.  
  39.    if (tzp) {
  40.       tzp -> tz_minuteswest = dt.timezone;
  41.       tzp -> tz_dsttime = 0;
  42.    }
  43. printf ("leaving gettod\n");fflush(0);
  44.    return (0);
  45. }
  46.  
  47.