gettimeofday.c 759 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <sys/types.h>
  2. #include <time.h>
  3. #include <sys/time.h>
  4. #include <string.h>
  5. #include "sys9.h"
  6. typedef unsigned long long uvlong;
  7. typedef long long vlong;
  8. typedef unsigned char uchar;
  9. static uvlong order = 0x0001020304050607ULL;
  10. static void
  11. be2vlong(vlong *to, uchar *f)
  12. {
  13. uchar *t, *o;
  14. int i;
  15. t = (uchar*)to;
  16. o = (uchar*)&order;
  17. for(i = 0; i < 8; i++)
  18. t[o[i]] = f[i];
  19. }
  20. int
  21. gettimeofday(struct timeval *tp, struct timezone *tzp)
  22. {
  23. int f;
  24. uchar b[8];
  25. vlong t;
  26. memset(b, 0, sizeof b);
  27. f = _OPEN("/dev/bintime", 0);
  28. if(f >= 0) {
  29. _PREAD(f, b, sizeof(b), 0);
  30. _CLOSE(f);
  31. }
  32. be2vlong(&t, b);
  33. tp->tv_sec = t/1000000000;
  34. tp->tv_usec = (t/1000)%1000000;
  35. if(tzp) {
  36. tzp->tz_minuteswest = 240;
  37. tzp->tz_dsttime = 1;
  38. }
  39. return 0;
  40. }