PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/time.in.h

https://gitlab.com/wilfred/emacs
C Header | 297 lines | 219 code | 26 blank | 52 comment | 50 complexity | 5edffd432a27b27476bc33ac5b4cdc78 MD5 | raw file
  1. /* A more-standard <time.h>.
  2. Copyright (C) 2007-2016 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. (However, skip this for MinGW as it treats __need_time_t
  20. incompatibly.) 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 __MINGW32__) \
  26. || defined _@GUARD_PREFIX@_TIME_H)
  27. # @INCLUDE_NEXT@ @NEXT_TIME_H@
  28. #else
  29. # define _@GUARD_PREFIX@_TIME_H
  30. # @INCLUDE_NEXT@ @NEXT_TIME_H@
  31. /* NetBSD 5.0 mis-defines NULL. */
  32. # include <stddef.h>
  33. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  34. /* The definition of _GL_ARG_NONNULL is copied here. */
  35. /* The definition of _GL_WARN_ON_USE is copied here. */
  36. /* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
  37. Or they define it with the wrong member names or define it in <sys/time.h>
  38. (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 does not define it,
  39. but the pthreads-win32 library defines it in <pthread.h>. */
  40. # if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
  41. # if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
  42. # include <sys/time.h>
  43. # elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
  44. # include <pthread.h>
  45. # elif @UNISTD_H_DEFINES_STRUCT_TIMESPEC@
  46. # include <unistd.h>
  47. # else
  48. # ifdef __cplusplus
  49. extern "C" {
  50. # endif
  51. # if !GNULIB_defined_struct_timespec
  52. # undef timespec
  53. # define timespec rpl_timespec
  54. struct timespec
  55. {
  56. time_t tv_sec;
  57. long int tv_nsec;
  58. };
  59. # define GNULIB_defined_struct_timespec 1
  60. # endif
  61. # ifdef __cplusplus
  62. }
  63. # endif
  64. # endif
  65. # endif
  66. # if !GNULIB_defined_struct_time_t_must_be_integral
  67. /* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
  68. time_t to be an integer type, even though C99 permits floating
  69. point. We don't know of any implementation that uses floating
  70. point, and it is much easier to write code that doesn't have to
  71. worry about that corner case, so we force the issue. */
  72. struct __time_t_must_be_integral {
  73. unsigned int __floating_time_t_unsupported : (time_t) 1;
  74. };
  75. # define GNULIB_defined_struct_time_t_must_be_integral 1
  76. # endif
  77. /* Sleep for at least RQTP seconds unless interrupted, If interrupted,
  78. return -1 and store the remaining time into RMTP. See
  79. <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
  80. # if @GNULIB_NANOSLEEP@
  81. # if @REPLACE_NANOSLEEP@
  82. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  83. # define nanosleep rpl_nanosleep
  84. # endif
  85. _GL_FUNCDECL_RPL (nanosleep, int,
  86. (struct timespec const *__rqtp, struct timespec *__rmtp)
  87. _GL_ARG_NONNULL ((1)));
  88. _GL_CXXALIAS_RPL (nanosleep, int,
  89. (struct timespec const *__rqtp, struct timespec *__rmtp));
  90. # else
  91. # if ! @HAVE_NANOSLEEP@
  92. _GL_FUNCDECL_SYS (nanosleep, int,
  93. (struct timespec const *__rqtp, struct timespec *__rmtp)
  94. _GL_ARG_NONNULL ((1)));
  95. # endif
  96. _GL_CXXALIAS_SYS (nanosleep, int,
  97. (struct timespec const *__rqtp, struct timespec *__rmtp));
  98. # endif
  99. _GL_CXXALIASWARN (nanosleep);
  100. # endif
  101. /* Return the 'time_t' representation of TP and normalize TP. */
  102. # if @GNULIB_MKTIME@
  103. # if @REPLACE_MKTIME@
  104. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  105. # define mktime rpl_mktime
  106. # endif
  107. _GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
  108. _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
  109. # else
  110. _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
  111. # endif
  112. _GL_CXXALIASWARN (mktime);
  113. # endif
  114. /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
  115. <http://www.opengroup.org/susv3xsh/localtime_r.html> and
  116. <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
  117. # if @GNULIB_TIME_R@
  118. # if @REPLACE_LOCALTIME_R@
  119. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  120. # undef localtime_r
  121. # define localtime_r rpl_localtime_r
  122. # endif
  123. _GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
  124. struct tm *restrict __result)
  125. _GL_ARG_NONNULL ((1, 2)));
  126. _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
  127. struct tm *restrict __result));
  128. # else
  129. # if ! @HAVE_DECL_LOCALTIME_R@
  130. _GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
  131. struct tm *restrict __result)
  132. _GL_ARG_NONNULL ((1, 2)));
  133. # endif
  134. _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
  135. struct tm *restrict __result));
  136. # endif
  137. # if @HAVE_DECL_LOCALTIME_R@
  138. _GL_CXXALIASWARN (localtime_r);
  139. # endif
  140. # if @REPLACE_LOCALTIME_R@
  141. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  142. # undef gmtime_r
  143. # define gmtime_r rpl_gmtime_r
  144. # endif
  145. _GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
  146. struct tm *restrict __result)
  147. _GL_ARG_NONNULL ((1, 2)));
  148. _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
  149. struct tm *restrict __result));
  150. # else
  151. # if ! @HAVE_DECL_LOCALTIME_R@
  152. _GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
  153. struct tm *restrict __result)
  154. _GL_ARG_NONNULL ((1, 2)));
  155. # endif
  156. _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
  157. struct tm *restrict __result));
  158. # endif
  159. # if @HAVE_DECL_LOCALTIME_R@
  160. _GL_CXXALIASWARN (gmtime_r);
  161. # endif
  162. # endif
  163. /* Convert TIMER to RESULT, assuming local time and UTC respectively. See
  164. <http://www.opengroup.org/susv3xsh/localtime.html> and
  165. <http://www.opengroup.org/susv3xsh/gmtime.html>. */
  166. # if @GNULIB_GETTIMEOFDAY@
  167. # if @REPLACE_LOCALTIME@
  168. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  169. # undef localtime
  170. # define localtime rpl_localtime
  171. # endif
  172. _GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
  173. _GL_ARG_NONNULL ((1)));
  174. _GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
  175. # else
  176. _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
  177. # endif
  178. _GL_CXXALIASWARN (localtime);
  179. # endif
  180. # if @GNULIB_GETTIMEOFDAY@
  181. # if @REPLACE_GMTIME@
  182. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  183. # undef gmtime
  184. # define gmtime rpl_gmtime
  185. # endif
  186. _GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
  187. _GL_ARG_NONNULL ((1)));
  188. _GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
  189. # else
  190. _GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
  191. # endif
  192. _GL_CXXALIASWARN (gmtime);
  193. # endif
  194. /* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
  195. the resulting broken-down time into TM. See
  196. <http://www.opengroup.org/susv3xsh/strptime.html>. */
  197. # if @GNULIB_STRPTIME@
  198. # if ! @HAVE_STRPTIME@
  199. _GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
  200. char const *restrict __format,
  201. struct tm *restrict __tm)
  202. _GL_ARG_NONNULL ((1, 2, 3)));
  203. # endif
  204. _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
  205. char const *restrict __format,
  206. struct tm *restrict __tm));
  207. _GL_CXXALIASWARN (strptime);
  208. # endif
  209. # if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
  210. typedef struct tm_zone *timezone_t;
  211. _GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
  212. _GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name));
  213. _GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz));
  214. _GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz));
  215. _GL_FUNCDECL_SYS (localtime_rz, struct tm *,
  216. (timezone_t __tz, time_t const *restrict __timer,
  217. struct tm *restrict __result) _GL_ARG_NONNULL ((2, 3)));
  218. _GL_CXXALIAS_SYS (localtime_rz, struct tm *,
  219. (timezone_t __tz, time_t const *restrict __timer,
  220. struct tm *restrict __result));
  221. _GL_FUNCDECL_SYS (mktime_z, time_t,
  222. (timezone_t __tz, struct tm *restrict __result)
  223. _GL_ARG_NONNULL ((2)));
  224. _GL_CXXALIAS_SYS (mktime_z, time_t,
  225. (timezone_t __tz, struct tm *restrict __result));
  226. # endif
  227. /* Convert TM to a time_t value, assuming UTC. */
  228. # if @GNULIB_TIMEGM@
  229. # if @REPLACE_TIMEGM@
  230. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  231. # undef timegm
  232. # define timegm rpl_timegm
  233. # endif
  234. _GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
  235. _GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
  236. # else
  237. # if ! @HAVE_TIMEGM@
  238. _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
  239. # endif
  240. _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
  241. # endif
  242. _GL_CXXALIASWARN (timegm);
  243. # endif
  244. /* Encourage applications to avoid unsafe functions that can overrun
  245. buffers when given outlandish struct tm values. Portable
  246. applications should use strftime (or even sprintf) instead. */
  247. # if defined GNULIB_POSIXCHECK
  248. # undef asctime
  249. _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
  250. "better use strftime (or even sprintf) instead");
  251. # endif
  252. # if defined GNULIB_POSIXCHECK
  253. # undef asctime_r
  254. _GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
  255. "better use strftime (or even sprintf) instead");
  256. # endif
  257. # if defined GNULIB_POSIXCHECK
  258. # undef ctime
  259. _GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
  260. "better use strftime (or even sprintf) instead");
  261. # endif
  262. # if defined GNULIB_POSIXCHECK
  263. # undef ctime_r
  264. _GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
  265. "better use strftime (or even sprintf) instead");
  266. # endif
  267. #endif