time.h 1.4 KB

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