home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / timeoday.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  960b  |  59 lines

  1. /* BSDish gettimeofday() and settimeofday() calls */
  2. /* also ftime(), which seems to be similar to gettimeofday() */
  3.  
  4. #include <types.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. #ifdef __TURBOC__
  8. #include <sys\timeb.h>
  9. #else
  10. #include <sys/timeb.h>
  11. #endif
  12.  
  13. extern int _dst;    /* in time.c */
  14. extern long _timezone;    /* in localtim.c */
  15.  
  16. int
  17. gettimeofday( tv, tzp )
  18.     struct timeval *tv;
  19.     struct timezone *tzp;
  20. {
  21.     struct timeb tp;
  22.     int r;
  23.  
  24.     r = ftime(&tp);
  25.     if (r) return r;
  26.  
  27.     if (tv) {
  28.         tv->tv_sec = tp.time;
  29.         tv->tv_usec = 0;
  30.     }
  31.     if (tzp) {
  32.         tzp->tz_minuteswest = tp.timezone;
  33.         tzp->tz_dsttime = tp.dstflag;
  34.     }
  35.     return 0;
  36. }
  37.  
  38. int
  39. settimeofday( tv, tzp )
  40.     struct timeval *tv;
  41.     struct timezone *tzp;
  42. {
  43.     return stime(&tv->tv_sec);
  44. }
  45.  
  46. int
  47. ftime(tp)
  48.     struct timeb *tp;
  49. {
  50.     long t = time((time_t *)0);
  51.  
  52.     tp->time = t;
  53.     tp->millitm = 0;
  54.     tp->timezone = _timezone / 60;
  55.     tp->dstflag = (_dst) ? 1 : 0;
  56.  
  57.     return 0;
  58. }
  59.