1
0

time.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef _SYS_TIME_H
  2. #define _SYS_TIME_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <sys/select.h>
  7. int gettimeofday (struct timeval *, void *);
  8. #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
  9. #define ITIMER_REAL 0
  10. #define ITIMER_VIRTUAL 1
  11. #define ITIMER_PROF 2
  12. struct itimerval
  13. {
  14. struct timeval it_interval;
  15. struct timeval it_value;
  16. };
  17. int getitimer (int, struct itimerval *);
  18. int setitimer (int, const struct itimerval *, struct itimerval *);
  19. int utimes (const char *, const struct timeval [2]);
  20. #endif
  21. #ifdef _GNU_SOURCE
  22. int settimeofday (const struct timeval *, void *);
  23. int adjtime (const struct timeval *, struct timeval *);
  24. struct timezone {
  25. int tz_minuteswest;
  26. int tz_dsttime;
  27. };
  28. #define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
  29. #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
  30. #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
  31. (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
  32. #define timeradd(s,t,a) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
  33. ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
  34. ((a)->tv_usec -= 1000000, (a)->tv_sec++) )
  35. #define timersub(s,t,a) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
  36. ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
  37. ((a)->tv_usec += 1000000, (a)->tv_sec--) )
  38. #endif
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42. #endif