time.in.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* A more-standard <time.h>.
  2. Copyright (C) 2007-2014 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program 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
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  13. #if __GNUC__ >= 3
  14. @PRAGMA_SYSTEM_HEADER@
  15. #endif
  16. @PRAGMA_COLUMNS@
  17. /* Don't get in the way of glibc when it includes time.h merely to
  18. declare a few standard symbols, rather than to declare all the
  19. symbols. Also, Solaris 8 <time.h> eventually includes itself
  20. recursively; if that is happening, just include the system <time.h>
  21. without adding our own declarations. */
  22. #if (defined __need_time_t || defined __need_clock_t \
  23. || defined __need_timespec \
  24. || defined _@GUARD_PREFIX@_TIME_H)
  25. # @INCLUDE_NEXT@ @NEXT_TIME_H@
  26. #else
  27. # define _@GUARD_PREFIX@_TIME_H
  28. # @INCLUDE_NEXT@ @NEXT_TIME_H@
  29. /* NetBSD 5.0 mis-defines NULL. */
  30. # include <stddef.h>
  31. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  32. /* The definition of _GL_ARG_NONNULL is copied here. */
  33. /* The definition of _GL_WARN_ON_USE is copied here. */
  34. /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
  35. Or they define it with the wrong member names or define it in <sys/time.h>
  36. (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it,
  37. but the pthreads-win32 library defines it in <pthread.h>. */
  38. # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
  39. # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
  40. # include <sys/time.h>
  41. # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
  42. # include <pthread.h>
  43. # else
  44. # ifdef __cplusplus
  45. extern "C" {
  46. # endif
  47. # if !GNULIB_defined_struct_timespec
  48. # undef timespec
  49. # define timespec rpl_timespec
  50. struct timespec
  51. {
  52. time_t tv_sec;
  53. long int tv_nsec;
  54. };
  55. # define GNULIB_defined_struct_timespec 1
  56. # endif
  57. # ifdef __cplusplus
  58. }
  59. # endif
  60. # endif
  61. # endif
  62. # if !GNULIB_defined_struct_time_t_must_be_integral
  63. /* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
  64. time_t to be an integer type, even though C99 permits floating
  65. point. We don't know of any implementation that uses floating
  66. point, and it is much easier to write code that doesn't have to
  67. worry about that corner case, so we force the issue. */
  68. struct __time_t_must_be_integral {
  69. unsigned int __floating_time_t_unsupported : (time_t) 1;
  70. };
  71. # define GNULIB_defined_struct_time_t_must_be_integral 1
  72. # endif
  73. /* Sleep for at least RQTP seconds unless interrupted, If interrupted,
  74. return -1 and store the remaining time into RMTP. See
  75. <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
  76. # if @GNULIB_NANOSLEEP@
  77. # if @REPLACE_NANOSLEEP@
  78. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  79. # define nanosleep rpl_nanosleep
  80. # endif
  81. _GL_FUNCDECL_RPL (nanosleep, int,
  82. (struct timespec const *__rqtp, struct timespec *__rmtp)
  83. _GL_ARG_NONNULL ((1)));
  84. _GL_CXXALIAS_RPL (nanosleep, int,
  85. (struct timespec const *__rqtp, struct timespec *__rmtp));
  86. # else
  87. # if ! @HAVE_NANOSLEEP@
  88. _GL_FUNCDECL_SYS (nanosleep, int,
  89. (struct timespec const *__rqtp, struct timespec *__rmtp)
  90. _GL_ARG_NONNULL ((1)));
  91. # endif
  92. _GL_CXXALIAS_SYS (nanosleep, int,
  93. (struct timespec const *__rqtp, struct timespec *__rmtp));
  94. # endif
  95. _GL_CXXALIASWARN (nanosleep);
  96. # endif
  97. /* Return the 'time_t' representation of TP and normalize TP. */
  98. # if @GNULIB_MKTIME@
  99. # if @REPLACE_MKTIME@
  100. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  101. # define mktime rpl_mktime
  102. # endif
  103. _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
  104. _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
  105. # else
  106. _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
  107. # endif
  108. _GL_CXXALIASWARN (mktime);
  109. # endif
  110. /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
  111. <http://www.opengroup.org/susv3xsh/localtime_r.html> and
  112. <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
  113. # if @GNULIB_TIME_R@
  114. # if @REPLACE_LOCALTIME_R@
  115. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  116. # undef localtime_r
  117. # define localtime_r rpl_localtime_r
  118. # endif
  119. _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
  120. struct tm *restrict __result)
  121. _GL_ARG_NONNULL ((1, 2)));
  122. _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
  123. struct tm *restrict __result));
  124. # else
  125. # if ! @HAVE_DECL_LOCALTIME_R@
  126. _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
  127. struct tm *restrict __result)
  128. _GL_ARG_NONNULL ((1, 2)));
  129. # endif
  130. _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
  131. struct tm *restrict __result));
  132. # endif
  133. # if @HAVE_DECL_LOCALTIME_R@
  134. _GL_CXXALIASWARN (localtime_r);
  135. # endif
  136. # if @REPLACE_LOCALTIME_R@
  137. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  138. # undef gmtime_r
  139. # define gmtime_r rpl_gmtime_r
  140. # endif
  141. _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
  142. struct tm *restrict __result)
  143. _GL_ARG_NONNULL ((1, 2)));
  144. _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
  145. struct tm *restrict __result));
  146. # else
  147. # if ! @HAVE_DECL_LOCALTIME_R@
  148. _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
  149. struct tm *restrict __result)
  150. _GL_ARG_NONNULL ((1, 2)));
  151. # endif
  152. _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
  153. struct tm *restrict __result));
  154. # endif
  155. # if @HAVE_DECL_LOCALTIME_R@
  156. _GL_CXXALIASWARN (gmtime_r);
  157. # endif
  158. # endif
  159. /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
  160. <http://www.opengroup.org/susv3xsh/localtime.html> and
  161. <http://www.opengroup.org/susv3xsh/gmtime.html>. */
  162. # if @GNULIB_GETTIMEOFDAY@
  163. # if @REPLACE_LOCALTIME@
  164. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  165. # undef localtime
  166. # define localtime rpl_localtime
  167. # endif
  168. _GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
  169. _GL_ARG_NONNULL ((1)));
  170. _GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
  171. # else
  172. _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
  173. # endif
  174. _GL_CXXALIASWARN (localtime);
  175. # endif
  176. # if @GNULIB_GETTIMEOFDAY@
  177. # if @REPLACE_GMTIME@
  178. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  179. # undef gmtime
  180. # define gmtime rpl_gmtime
  181. # endif
  182. _GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
  183. _GL_ARG_NONNULL ((1)));
  184. _GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
  185. # else
  186. _GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
  187. # endif
  188. _GL_CXXALIASWARN (gmtime);
  189. # endif
  190. /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
  191. the resulting broken-down time into TM. See
  192. <http://www.opengroup.org/susv3xsh/strptime.html>. */
  193. # if @GNULIB_STRPTIME@
  194. # if ! @HAVE_STRPTIME@
  195. _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
  196. char const *restrict __format,
  197. struct tm *restrict __tm)
  198. _GL_ARG_NONNULL ((1, 2, 3)));
  199. # endif
  200. _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
  201. char const *restrict __format,
  202. struct tm *restrict __tm));
  203. _GL_CXXALIASWARN (strptime);
  204. # endif
  205. /* Convert TM to a time_t value, assuming UTC. */
  206. # if @GNULIB_TIMEGM@
  207. # if @REPLACE_TIMEGM@
  208. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  209. # undef timegm
  210. # define timegm rpl_timegm
  211. # endif
  212. _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
  213. _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
  214. # else
  215. # if ! @HAVE_TIMEGM@
  216. _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
  217. # endif
  218. _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
  219. # endif
  220. _GL_CXXALIASWARN (timegm);
  221. # endif
  222. /* Encourage applications to avoid unsafe functions that can overrun
  223. buffers when given outlandish struct tm values. Portable
  224. applications should use strftime (or even sprintf) instead. */
  225. # if defined GNULIB_POSIXCHECK
  226. # undef asctime
  227. _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
  228. "better use strftime (or even sprintf) instead");
  229. # endif
  230. # if defined GNULIB_POSIXCHECK
  231. # undef asctime_r
  232. _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
  233. "better use strftime (or even sprintf) instead");
  234. # endif
  235. # if defined GNULIB_POSIXCHECK
  236. # undef ctime
  237. _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
  238. "better use strftime (or even sprintf) instead");
  239. # endif
  240. # if defined GNULIB_POSIXCHECK
  241. # undef ctime_r
  242. _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
  243. "better use strftime (or even sprintf) instead");
  244. # endif
  245. #endif