time.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif