time.in.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* A more-standard <time.h>.
  2. Copyright (C) 2007-2015 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 General Public License as published by
  5. the Free Software Foundation; either version 3, 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 General Public License for more details.
  11. You should have received a copy of the GNU 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. # elif @UNISTD_H_DEFINES_STRUCT_TIMESPEC@
  44. # include <unistd.h>
  45. # else
  46. # ifdef __cplusplus
  47. extern "C" {
  48. # endif
  49. # if !GNULIB_defined_struct_timespec
  50. # undef timespec
  51. # define timespec rpl_timespec
  52. struct timespec
  53. {
  54. time_t tv_sec;
  55. long int tv_nsec;
  56. };
  57. # define GNULIB_defined_struct_timespec 1
  58. # endif
  59. # ifdef __cplusplus
  60. }
  61. # endif
  62. # endif
  63. # endif
  64. # if !GNULIB_defined_struct_time_t_must_be_integral
  65. /* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
  66. time_t to be an integer type, even though C99 permits floating
  67. point. We don't know of any implementation that uses floating
  68. point, and it is much easier to write code that doesn't have to
  69. worry about that corner case, so we force the issue. */
  70. struct __time_t_must_be_integral {
  71. unsigned int __floating_time_t_unsupported : (time_t) 1;
  72. };
  73. # define GNULIB_defined_struct_time_t_must_be_integral 1
  74. # endif
  75. /* Sleep for at least RQTP seconds unless interrupted, If interrupted,
  76. return -1 and store the remaining time into RMTP. See
  77. <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
  78. # if @GNULIB_NANOSLEEP@
  79. # if @REPLACE_NANOSLEEP@
  80. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  81. # define nanosleep rpl_nanosleep
  82. # endif
  83. _GL_FUNCDECL_RPL (nanosleep, int,
  84. (struct timespec const *__rqtp, struct timespec *__rmtp)
  85. _GL_ARG_NONNULL ((1)));
  86. _GL_CXXALIAS_RPL (nanosleep, int,
  87. (struct timespec const *__rqtp, struct timespec *__rmtp));
  88. # else
  89. # if ! @HAVE_NANOSLEEP@
  90. _GL_FUNCDECL_SYS (nanosleep, int,
  91. (struct timespec const *__rqtp, struct timespec *__rmtp)
  92. _GL_ARG_NONNULL ((1)));
  93. # endif
  94. _GL_CXXALIAS_SYS (nanosleep, int,
  95. (struct timespec const *__rqtp, struct timespec *__rmtp));
  96. # endif
  97. _GL_CXXALIASWARN (nanosleep);
  98. # endif
  99. /* Return the 'time_t' representation of TP and normalize TP. */
  100. # if @GNULIB_MKTIME@
  101. # if @REPLACE_MKTIME@
  102. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  103. # define mktime rpl_mktime
  104. # endif
  105. _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
  106. _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
  107. # else
  108. _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
  109. # endif
  110. _GL_CXXALIASWARN (mktime);
  111. # endif
  112. /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
  113. <http://www.opengroup.org/susv3xsh/localtime_r.html> and
  114. <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
  115. # if @GNULIB_TIME_R@
  116. # if @REPLACE_LOCALTIME_R@
  117. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  118. # undef localtime_r
  119. # define localtime_r rpl_localtime_r
  120. # endif
  121. _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
  122. struct tm *restrict __result)
  123. _GL_ARG_NONNULL ((1, 2)));
  124. _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
  125. struct tm *restrict __result));
  126. # else
  127. # if ! @HAVE_DECL_LOCALTIME_R@
  128. _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
  129. struct tm *restrict __result)
  130. _GL_ARG_NONNULL ((1, 2)));
  131. # endif
  132. _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
  133. struct tm *restrict __result));
  134. # endif
  135. # if @HAVE_DECL_LOCALTIME_R@
  136. _GL_CXXALIASWARN (localtime_r);
  137. # endif
  138. # if @REPLACE_LOCALTIME_R@
  139. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  140. # undef gmtime_r
  141. # define gmtime_r rpl_gmtime_r
  142. # endif
  143. _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
  144. struct tm *restrict __result)
  145. _GL_ARG_NONNULL ((1, 2)));
  146. _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
  147. struct tm *restrict __result));
  148. # else
  149. # if ! @HAVE_DECL_LOCALTIME_R@
  150. _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
  151. struct tm *restrict __result)
  152. _GL_ARG_NONNULL ((1, 2)));
  153. # endif
  154. _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
  155. struct tm *restrict __result));
  156. # endif
  157. # if @HAVE_DECL_LOCALTIME_R@
  158. _GL_CXXALIASWARN (gmtime_r);
  159. # endif
  160. # endif
  161. /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
  162. <http://www.opengroup.org/susv3xsh/localtime.html> and
  163. <http://www.opengroup.org/susv3xsh/gmtime.html>. */
  164. # if @GNULIB_GETTIMEOFDAY@
  165. # if @REPLACE_LOCALTIME@
  166. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  167. # undef localtime
  168. # define localtime rpl_localtime
  169. # endif
  170. _GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
  171. _GL_ARG_NONNULL ((1)));
  172. _GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
  173. # else
  174. _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
  175. # endif
  176. _GL_CXXALIASWARN (localtime);
  177. # endif
  178. # if @GNULIB_GETTIMEOFDAY@
  179. # if @REPLACE_GMTIME@
  180. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  181. # undef gmtime
  182. # define gmtime rpl_gmtime
  183. # endif
  184. _GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
  185. _GL_ARG_NONNULL ((1)));
  186. _GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
  187. # else
  188. _GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
  189. # endif
  190. _GL_CXXALIASWARN (gmtime);
  191. # endif
  192. /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
  193. the resulting broken-down time into TM. See
  194. <http://www.opengroup.org/susv3xsh/strptime.html>. */
  195. # if @GNULIB_STRPTIME@
  196. # if ! @HAVE_STRPTIME@
  197. _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
  198. char const *restrict __format,
  199. struct tm *restrict __tm)
  200. _GL_ARG_NONNULL ((1, 2, 3)));
  201. # endif
  202. _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
  203. char const *restrict __format,
  204. struct tm *restrict __tm));
  205. _GL_CXXALIASWARN (strptime);
  206. # endif
  207. /* Convert TM to a time_t value, assuming UTC. */
  208. # if @GNULIB_TIMEGM@
  209. # if @REPLACE_TIMEGM@
  210. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  211. # undef timegm
  212. # define timegm rpl_timegm
  213. # endif
  214. _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
  215. _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
  216. # else
  217. # if ! @HAVE_TIMEGM@
  218. _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
  219. # endif
  220. _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
  221. # endif
  222. _GL_CXXALIASWARN (timegm);
  223. # endif
  224. /* Encourage applications to avoid unsafe functions that can overrun
  225. buffers when given outlandish struct tm values. Portable
  226. applications should use strftime (or even sprintf) instead. */
  227. # if defined GNULIB_POSIXCHECK
  228. # undef asctime
  229. _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
  230. "better use strftime (or even sprintf) instead");
  231. # endif
  232. # if defined GNULIB_POSIXCHECK
  233. # undef asctime_r
  234. _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
  235. "better use strftime (or even sprintf) instead");
  236. # endif
  237. # if defined GNULIB_POSIXCHECK
  238. # undef ctime
  239. _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
  240. "better use strftime (or even sprintf) instead");
  241. # endif
  242. # if defined GNULIB_POSIXCHECK
  243. # undef ctime_r
  244. _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
  245. "better use strftime (or even sprintf) instead");
  246. # endif
  247. #endif