time.h 1.6 KB

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