time.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef _SYS_TIME_H
  2. #define _SYS_TIME_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <features.h>
  7. #include <sys/select.h>
  8. int gettimeofday (struct timeval *__restrict, void *__restrict);
  9. #define ITIMER_REAL 0
  10. #define ITIMER_VIRTUAL 1
  11. #define ITIMER_PROF 2
  12. struct itimerval {
  13. struct timeval it_interval;
  14. struct timeval it_value;
  15. };
  16. int getitimer (int, struct itimerval *);
  17. int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict);
  18. int utimes (const char *, const struct timeval [2]);
  19. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  20. struct timezone {
  21. int tz_minuteswest;
  22. int tz_dsttime;
  23. };
  24. int futimes(int, const struct timeval [2]);
  25. int futimesat(int, const char *, const struct timeval [2]);
  26. int lutimes(const char *, const struct timeval [2]);
  27. int settimeofday(const struct timeval *, const struct timezone *);
  28. int adjtime (const struct timeval *, struct timeval *);
  29. #define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
  30. #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
  31. #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
  32. (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
  33. #define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
  34. ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
  35. ((a)->tv_usec -= 1000000, (a)->tv_sec++) )
  36. #define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
  37. ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
  38. ((a)->tv_usec += 1000000, (a)->tv_sec--) )
  39. #endif
  40. #if defined(_GNU_SOURCE)
  41. #define TIMEVAL_TO_TIMESPEC(tv, ts) ( \
  42. (ts)->tv_sec = (tv)->tv_sec, \
  43. (ts)->tv_nsec = (tv)->tv_usec * 1000, \
  44. (void)0 )
  45. #define TIMESPEC_TO_TIMEVAL(tv, ts) ( \
  46. (tv)->tv_sec = (ts)->tv_sec, \
  47. (tv)->tv_usec = (ts)->tv_nsec / 1000, \
  48. (void)0 )
  49. #endif
  50. #if _REDIR_TIME64
  51. __REDIR(gettimeofday, __gettimeofday_time64);
  52. __REDIR(getitimer, __getitimer_time64);
  53. __REDIR(setitimer, __setitimer_time64);
  54. __REDIR(utimes, __utimes_time64);
  55. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  56. __REDIR(futimes, __futimes_time64);
  57. __REDIR(futimesat, __futimesat_time64);
  58. __REDIR(lutimes, __lutimes_time64);
  59. __REDIR(settimeofday, __settimeofday_time64);
  60. __REDIR(adjtime, __adjtime64);
  61. #endif
  62. #endif
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif