time.h 1.6 KB

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