time.c 700 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * time - return the current calendar time (seconds since jan 1, 1970)
  3. */
  4. /* $Id$ */
  5. #if defined(__BSD4_2)
  6. #include <time.h>
  7. /*
  8. * Structure returned by gettimeofday(2) system call,
  9. * and used in other calls.
  10. */
  11. struct timeval {
  12. long tv_sec; /* seconds */
  13. long tv_usec; /* and microseconds */
  14. };
  15. struct timezone {
  16. int tz_minuteswest; /* minutes west of Greenwich */
  17. int tz_dsttime; /* type of dst correction */
  18. };
  19. int _gettimeofday(struct timeval *tp, struct timezone *tzp);
  20. time_t
  21. time(time_t *timer)
  22. {
  23. struct timeval tv;
  24. struct timezone tz;
  25. _gettimeofday(&tv, &tz);
  26. if (timer) *timer = tv.tv_sec;
  27. return tv.tv_sec;
  28. }
  29. #else
  30. /* Assume time() is a system call */ /* ??? */
  31. #endif