time.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef _TIME_H
  2. #define _TIME_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <features.h>
  7. #if __cplusplus >= 201103L
  8. #define NULL nullptr
  9. #elif defined(__cplusplus)
  10. #define NULL 0L
  11. #else
  12. #define NULL ((void*)0)
  13. #endif
  14. #define __NEED_size_t
  15. #define __NEED_time_t
  16. #define __NEED_clock_t
  17. #define __NEED_struct_timespec
  18. #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  19. || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  20. || defined(_BSD_SOURCE)
  21. #define __NEED_clockid_t
  22. #define __NEED_timer_t
  23. #define __NEED_pid_t
  24. #define __NEED_locale_t
  25. #endif
  26. #include <bits/alltypes.h>
  27. #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
  28. #define __tm_gmtoff tm_gmtoff
  29. #define __tm_zone tm_zone
  30. #endif
  31. struct tm {
  32. int tm_sec;
  33. int tm_min;
  34. int tm_hour;
  35. int tm_mday;
  36. int tm_mon;
  37. int tm_year;
  38. int tm_wday;
  39. int tm_yday;
  40. int tm_isdst;
  41. long __tm_gmtoff;
  42. const char *__tm_zone;
  43. };
  44. clock_t clock (void);
  45. time_t time (time_t *);
  46. double difftime (time_t, time_t);
  47. time_t mktime (struct tm *);
  48. size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict);
  49. struct tm *gmtime (const time_t *);
  50. struct tm *localtime (const time_t *);
  51. char *asctime (const struct tm *);
  52. char *ctime (const time_t *);
  53. int timespec_get(struct timespec *, int);
  54. #define CLOCKS_PER_SEC 1000000L
  55. #define TIME_UTC 1
  56. #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  57. || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  58. || defined(_BSD_SOURCE)
  59. size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t);
  60. struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
  61. struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
  62. char *asctime_r (const struct tm *__restrict, char *__restrict);
  63. char *ctime_r (const time_t *, char *);
  64. void tzset (void);
  65. struct itimerspec {
  66. struct timespec it_interval;
  67. struct timespec it_value;
  68. };
  69. #define CLOCK_REALTIME 0
  70. #define CLOCK_MONOTONIC 1
  71. #define CLOCK_PROCESS_CPUTIME_ID 2
  72. #define CLOCK_THREAD_CPUTIME_ID 3
  73. #define CLOCK_MONOTONIC_RAW 4
  74. #define CLOCK_REALTIME_COARSE 5
  75. #define CLOCK_MONOTONIC_COARSE 6
  76. #define CLOCK_BOOTTIME 7
  77. #define CLOCK_REALTIME_ALARM 8
  78. #define CLOCK_BOOTTIME_ALARM 9
  79. #define CLOCK_SGI_CYCLE 10
  80. #define CLOCK_TAI 11
  81. #define TIMER_ABSTIME 1
  82. int nanosleep (const struct timespec *, struct timespec *);
  83. int clock_getres (clockid_t, struct timespec *);
  84. int clock_gettime (clockid_t, struct timespec *);
  85. int clock_settime (clockid_t, const struct timespec *);
  86. int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *);
  87. int clock_getcpuclockid (pid_t, clockid_t *);
  88. struct sigevent;
  89. int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict);
  90. int timer_delete (timer_t);
  91. int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict);
  92. int timer_gettime (timer_t, struct itimerspec *);
  93. int timer_getoverrun (timer_t);
  94. extern char *tzname[2];
  95. #endif
  96. #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
  97. char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict);
  98. extern int daylight;
  99. extern long timezone;
  100. extern int getdate_err;
  101. struct tm *getdate (const char *);
  102. #endif
  103. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  104. int stime(const time_t *);
  105. time_t timegm(struct tm *);
  106. #endif
  107. #if _REDIR_TIME64
  108. __REDIR(time, __time64);
  109. __REDIR(difftime, __difftime64);
  110. __REDIR(mktime, __mktime64);
  111. __REDIR(gmtime, __gmtime64);
  112. __REDIR(localtime, __localtime64);
  113. __REDIR(ctime, __ctime64);
  114. __REDIR(timespec_get, __timespec_get_time64);
  115. #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  116. || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  117. || defined(_BSD_SOURCE)
  118. __REDIR(gmtime_r, __gmtime64_r);
  119. __REDIR(localtime_r, __localtime64_r);
  120. __REDIR(ctime_r, __ctime64_r);
  121. __REDIR(nanosleep, __nanosleep_time64);
  122. __REDIR(clock_getres, __clock_getres_time64);
  123. __REDIR(clock_gettime, __clock_gettime64);
  124. __REDIR(clock_settime, __clock_settime64);
  125. __REDIR(clock_nanosleep, __clock_nanosleep_time64);
  126. __REDIR(timer_settime, __timer_settime64);
  127. __REDIR(timer_gettime, __timer_gettime64);
  128. #endif
  129. #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
  130. __REDIR(stime, __stime64);
  131. __REDIR(timegm, __timegm_time64);
  132. #endif
  133. #endif
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif