time.in.h 7.8 KB

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