home *** CD-ROM | disk | FTP | other *** search
- /* BSDish gettimeofday() and settimeofday() calls */
- /* also ftime(), which seems to be similar to gettimeofday() */
-
- #include <types.h>
- #include <time.h>
- #include <unistd.h>
- #include <sys/timeb.h>
-
- extern int _dst; /* in time.c */
- extern long _timezone; /* in localtim.c */
-
- int
- gettimeofday( tv, tzp )
- struct timeval *tv;
- struct timezone *tzp;
- {
- struct timeb tp;
- int r;
-
- r = ftime(&tp);
- if (r) return r;
-
- if (tv) {
- tv->tv_sec = tp.time;
- tv->tv_usec = 0;
- }
- if (tzp) {
- tzp->tz_minuteswest = tp.timezone;
- tzp->tz_dsttime = tp.dstflag;
- }
- return 0;
- }
-
- int
- settimeofday( tv, tzp )
- struct timeval *tv;
- struct timezone *tzp;
- {
- return stime(&tv->tv_sec);
- }
-
- int
- ftime(tp)
- struct timeb *tp;
- {
- long t = time((time_t *)0);
-
- tp->time = t;
- tp->millitm = 0;
- tp->timezone = _timezone / 60;
- tp->dstflag = (_dst) ? 1 : 0;
-
- return 0;
- }
-