time.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * time.h
  3. *
  4. * Struct and function declarations for dealing with time.
  5. */
  6. #ifndef _TIME_H_
  7. #define _TIME_H_
  8. #include "_ansi.h"
  9. #include <sys/cdefs.h>
  10. #include <sys/reent.h>
  11. #define __need_size_t
  12. #define __need_NULL
  13. #include <stddef.h>
  14. /* Get _CLOCKS_PER_SEC_ */
  15. #include <machine/time.h>
  16. #ifndef _CLOCKS_PER_SEC_
  17. #define _CLOCKS_PER_SEC_ 1000
  18. #endif
  19. #define CLOCKS_PER_SEC _CLOCKS_PER_SEC_
  20. #define CLK_TCK CLOCKS_PER_SEC
  21. #include <sys/types.h>
  22. #include <sys/timespec.h>
  23. #if __POSIX_VISIBLE >= 200809
  24. #include <sys/_locale.h>
  25. #endif
  26. _BEGIN_STD_C
  27. struct tm
  28. {
  29. int tm_sec;
  30. int tm_min;
  31. int tm_hour;
  32. int tm_mday;
  33. int tm_mon;
  34. int tm_year;
  35. int tm_wday;
  36. int tm_yday;
  37. int tm_isdst;
  38. #ifdef __TM_GMTOFF
  39. long __TM_GMTOFF;
  40. #endif
  41. #ifdef __TM_ZONE
  42. const char *__TM_ZONE;
  43. #endif
  44. };
  45. clock_t clock (void);
  46. double difftime (time_t _time2, time_t _time1);
  47. time_t mktime (struct tm *_timeptr);
  48. time_t time (time_t *_timer);
  49. #ifndef _REENT_ONLY
  50. char *asctime (const struct tm *_tblock);
  51. char *ctime (const time_t *_time);
  52. struct tm *gmtime (const time_t *_timer);
  53. struct tm *localtime (const time_t *_timer);
  54. #endif
  55. size_t strftime (char *__restrict _s,
  56. size_t _maxsize, const char *__restrict _fmt,
  57. const struct tm *__restrict _t);
  58. #if __POSIX_VISIBLE >= 200809
  59. extern size_t strftime_l (char *__restrict _s, size_t _maxsize,
  60. const char *__restrict _fmt,
  61. const struct tm *__restrict _t, locale_t _l);
  62. #endif
  63. char *asctime_r (const struct tm *__restrict,
  64. char *__restrict);
  65. char *ctime_r (const time_t *, char *);
  66. struct tm *gmtime_r (const time_t *__restrict,
  67. struct tm *__restrict);
  68. struct tm *localtime_r (const time_t *__restrict,
  69. struct tm *__restrict);
  70. _END_STD_C
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74. #if __XSI_VISIBLE
  75. char *strptime (const char *__restrict,
  76. const char *__restrict,
  77. struct tm *__restrict);
  78. #endif
  79. #if __GNU_VISIBLE
  80. char *strptime_l (const char *__restrict, const char *__restrict,
  81. struct tm *__restrict, locale_t);
  82. #endif
  83. #if __POSIX_VISIBLE
  84. void tzset (void);
  85. #endif
  86. void _tzset_r (struct _reent *);
  87. /* getdate functions */
  88. #ifdef HAVE_GETDATE
  89. #if __XSI_VISIBLE >= 4
  90. #ifndef _REENT_ONLY
  91. #define getdate_err (*__getdate_err())
  92. int *__getdate_err (void);
  93. struct tm * getdate (const char *);
  94. /* getdate_err is set to one of the following values to indicate the error.
  95. 1 the DATEMSK environment variable is null or undefined,
  96. 2 the template file cannot be opened for reading,
  97. 3 failed to get file status information,
  98. 4 the template file is not a regular file,
  99. 5 an error is encountered while reading the template file,
  100. 6 memory allication failed (not enough memory available),
  101. 7 there is no line in the template that matches the input,
  102. 8 invalid input specification */
  103. #endif /* !_REENT_ONLY */
  104. #endif /* __XSI_VISIBLE >= 4 */
  105. #if __GNU_VISIBLE
  106. /* getdate_r returns the error code as above */
  107. int getdate_r (const char *, struct tm *);
  108. #endif /* __GNU_VISIBLE */
  109. #endif /* HAVE_GETDATE */
  110. /* defines for the opengroup specifications Derived from Issue 1 of the SVID. */
  111. #if __SVID_VISIBLE || __XSI_VISIBLE
  112. extern __IMPORT long _timezone;
  113. extern __IMPORT int _daylight;
  114. #endif
  115. #if __POSIX_VISIBLE
  116. extern __IMPORT char *_tzname[2];
  117. /* POSIX defines the external tzname being defined in time.h */
  118. #ifndef tzname
  119. #define tzname _tzname
  120. #endif
  121. #endif /* __POSIX_VISIBLE */
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #include <sys/features.h>
  126. #ifdef __CYGWIN__
  127. #include <cygwin/time.h>
  128. #endif /*__CYGWIN__*/
  129. #if defined(_POSIX_TIMERS)
  130. #include <signal.h>
  131. #ifdef __cplusplus
  132. extern "C" {
  133. #endif
  134. /* Clocks, P1003.1b-1993, p. 263 */
  135. int clock_settime (clockid_t clock_id, const struct timespec *tp);
  136. int clock_gettime (clockid_t clock_id, struct timespec *tp);
  137. int clock_getres (clockid_t clock_id, struct timespec *res);
  138. /* Create a Per-Process Timer, P1003.1b-1993, p. 264 */
  139. int timer_create (clockid_t clock_id,
  140. struct sigevent *__restrict evp,
  141. timer_t *__restrict timerid);
  142. /* Delete a Per_process Timer, P1003.1b-1993, p. 266 */
  143. int timer_delete (timer_t timerid);
  144. /* Per-Process Timers, P1003.1b-1993, p. 267 */
  145. int timer_settime (timer_t timerid, int flags,
  146. const struct itimerspec *__restrict value,
  147. struct itimerspec *__restrict ovalue);
  148. int timer_gettime (timer_t timerid, struct itimerspec *value);
  149. int timer_getoverrun (timer_t timerid);
  150. /* High Resolution Sleep, P1003.1b-1993, p. 269 */
  151. int nanosleep (const struct timespec *rqtp, struct timespec *rmtp);
  152. #ifdef __cplusplus
  153. }
  154. #endif
  155. #endif /* _POSIX_TIMERS */
  156. #if defined(_POSIX_CLOCK_SELECTION)
  157. #ifdef __cplusplus
  158. extern "C" {
  159. #endif
  160. int clock_nanosleep (clockid_t clock_id, int flags,
  161. const struct timespec *rqtp, struct timespec *rmtp);
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif /* _POSIX_CLOCK_SELECTION */
  166. #ifdef __cplusplus
  167. extern "C" {
  168. #endif
  169. /* CPU-time Clock Attributes, P1003.4b/D8, p. 54 */
  170. /* values for the clock enable attribute */
  171. #define CLOCK_ENABLED 1 /* clock is enabled, i.e. counting execution time */
  172. #define CLOCK_DISABLED 0 /* clock is disabled */
  173. /* values for the pthread cputime_clock_allowed attribute */
  174. #define CLOCK_ALLOWED 1 /* If a thread is created with this value a */
  175. /* CPU-time clock attached to that thread */
  176. /* shall be accessible. */
  177. #define CLOCK_DISALLOWED 0 /* If a thread is created with this value, the */
  178. /* thread shall not have a CPU-time clock */
  179. /* accessible. */
  180. /* Flag indicating time is "absolute" with respect to the clock
  181. associated with a time. Value 4 is historic. */
  182. #define TIMER_ABSTIME 4
  183. /* Manifest Constants, P1003.1b-1993, p. 262 */
  184. #if __GNU_VISIBLE
  185. #define CLOCK_REALTIME_COARSE ((clockid_t) 0)
  186. #endif
  187. #define CLOCK_REALTIME ((clockid_t) 1)
  188. /* Manifest Constants, P1003.4b/D8, p. 55 */
  189. #if defined(_POSIX_CPUTIME)
  190. /* When used in a clock or timer function call, this is interpreted as
  191. the identifier of the CPU_time clock associated with the PROCESS
  192. making the function call. */
  193. #define CLOCK_PROCESS_CPUTIME_ID ((clockid_t) 2)
  194. #endif
  195. #if defined(_POSIX_THREAD_CPUTIME)
  196. /* When used in a clock or timer function call, this is interpreted as
  197. the identifier of the CPU_time clock associated with the THREAD
  198. making the function call. */
  199. #define CLOCK_THREAD_CPUTIME_ID ((clockid_t) 3)
  200. #endif
  201. #if defined(_POSIX_MONOTONIC_CLOCK)
  202. /* The identifier for the system-wide monotonic clock, which is defined
  203. * as a clock whose value cannot be set via clock_settime() and which
  204. * cannot have backward clock jumps. */
  205. #define CLOCK_MONOTONIC ((clockid_t) 4)
  206. #endif
  207. #if __GNU_VISIBLE
  208. #define CLOCK_MONOTONIC_RAW ((clockid_t) 5)
  209. #define CLOCK_MONOTONIC_COARSE ((clockid_t) 6)
  210. #define CLOCK_BOOTTIME ((clockid_t) 7)
  211. #define CLOCK_REALTIME_ALARM ((clockid_t) 8)
  212. #define CLOCK_BOOTTIME_ALARM ((clockid_t) 9)
  213. #endif
  214. #if defined(_POSIX_CPUTIME)
  215. /* Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 */
  216. int clock_getcpuclockid (pid_t pid, clockid_t *clock_id);
  217. #endif /* _POSIX_CPUTIME */
  218. #if defined(_POSIX_CPUTIME) || defined(_POSIX_THREAD_CPUTIME)
  219. /* CPU-time Clock Attribute Access, P1003.4b/D8, p. 56 */
  220. int clock_setenable_attr (clockid_t clock_id, int attr);
  221. int clock_getenable_attr (clockid_t clock_id, int *attr);
  222. #endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226. #endif /* _TIME_H_ */