time.in.h 8.9 KB

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