time.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /* Copyright (C) 1991-1999,2000,2001,2002,2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /*
  16. * ISO C99 Standard: 7.23 Date and time <time.h>
  17. */
  18. #ifndef _TIME_H
  19. #if (! defined __need_time_t && !defined __need_clock_t && \
  20. ! defined __need_timespec)
  21. # define _TIME_H 1
  22. # include <features.h>
  23. __BEGIN_DECLS
  24. #endif
  25. #ifdef _TIME_H
  26. /* Get size_t and NULL from <stddef.h>. */
  27. # define __need_size_t
  28. # define __need_NULL
  29. # include <stddef.h>
  30. /* This defines CLOCKS_PER_SEC, which is the number of processor clock
  31. ticks per second. */
  32. # include <bits/time.h>
  33. /* This is the obsolete POSIX.1-1988 name for the same constant. */
  34. # if !defined __STRICT_ANSI__ && !defined __USE_XOPEN2K
  35. # ifndef CLK_TCK
  36. # define CLK_TCK CLOCKS_PER_SEC
  37. # endif
  38. # endif
  39. #endif /* <time.h> included. */
  40. #if !defined __clock_t_defined && (defined _TIME_H || defined __need_clock_t)
  41. # define __clock_t_defined 1
  42. # include <bits/types.h>
  43. __BEGIN_NAMESPACE_STD
  44. /* Returned by `clock'. */
  45. typedef __clock_t clock_t;
  46. __END_NAMESPACE_STD
  47. #if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC
  48. __USING_NAMESPACE_STD(clock_t)
  49. #endif
  50. #endif /* clock_t not defined and <time.h> or need clock_t. */
  51. #undef __need_clock_t
  52. #if !defined __time_t_defined && (defined _TIME_H || defined __need_time_t)
  53. # define __time_t_defined 1
  54. # include <bits/types.h>
  55. __BEGIN_NAMESPACE_STD
  56. /* Returned by `time'. */
  57. typedef __time_t time_t;
  58. __END_NAMESPACE_STD
  59. #if defined __USE_POSIX || defined __USE_MISC || defined __USE_SVID
  60. __USING_NAMESPACE_STD(time_t)
  61. #endif
  62. #endif /* time_t not defined and <time.h> or need time_t. */
  63. #undef __need_time_t
  64. #if !defined __clockid_t_defined && \
  65. ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_clockid_t)
  66. # define __clockid_t_defined 1
  67. # include <bits/types.h>
  68. /* Clock ID used in clock and timer functions. */
  69. typedef __clockid_t clockid_t;
  70. #endif /* clockid_t not defined and <time.h> or need clockid_t. */
  71. #undef __clockid_time_t
  72. #if !defined __timer_t_defined && \
  73. ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_timer_t)
  74. # define __timer_t_defined 1
  75. # include <bits/types.h>
  76. /* Timer ID returned by `timer_create'. */
  77. typedef __timer_t timer_t;
  78. #endif /* timer_t not defined and <time.h> or need timer_t. */
  79. #undef __need_timer_t
  80. #if !defined __timespec_defined && \
  81. ((defined _TIME_H && \
  82. (defined __USE_POSIX199309 || defined __USE_MISC)) || \
  83. defined __need_timespec)
  84. # define __timespec_defined 1
  85. /* POSIX.1b structure for a time value. This is like a `struct timeval' but
  86. has nanoseconds instead of microseconds. */
  87. struct timespec
  88. {
  89. __time_t tv_sec; /* Seconds. */
  90. long int tv_nsec; /* Nanoseconds. */
  91. };
  92. #endif /* timespec not defined and <time.h> or need timespec. */
  93. #undef __need_timespec
  94. #ifdef _TIME_H
  95. __BEGIN_NAMESPACE_STD
  96. /* Used by other time functions. */
  97. struct tm
  98. {
  99. int tm_sec; /* Seconds. [0-60] (1 leap second) */
  100. int tm_min; /* Minutes. [0-59] */
  101. int tm_hour; /* Hours. [0-23] */
  102. int tm_mday; /* Day. [1-31] */
  103. int tm_mon; /* Month. [0-11] */
  104. int tm_year; /* Year - 1900. */
  105. int tm_wday; /* Day of week. [0-6] */
  106. int tm_yday; /* Days in year.[0-365] */
  107. int tm_isdst; /* DST. [-1/0/1]*/
  108. #ifdef __UCLIBC_HAS_TM_EXTENSIONS__
  109. #ifdef __USE_BSD
  110. long int tm_gmtoff; /* Seconds east of UTC. */
  111. __const char *tm_zone; /* Timezone abbreviation. */
  112. #else
  113. long int __tm_gmtoff; /* Seconds east of UTC. */
  114. __const char *__tm_zone; /* Timezone abbreviation. */
  115. #endif
  116. char __tm_tzname[8]; /* In uClibc, tm_zone points to __tm_tzname. */
  117. #endif /* __UCLIBC_HAS_TM_EXTENSIONS__ */
  118. };
  119. __END_NAMESPACE_STD
  120. #if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC
  121. __USING_NAMESPACE_STD(tm)
  122. #endif
  123. #ifdef __USE_POSIX199309
  124. /* POSIX.1b structure for timer start values and intervals. */
  125. struct itimerspec
  126. {
  127. struct timespec it_interval;
  128. struct timespec it_value;
  129. };
  130. /* We can use a simple forward declaration. */
  131. struct sigevent;
  132. #endif /* POSIX.1b */
  133. #ifdef __USE_XOPEN2K
  134. # ifndef __pid_t_defined
  135. typedef __pid_t pid_t;
  136. # define __pid_t_defined
  137. # endif
  138. #endif
  139. __BEGIN_NAMESPACE_STD
  140. /* Time used by the program so far (user time + system time).
  141. The result / CLOCKS_PER_SECOND is program time in seconds. */
  142. extern clock_t clock (void) __THROW;
  143. /* Return the current time and put it in *TIMER if TIMER is not NULL. */
  144. extern time_t time (time_t *__timer) __THROW;
  145. #ifdef __UCLIBC_HAS_FLOATS__
  146. /* Return the difference between TIME1 and TIME0. */
  147. extern double difftime (time_t __time1, time_t __time0)
  148. __THROW __attribute__ ((__const__));
  149. #endif /* __UCLIBC_HAS_FLOATS__ */
  150. /* Return the `time_t' representation of TP and normalize TP. */
  151. extern time_t mktime (struct tm *__tp) __THROW;
  152. /* Format TP into S according to FORMAT.
  153. Write no more than MAXSIZE characters and return the number
  154. of characters written, or 0 if it would exceed MAXSIZE. */
  155. extern size_t strftime (char *__restrict __s, size_t __maxsize,
  156. __const char *__restrict __format,
  157. __const struct tm *__restrict __tp) __THROW;
  158. __END_NAMESPACE_STD
  159. # ifdef __USE_XOPEN
  160. /* Parse S according to FORMAT and store binary time information in TP.
  161. The return value is a pointer to the first unparsed character in S. */
  162. extern char *strptime (__const char *__restrict __s,
  163. __const char *__restrict __fmt, struct tm *__tp)
  164. __THROW;
  165. # endif
  166. #ifdef __UCLIBC_HAS_XLOCALE__
  167. # ifdef __USE_GNU
  168. /* Similar to the two functions above but take the information from
  169. the provided locale and not the global locale. */
  170. # include <xlocale.h>
  171. extern size_t strftime_l (char *__restrict __s, size_t __maxsize,
  172. __const char *__restrict __format,
  173. __const struct tm *__restrict __tp,
  174. __locale_t __loc) __THROW;
  175. extern char *strptime_l (__const char *__restrict __s,
  176. __const char *__restrict __fmt, struct tm *__tp,
  177. __locale_t __loc) __THROW;
  178. extern size_t __strftime_l (char *__restrict __s, size_t __maxsize,
  179. __const char *__restrict __format,
  180. __const struct tm *__restrict __tp,
  181. __locale_t __loc) __THROW;
  182. extern char *__strptime_l (__const char *__restrict __s,
  183. __const char *__restrict __fmt, struct tm *__tp,
  184. __locale_t __loc) __THROW;
  185. # endif
  186. #endif
  187. __BEGIN_NAMESPACE_STD
  188. /* Return the `struct tm' representation of *TIMER
  189. in Universal Coordinated Time (aka Greenwich Mean Time). */
  190. extern struct tm *gmtime (__const time_t *__timer) __THROW;
  191. /* Return the `struct tm' representation
  192. of *TIMER in the local timezone. */
  193. extern struct tm *localtime (__const time_t *__timer) __THROW;
  194. __END_NAMESPACE_STD
  195. # if defined __USE_POSIX || defined __USE_MISC
  196. /* Return the `struct tm' representation of *TIMER in UTC,
  197. using *TP to store the result. */
  198. extern struct tm *gmtime_r (__const time_t *__restrict __timer,
  199. struct tm *__restrict __tp) __THROW;
  200. /* Return the `struct tm' representation of *TIMER in local time,
  201. using *TP to store the result. */
  202. extern struct tm *localtime_r (__const time_t *__restrict __timer,
  203. struct tm *__restrict __tp) __THROW;
  204. # endif /* POSIX or misc */
  205. __BEGIN_NAMESPACE_STD
  206. /* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
  207. that is the representation of TP in this format. */
  208. extern char *asctime (__const struct tm *__tp) __THROW;
  209. /* Equivalent to `asctime (localtime (timer))'. */
  210. extern char *ctime (__const time_t *__timer) __THROW;
  211. __END_NAMESPACE_STD
  212. # if defined __USE_POSIX || defined __USE_MISC
  213. /* Reentrant versions of the above functions. */
  214. /* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n"
  215. that is the representation of TP in this format. */
  216. extern char *asctime_r (__const struct tm *__restrict __tp,
  217. char *__restrict __buf) __THROW;
  218. /* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'. */
  219. extern char *ctime_r (__const time_t *__restrict __timer,
  220. char *__restrict __buf) __THROW;
  221. # endif /* POSIX or misc */
  222. /* Defined in localtime.c. */
  223. extern char *__tzname[2]; /* Current timezone names. */
  224. extern int __daylight; /* If daylight-saving time is ever in use. */
  225. extern long int __timezone; /* Seconds west of UTC. */
  226. # ifdef __USE_POSIX
  227. /* Same as above. */
  228. extern char *tzname[2];
  229. /* Set time conversion information from the TZ environment variable.
  230. If TZ is not defined, a locale-dependent default is used. */
  231. extern void tzset (void) __THROW;
  232. # endif
  233. # if defined __USE_SVID || defined __USE_XOPEN
  234. extern int daylight;
  235. extern long int timezone;
  236. # endif
  237. # ifdef __USE_SVID
  238. /* Set the system time to *WHEN.
  239. This call is restricted to the superuser. */
  240. extern int stime (__const time_t *__when) __THROW;
  241. # endif
  242. /* Nonzero if YEAR is a leap year (every 4 years,
  243. except every 100th isn't, and every 400th is). */
  244. # define __isleap(year) \
  245. ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
  246. # ifdef __USE_MISC
  247. /* Miscellaneous functions many Unices inherited from the public domain
  248. localtime package. These are included only for compatibility. */
  249. /* Like `mktime', but for TP represents Universal Time, not local time. */
  250. extern time_t timegm (struct tm *__tp) __THROW;
  251. /* Another name for `mktime'. */
  252. extern time_t timelocal (struct tm *__tp) __THROW;
  253. /* Return the number of days in YEAR. */
  254. extern int dysize (int __year) __THROW __attribute__ ((__const__));
  255. # endif
  256. # ifdef __USE_POSIX199309
  257. /* Pause execution for a number of nanoseconds.
  258. This function is a cancellation point and therefore not marked with
  259. __THROW. */
  260. extern int nanosleep (__const struct timespec *__requested_time,
  261. struct timespec *__remaining);
  262. /* Get resolution of clock CLOCK_ID. */
  263. extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
  264. /* Get current value of clock CLOCK_ID and store it in TP. */
  265. extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
  266. /* Set clock CLOCK_ID to value TP. */
  267. extern int clock_settime (clockid_t __clock_id, __const struct timespec *__tp)
  268. __THROW;
  269. # ifdef __USE_XOPEN2K
  270. /* High-resolution sleep with the specified clock.
  271. This function is a cancellation point and therefore not marked with
  272. __THROW. */
  273. extern int clock_nanosleep (clockid_t __clock_id, int __flags,
  274. __const struct timespec *__req,
  275. struct timespec *__rem);
  276. /* Return clock ID for CPU-time clock. */
  277. extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW;
  278. # endif
  279. /* Create new per-process timer using CLOCK_ID. */
  280. extern int timer_create (clockid_t __clock_id,
  281. struct sigevent *__restrict __evp,
  282. timer_t *__restrict __timerid) __THROW;
  283. /* Delete timer TIMERID. */
  284. extern int timer_delete (timer_t __timerid) __THROW;
  285. /* Set timer TIMERID to VALUE, returning old value in OVLAUE. */
  286. extern int timer_settime (timer_t __timerid, int __flags,
  287. __const struct itimerspec *__restrict __value,
  288. struct itimerspec *__restrict __ovalue) __THROW;
  289. /* Get current value of timer TIMERID and store it in VLAUE. */
  290. extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
  291. __THROW;
  292. /* Get expiration overrun for timer TIMERID. */
  293. extern int timer_getoverrun (timer_t __timerid) __THROW;
  294. # endif
  295. # ifdef __USE_XOPEN_EXTENDED
  296. /* Set to one of the following values to indicate an error.
  297. 1 the DATEMSK environment variable is null or undefined,
  298. 2 the template file cannot be opened for reading,
  299. 3 failed to get file status information,
  300. 4 the template file is not a regular file,
  301. 5 an error is encountered while reading the template file,
  302. 6 memory allication failed (not enough memory available),
  303. 7 there is no line in the template that matches the input,
  304. 8 invalid input specification Example: February 31 or a time is
  305. specified that can not be represented in a time_t (representing
  306. the time in seconds since 00:00:00 UTC, January 1, 1970) */
  307. extern int getdate_err;
  308. /* Parse the given string as a date specification and return a value
  309. representing the value. The templates from the file identified by
  310. the environment variable DATEMSK are used. In case of an error
  311. `getdate_err' is set.
  312. This function is a possible cancellation points and therefore not
  313. marked with __THROW. */
  314. extern struct tm *getdate (__const char *__string);
  315. # endif
  316. # ifdef __USE_GNU
  317. /* Since `getdate' is not reentrant because of the use of `getdate_err'
  318. and the static buffer to return the result in, we provide a thread-safe
  319. variant. The functionality is the same. The result is returned in
  320. the buffer pointed to by RESBUFP and in case of an error the return
  321. value is != 0 with the same values as given above for `getdate_err'.
  322. This function is not part of POSIX and therefore no official
  323. cancellation point. But due to similarity with an POSIX interface
  324. or due to the implementation it is a cancellation point and
  325. therefore not marked with __THROW. */
  326. extern int getdate_r (__const char *__restrict __string,
  327. struct tm *__restrict __resbufp);
  328. # endif
  329. __END_DECLS
  330. #endif /* <time.h> included. */
  331. #endif /* <time.h> not already included. */