time.h 7.0 KB

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