time.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. || defined(_BSD_SOURCE)
  10. #define ITIMER_REAL 0
  11. #define ITIMER_VIRTUAL 1
  12. #define ITIMER_PROF 2
  13. struct itimerval
  14. {
  15. struct timeval it_interval;
  16. struct timeval it_value;
  17. };
  18. int getitimer (int, struct itimerval *);
  19. int setitimer (int, const struct itimerval *, struct itimerval *);
  20. int utimes (const char *, const struct timeval [2]);
  21. #endif
  22. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  23. int futimes(int, const struct timeval [2]);
  24. int lutimes(const char *, const struct timeval [2]);
  25. int settimeofday (const struct timeval *, void *);
  26. int adjtime (const struct timeval *, struct timeval *);
  27. struct timezone {
  28. int tz_minuteswest;
  29. int tz_dsttime;
  30. };
  31. #define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
  32. #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
  33. #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
  34. (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
  35. #define timeradd(s,t,a) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
  36. ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
  37. ((a)->tv_usec -= 1000000, (a)->tv_sec++) )
  38. #define timersub(s,t,a) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
  39. ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
  40. ((a)->tv_usec += 1000000, (a)->tv_sec--) )
  41. #endif
  42. #ifdef __cplusplus
  43. }
  44. #endif
  45. #endif