time.in.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* A more-standard <time.h>.
  2. Copyright (C) 2007-2010 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, 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. /* 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 _GL_TIME_H)
  25. # @INCLUDE_NEXT@ @NEXT_TIME_H@
  26. #else
  27. # define _GL_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 does not define it, but the
  37. 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. /* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */
  44. # undef asctime_r
  45. # undef ctime_r
  46. # undef gmtime_r
  47. # undef localtime_r
  48. # undef rand_r
  49. # undef strtok_r
  50. # else
  51. # ifdef __cplusplus
  52. extern "C" {
  53. # endif
  54. # undef timespec
  55. # define timespec rpl_timespec
  56. struct timespec
  57. {
  58. time_t tv_sec;
  59. long int tv_nsec;
  60. };
  61. # ifdef __cplusplus
  62. }
  63. # endif
  64. # endif
  65. # endif
  66. /* Sleep for at least RQTP seconds unless interrupted, If interrupted,
  67. return -1 and store the remaining time into RMTP. See
  68. <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
  69. # if @GNULIB_NANOSLEEP@
  70. # if @REPLACE_NANOSLEEP@
  71. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  72. # define nanosleep rpl_nanosleep
  73. # endif
  74. _GL_FUNCDECL_RPL (nanosleep, int,
  75. (struct timespec const *__rqtp, struct timespec *__rmtp)
  76. _GL_ARG_NONNULL ((1)));
  77. _GL_CXXALIAS_RPL (nanosleep, int,
  78. (struct timespec const *__rqtp, struct timespec *__rmtp));
  79. # else
  80. # if ! @HAVE_NANOSLEEP@
  81. _GL_FUNCDECL_SYS (nanosleep, int,
  82. (struct timespec const *__rqtp, struct timespec *__rmtp)
  83. _GL_ARG_NONNULL ((1)));
  84. # endif
  85. _GL_CXXALIAS_SYS (nanosleep, int,
  86. (struct timespec const *__rqtp, struct timespec *__rmtp));
  87. # endif
  88. _GL_CXXALIASWARN (nanosleep);
  89. # endif
  90. /* Return the 'time_t' representation of TP and normalize TP. */
  91. # if @GNULIB_MKTIME@
  92. # if @REPLACE_MKTIME@
  93. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  94. # define mktime rpl_mktime
  95. # endif
  96. _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
  97. _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
  98. # else
  99. _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
  100. # endif
  101. _GL_CXXALIASWARN (mktime);
  102. # endif
  103. /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
  104. <http://www.opengroup.org/susv3xsh/localtime_r.html> and
  105. <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
  106. # if @GNULIB_TIME_R@
  107. # if @REPLACE_LOCALTIME_R@
  108. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  109. # undef localtime_r
  110. # define localtime_r rpl_localtime_r
  111. # endif
  112. _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
  113. struct tm *restrict __result)
  114. _GL_ARG_NONNULL ((1, 2)));
  115. _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
  116. struct tm *restrict __result));
  117. # else
  118. # if ! @HAVE_LOCALTIME_R@
  119. _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
  120. struct tm *restrict __result)
  121. _GL_ARG_NONNULL ((1, 2)));
  122. # endif
  123. _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
  124. struct tm *restrict __result));
  125. # endif
  126. _GL_CXXALIASWARN (localtime_r);
  127. # if @REPLACE_LOCALTIME_R@
  128. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  129. # undef gmtime_r
  130. # define gmtime_r rpl_gmtime_r
  131. # endif
  132. _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
  133. struct tm *restrict __result)
  134. _GL_ARG_NONNULL ((1, 2)));
  135. _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
  136. struct tm *restrict __result));
  137. # else
  138. # if ! @HAVE_LOCALTIME_R@
  139. _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
  140. struct tm *restrict __result)
  141. _GL_ARG_NONNULL ((1, 2)));
  142. # endif
  143. _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
  144. struct tm *restrict __result));
  145. # endif
  146. _GL_CXXALIASWARN (gmtime_r);
  147. # endif
  148. /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
  149. the resulting broken-down time into TM. See
  150. <http://www.opengroup.org/susv3xsh/strptime.html>. */
  151. # if @GNULIB_STRPTIME@
  152. # if ! @HAVE_STRPTIME@
  153. _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
  154. char const *restrict __format,
  155. struct tm *restrict __tm)
  156. _GL_ARG_NONNULL ((1, 2, 3)));
  157. # endif
  158. _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
  159. char const *restrict __format,
  160. struct tm *restrict __tm));
  161. _GL_CXXALIASWARN (strptime);
  162. # endif
  163. /* Convert TM to a time_t value, assuming UTC. */
  164. # if @GNULIB_TIMEGM@
  165. # if @REPLACE_TIMEGM@
  166. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  167. # undef timegm
  168. # define timegm rpl_timegm
  169. # endif
  170. _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
  171. _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
  172. # else
  173. # if ! @HAVE_TIMEGM@
  174. _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
  175. # endif
  176. _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
  177. # endif
  178. _GL_CXXALIASWARN (timegm);
  179. # endif
  180. /* Encourage applications to avoid unsafe functions that can overrun
  181. buffers when given outlandish struct tm values. Portable
  182. applications should use strftime (or even sprintf) instead. */
  183. # if defined GNULIB_POSIXCHECK
  184. # undef asctime
  185. _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
  186. "better use strftime (or even sprintf) instead");
  187. # endif
  188. # if defined GNULIB_POSIXCHECK
  189. # undef asctime_r
  190. _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
  191. "better use strftime (or even sprintf) instead");
  192. # endif
  193. # if defined GNULIB_POSIXCHECK
  194. # undef ctime
  195. _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
  196. "better use strftime (or even sprintf) instead");
  197. # endif
  198. # if defined GNULIB_POSIXCHECK
  199. # undef ctime_r
  200. _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
  201. "better use strftime (or even sprintf) instead");
  202. # endif
  203. #endif