time.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* time.h -- An implementation of the standard Unix <sys/time.h> file.
  2. Written by Geoffrey Noer <noer@cygnus.com>
  3. Public domain; no rights reserved. */
  4. #ifndef _SYS_TIME_H_
  5. #define _SYS_TIME_H_
  6. #include <_ansi.h>
  7. #include <sys/types.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #ifndef _TIMEVAL_DEFINED
  12. #define _TIMEVAL_DEFINED
  13. struct timeval {
  14. time_t tv_sec;
  15. suseconds_t tv_usec;
  16. };
  17. /* BSD time macros used by RTEMS code */
  18. #if defined (__rtems__) || defined (__CYGWIN__) || defined(__XTENSA__)
  19. /* Convenience macros for operations on timevals.
  20. NOTE: `timercmp' does not work for >= or <=. */
  21. #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
  22. #define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
  23. #define timercmp(a, b, CMP) \
  24. (((a)->tv_sec == (b)->tv_sec) ? \
  25. ((a)->tv_usec CMP (b)->tv_usec) : \
  26. ((a)->tv_sec CMP (b)->tv_sec))
  27. #define timeradd(a, b, result) \
  28. do { \
  29. (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
  30. (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
  31. if ((result)->tv_usec >= 1000000) \
  32. { \
  33. ++(result)->tv_sec; \
  34. (result)->tv_usec -= 1000000; \
  35. } \
  36. } while (0)
  37. #define timersub(a, b, result) \
  38. do { \
  39. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  40. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  41. if ((result)->tv_usec < 0) { \
  42. --(result)->tv_sec; \
  43. (result)->tv_usec += 1000000; \
  44. } \
  45. } while (0)
  46. #endif /* defined (__rtems__) || defined (__CYGWIN__) */
  47. #endif /* !_TIMEVAL_DEFINED */
  48. struct timezone {
  49. int tz_minuteswest;
  50. int tz_dsttime;
  51. };
  52. #ifdef __CYGWIN__
  53. #include <cygwin/sys_time.h>
  54. #endif /* __CYGWIN__ */
  55. #define ITIMER_REAL 0
  56. #define ITIMER_VIRTUAL 1
  57. #define ITIMER_PROF 2
  58. struct itimerval {
  59. struct timeval it_interval;
  60. struct timeval it_value;
  61. };
  62. #ifdef _COMPILING_NEWLIB
  63. int _EXFUN(_gettimeofday, (struct timeval *__p, void *__tz));
  64. #endif
  65. int _EXFUN(gettimeofday, (struct timeval *__restrict __p,
  66. void *__restrict __tz));
  67. #if __BSD_VISIBLE
  68. int _EXFUN(settimeofday, (const struct timeval *, const struct timezone *));
  69. int _EXFUN(adjtime, (const struct timeval *, struct timeval *));
  70. #endif
  71. int _EXFUN(utimes, (const char *__path, const struct timeval *__tvp));
  72. int _EXFUN(getitimer, (int __which, struct itimerval *__value));
  73. int _EXFUN(setitimer, (int __which, const struct itimerval *__restrict __value,
  74. struct itimerval *__restrict __ovalue));
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif /* _SYS_TIME_H_ */