Blame lib/time.in.h

Packit 33f14e
/* A more-standard <time.h>.
Packit 33f14e
Packit 33f14e
   Copyright (C) 2007-2017 Free Software Foundation, Inc.
Packit 33f14e
Packit 33f14e
   This program is free software; you can redistribute it and/or modify
Packit 33f14e
   it under the terms of the GNU General Public License as published by
Packit 33f14e
   the Free Software Foundation; either version 3, or (at your option)
Packit 33f14e
   any later version.
Packit 33f14e
Packit 33f14e
   This program is distributed in the hope that it will be useful,
Packit 33f14e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 33f14e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 33f14e
   GNU General Public License for more details.
Packit 33f14e
Packit 33f14e
   You should have received a copy of the GNU General Public License
Packit 33f14e
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit 33f14e
Packit 33f14e
#if __GNUC__ >= 3
Packit 33f14e
@PRAGMA_SYSTEM_HEADER@
Packit 33f14e
#endif
Packit 33f14e
@PRAGMA_COLUMNS@
Packit 33f14e
Packit 33f14e
/* Don't get in the way of glibc when it includes time.h merely to
Packit 33f14e
   declare a few standard symbols, rather than to declare all the
Packit 33f14e
   symbols.  (However, skip this for MinGW as it treats __need_time_t
Packit 33f14e
   incompatibly.)  Also, Solaris 8 <time.h> eventually includes itself
Packit 33f14e
   recursively; if that is happening, just include the system <time.h>
Packit 33f14e
   without adding our own declarations.  */
Packit 33f14e
#if (((defined __need_time_t || defined __need_clock_t \
Packit 33f14e
       || defined __need_timespec)                     \
Packit 33f14e
      && !defined __MINGW32__)                         \
Packit 33f14e
     || defined _@GUARD_PREFIX@_TIME_H)
Packit 33f14e
Packit 33f14e
# @INCLUDE_NEXT@ @NEXT_TIME_H@
Packit 33f14e
Packit 33f14e
#else
Packit 33f14e
Packit 33f14e
# define _@GUARD_PREFIX@_TIME_H
Packit 33f14e
Packit 33f14e
# @INCLUDE_NEXT@ @NEXT_TIME_H@
Packit 33f14e
Packit 33f14e
/* NetBSD 5.0 mis-defines NULL.  */
Packit 33f14e
# include <stddef.h>
Packit 33f14e
Packit 33f14e
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
Packit 33f14e
Packit 33f14e
/* The definition of _GL_ARG_NONNULL is copied here.  */
Packit 33f14e
Packit 33f14e
/* The definition of _GL_WARN_ON_USE is copied here.  */
Packit 33f14e
Packit 33f14e
/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
Packit 33f14e
   Or they define it with the wrong member names or define it in <sys/time.h>
Packit 33f14e
   (e.g., FreeBSD circa 1997).  Stock Mingw prior to 3.0 does not define it,
Packit 33f14e
   but the pthreads-win32 library defines it in <pthread.h>.  */
Packit 33f14e
# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
Packit 33f14e
#  if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
Packit 33f14e
#   include <sys/time.h>
Packit 33f14e
#  elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
Packit 33f14e
#   include <pthread.h>
Packit 33f14e
#  elif @UNISTD_H_DEFINES_STRUCT_TIMESPEC@
Packit 33f14e
#   include <unistd.h>
Packit 33f14e
#  else
Packit 33f14e
Packit 33f14e
#   ifdef __cplusplus
Packit 33f14e
extern "C" {
Packit 33f14e
#   endif
Packit 33f14e
Packit 33f14e
#   if !GNULIB_defined_struct_timespec
Packit 33f14e
#    undef timespec
Packit 33f14e
#    define timespec rpl_timespec
Packit 33f14e
struct timespec
Packit 33f14e
{
Packit 33f14e
  time_t tv_sec;
Packit 33f14e
  long int tv_nsec;
Packit 33f14e
};
Packit 33f14e
#    define GNULIB_defined_struct_timespec 1
Packit 33f14e
#   endif
Packit 33f14e
Packit 33f14e
#   ifdef __cplusplus
Packit 33f14e
}
Packit 33f14e
#   endif
Packit 33f14e
Packit 33f14e
#  endif
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
# if !GNULIB_defined_struct_time_t_must_be_integral
Packit 33f14e
/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
Packit 33f14e
   time_t to be an integer type, even though C99 permits floating
Packit 33f14e
   point.  We don't know of any implementation that uses floating
Packit 33f14e
   point, and it is much easier to write code that doesn't have to
Packit 33f14e
   worry about that corner case, so we force the issue.  */
Packit 33f14e
struct __time_t_must_be_integral {
Packit 33f14e
  unsigned int __floating_time_t_unsupported : (time_t) 1;
Packit 33f14e
};
Packit 33f14e
#  define GNULIB_defined_struct_time_t_must_be_integral 1
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Sleep for at least RQTP seconds unless interrupted,  If interrupted,
Packit 33f14e
   return -1 and store the remaining time into RMTP.  See
Packit 33f14e
   <http://www.opengroup.org/susv3xsh/nanosleep.html>.  */
Packit 33f14e
# if @GNULIB_NANOSLEEP@
Packit 33f14e
#  if @REPLACE_NANOSLEEP@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    define nanosleep rpl_nanosleep
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (nanosleep, int,
Packit 33f14e
                  (struct timespec const *__rqtp, struct timespec *__rmtp)
Packit 33f14e
                  _GL_ARG_NONNULL ((1)));
Packit 33f14e
_GL_CXXALIAS_RPL (nanosleep, int,
Packit 33f14e
                  (struct timespec const *__rqtp, struct timespec *__rmtp));
Packit 33f14e
#  else
Packit 33f14e
#   if ! @HAVE_NANOSLEEP@
Packit 33f14e
_GL_FUNCDECL_SYS (nanosleep, int,
Packit 33f14e
                  (struct timespec const *__rqtp, struct timespec *__rmtp)
Packit 33f14e
                  _GL_ARG_NONNULL ((1)));
Packit 33f14e
#   endif
Packit 33f14e
_GL_CXXALIAS_SYS (nanosleep, int,
Packit 33f14e
                  (struct timespec const *__rqtp, struct timespec *__rmtp));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIASWARN (nanosleep);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Initialize time conversion information.  */
Packit 33f14e
# if @GNULIB_TZSET@
Packit 33f14e
#  if @REPLACE_TZSET@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    undef tzset
Packit 33f14e
#    define tzset rpl_tzset
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (tzset, void, (void));
Packit 33f14e
_GL_CXXALIAS_RPL (tzset, void, (void));
Packit 33f14e
#  else
Packit 33f14e
#   if ! @HAVE_TZSET@
Packit 33f14e
_GL_FUNCDECL_SYS (tzset, void, (void));
Packit 33f14e
#   endif
Packit 33f14e
_GL_CXXALIAS_SYS (tzset, void, (void));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIASWARN (tzset);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Return the 'time_t' representation of TP and normalize TP.  */
Packit 33f14e
# if @GNULIB_MKTIME@
Packit 33f14e
#  if @REPLACE_MKTIME@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    define mktime rpl_mktime
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
Packit 33f14e
_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
Packit 33f14e
#  else
Packit 33f14e
_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIASWARN (mktime);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
Packit 33f14e
   <http://www.opengroup.org/susv3xsh/localtime_r.html> and
Packit 33f14e
   <http://www.opengroup.org/susv3xsh/gmtime_r.html>.  */
Packit 33f14e
# if @GNULIB_TIME_R@
Packit 33f14e
#  if @REPLACE_LOCALTIME_R@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    undef localtime_r
Packit 33f14e
#    define localtime_r rpl_localtime_r
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
Packit 33f14e
                                             struct tm *restrict __result)
Packit 33f14e
                                            _GL_ARG_NONNULL ((1, 2)));
Packit 33f14e
_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
Packit 33f14e
                                             struct tm *restrict __result));
Packit 33f14e
#  else
Packit 33f14e
#   if ! @HAVE_DECL_LOCALTIME_R@
Packit 33f14e
_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
Packit 33f14e
                                             struct tm *restrict __result)
Packit 33f14e
                                            _GL_ARG_NONNULL ((1, 2)));
Packit 33f14e
#   endif
Packit 33f14e
_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
Packit 33f14e
                                             struct tm *restrict __result));
Packit 33f14e
#  endif
Packit 33f14e
#  if @HAVE_DECL_LOCALTIME_R@
Packit 33f14e
_GL_CXXALIASWARN (localtime_r);
Packit 33f14e
#  endif
Packit 33f14e
#  if @REPLACE_LOCALTIME_R@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    undef gmtime_r
Packit 33f14e
#    define gmtime_r rpl_gmtime_r
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
Packit 33f14e
                                          struct tm *restrict __result)
Packit 33f14e
                                         _GL_ARG_NONNULL ((1, 2)));
Packit 33f14e
_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
Packit 33f14e
                                          struct tm *restrict __result));
Packit 33f14e
#  else
Packit 33f14e
#   if ! @HAVE_DECL_LOCALTIME_R@
Packit 33f14e
_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
Packit 33f14e
                                          struct tm *restrict __result)
Packit 33f14e
                                         _GL_ARG_NONNULL ((1, 2)));
Packit 33f14e
#   endif
Packit 33f14e
_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
Packit 33f14e
                                          struct tm *restrict __result));
Packit 33f14e
#  endif
Packit 33f14e
#  if @HAVE_DECL_LOCALTIME_R@
Packit 33f14e
_GL_CXXALIASWARN (gmtime_r);
Packit 33f14e
#  endif
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Convert TIMER to RESULT, assuming local time and UTC respectively.  See
Packit 33f14e
   <http://www.opengroup.org/susv3xsh/localtime.html> and
Packit 33f14e
   <http://www.opengroup.org/susv3xsh/gmtime.html>.  */
Packit 33f14e
# if @GNULIB_LOCALTIME@ || @REPLACE_LOCALTIME@
Packit 33f14e
#  if @REPLACE_LOCALTIME@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    undef localtime
Packit 33f14e
#    define localtime rpl_localtime
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
Packit 33f14e
		                          _GL_ARG_NONNULL ((1)));
Packit 33f14e
_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
Packit 33f14e
#  else
Packit 33f14e
_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIASWARN (localtime);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
# if 0 || @REPLACE_GMTIME@
Packit 33f14e
#  if @REPLACE_GMTIME@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    undef gmtime
Packit 33f14e
#    define gmtime rpl_gmtime
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
Packit 33f14e
                                       _GL_ARG_NONNULL ((1)));
Packit 33f14e
_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
Packit 33f14e
#  else
Packit 33f14e
_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIASWARN (gmtime);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Parse BUF as a timestamp, assuming FORMAT specifies its layout, and store
Packit 33f14e
   the resulting broken-down time into TM.  See
Packit 33f14e
   <http://www.opengroup.org/susv3xsh/strptime.html>.  */
Packit 33f14e
# if @GNULIB_STRPTIME@
Packit 33f14e
#  if ! @HAVE_STRPTIME@
Packit 33f14e
_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
Packit 33f14e
                                     char const *restrict __format,
Packit 33f14e
                                     struct tm *restrict __tm)
Packit 33f14e
                                    _GL_ARG_NONNULL ((1, 2, 3)));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
Packit 33f14e
                                     char const *restrict __format,
Packit 33f14e
                                     struct tm *restrict __tm));
Packit 33f14e
_GL_CXXALIASWARN (strptime);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Convert *TP to a date and time string.  See
Packit 33f14e
   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ctime.html>.  */
Packit 33f14e
# if @GNULIB_CTIME@
Packit 33f14e
#  if @REPLACE_CTIME@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    define ctime rpl_ctime
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
Packit 33f14e
                                 _GL_ARG_NONNULL ((1)));
Packit 33f14e
_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
Packit 33f14e
#  else
Packit 33f14e
_GL_CXXALIAS_SYS (ctime, char *, (time_t const *__tp));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIASWARN (ctime);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Convert *TP to a date and time string.  See
Packit 33f14e
   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html>.  */
Packit 33f14e
# if @GNULIB_STRFTIME@
Packit 33f14e
#  if @REPLACE_STRFTIME@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    define strftime rpl_strftime
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (strftime, size_t, (char *__buf, size_t __bufsize,
Packit 33f14e
                                     const char *__fmt, const struct tm *__tp)
Packit 33f14e
                                    _GL_ARG_NONNULL ((1, 3, 4)));
Packit 33f14e
_GL_CXXALIAS_RPL (strftime, size_t, (char *__buf, size_t __bufsize,
Packit 33f14e
                                     const char *__fmt, const struct tm *__tp));
Packit 33f14e
#  else
Packit 33f14e
_GL_CXXALIAS_SYS (strftime, size_t, (char *__buf, size_t __bufsize,
Packit 33f14e
                                     const char *__fmt, const struct tm *__tp));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIASWARN (strftime);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
# if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
Packit 33f14e
typedef struct tm_zone *timezone_t;
Packit 33f14e
_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
Packit 33f14e
_GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name));
Packit 33f14e
_GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz));
Packit 33f14e
_GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz));
Packit 33f14e
_GL_FUNCDECL_SYS (localtime_rz, struct tm *,
Packit 33f14e
                  (timezone_t __tz, time_t const *restrict __timer,
Packit 33f14e
                   struct tm *restrict __result) _GL_ARG_NONNULL ((2, 3)));
Packit 33f14e
_GL_CXXALIAS_SYS (localtime_rz, struct tm *,
Packit 33f14e
                  (timezone_t __tz, time_t const *restrict __timer,
Packit 33f14e
                   struct tm *restrict __result));
Packit 33f14e
_GL_FUNCDECL_SYS (mktime_z, time_t,
Packit 33f14e
                  (timezone_t __tz, struct tm *restrict __result)
Packit 33f14e
                  _GL_ARG_NONNULL ((2)));
Packit 33f14e
_GL_CXXALIAS_SYS (mktime_z, time_t,
Packit 33f14e
                  (timezone_t __tz, struct tm *restrict __result));
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Convert TM to a time_t value, assuming UTC.  */
Packit 33f14e
# if @GNULIB_TIMEGM@
Packit 33f14e
#  if @REPLACE_TIMEGM@
Packit 33f14e
#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
Packit 33f14e
#    undef timegm
Packit 33f14e
#    define timegm rpl_timegm
Packit 33f14e
#   endif
Packit 33f14e
_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
Packit 33f14e
_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
Packit 33f14e
#  else
Packit 33f14e
#   if ! @HAVE_TIMEGM@
Packit 33f14e
_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
Packit 33f14e
#   endif
Packit 33f14e
_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
Packit 33f14e
#  endif
Packit 33f14e
_GL_CXXALIASWARN (timegm);
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
/* Encourage applications to avoid unsafe functions that can overrun
Packit 33f14e
   buffers when given outlandish struct tm values.  Portable
Packit 33f14e
   applications should use strftime (or even sprintf) instead.  */
Packit 33f14e
# if defined GNULIB_POSIXCHECK
Packit 33f14e
#  undef asctime
Packit 33f14e
_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
Packit 33f14e
                 "better use strftime (or even sprintf) instead");
Packit 33f14e
# endif
Packit 33f14e
# if defined GNULIB_POSIXCHECK
Packit 33f14e
#  undef asctime_r
Packit 33f14e
_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
Packit 33f14e
                 "better use strftime (or even sprintf) instead");
Packit 33f14e
# endif
Packit 33f14e
# if defined GNULIB_POSIXCHECK
Packit 33f14e
#  undef ctime
Packit 33f14e
_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
Packit 33f14e
                 "better use strftime (or even sprintf) instead");
Packit 33f14e
# endif
Packit 33f14e
# if defined GNULIB_POSIXCHECK
Packit 33f14e
#  undef ctime_r
Packit 33f14e
_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
Packit 33f14e
                 "better use strftime (or even sprintf) instead");
Packit 33f14e
# endif
Packit 33f14e
Packit 33f14e
#endif