home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / mntlib16.lzh / MNTLIB16 / TIME.C < prev    next >
C/C++ Source or Header  |  1993-07-29  |  1KB  |  51 lines

  1. /* time.c : return the elapsed seconds since midnight Jan 1 1970 GMT */
  2. /* written by Eric R. Smith and placed in the public domain */
  3.  
  4. #include <time.h>
  5. #include <osbind.h>
  6.  
  7. static struct tm this_tm;
  8. int _dst;
  9.  
  10. /* unixtime: convert a DOS time/date pair into a unix time */
  11. /* in case people were wondering about whether or not DST is applicable
  12.  * right now, we set the external variable _dst to the value
  13.  * returned from mktime
  14.  */
  15.  
  16. time_t 
  17. _unixtime(dostime, dosdate)
  18.     unsigned dostime, dosdate;
  19. {
  20.     time_t t;
  21.     struct tm *stm = &this_tm;
  22.  
  23.     stm->tm_sec = (dostime & 31) << 1;
  24.     stm->tm_min = (dostime >> 5) & 63;
  25.     stm->tm_hour = (dostime >> 11) & 31;
  26.     stm->tm_mday = dosdate & 31;
  27.     stm->tm_mon = ((dosdate >> 5) & 15) - 1;
  28.     stm->tm_year = 80 + ((dosdate >> 9) & 255);
  29.     stm->tm_isdst = -1;    /* we don't know about DST */
  30.  
  31. /* mktime expects a local time, which is what we're giving it :-) */
  32.     t = mktime(stm);
  33.  
  34.     _dst = (stm->tm_isdst == 1) ? 1 : 0;
  35.     return t;
  36. }
  37.  
  38. time_t time(t)
  39.     time_t *t;
  40. {
  41.     unsigned dostime, dosdate;
  42.     time_t    made;
  43.  
  44.     dostime = Tgettime();
  45.     dosdate = Tgetdate();
  46.     made = _unixtime(dostime, dosdate);
  47.     if (t)
  48.         *t = made;
  49.     return made;
  50. }
  51.