time.h 1.9 KB

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