Blame src/gl/time.in.h

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