Changeset View
Changeset View
Standalone View
Standalone View
contrib/tzcode/private.h
Show All 11 Lines | |||||
/* | /* | ||||
** This header is for use ONLY with the time conversion code. | ** This header is for use ONLY with the time conversion code. | ||||
** There is no guarantee that it will remain unchanged, | ** There is no guarantee that it will remain unchanged, | ||||
** or that it will remain at all. | ** or that it will remain at all. | ||||
** Do NOT copy it to any system include directory. | ** Do NOT copy it to any system include directory. | ||||
** Thank you! | ** Thank you! | ||||
*/ | */ | ||||
/* PORT_TO_C89 means the code should work even if the underlying | |||||
compiler and library support only C89. SUPPORT_C89 means the | |||||
tzcode library should support C89 callers in addition to the usual | |||||
support for C99-and-later callers. These macros are obsolescent, | |||||
and the plan is to remove them along with any code needed only when | |||||
they are nonzero. */ | |||||
#ifndef PORT_TO_C89 | |||||
# define PORT_TO_C89 0 | |||||
#endif | |||||
#ifndef SUPPORT_C89 | |||||
# define SUPPORT_C89 0 | |||||
#endif | |||||
#ifndef __STDC_VERSION__ | #ifndef __STDC_VERSION__ | ||||
# define __STDC_VERSION__ 0 | # define __STDC_VERSION__ 0 | ||||
#endif | #endif | ||||
/* Define true, false and bool if they don't work out of the box. */ | /* Define true, false and bool if they don't work out of the box. */ | ||||
#if __STDC_VERSION__ < 199901 | #if PORT_TO_C89 && __STDC_VERSION__ < 199901 | ||||
# define true 1 | # define true 1 | ||||
# define false 0 | # define false 0 | ||||
# define bool int | # define bool int | ||||
#elif __STDC_VERSION__ < 202311 | #elif __STDC_VERSION__ < 202311 | ||||
# include <stdbool.h> | # include <stdbool.h> | ||||
#endif | #endif | ||||
#if __STDC_VERSION__ < 202311 | |||||
# define static_assert(cond) extern int static_assert_check[(cond) ? 1 : -1] | |||||
#endif | |||||
/* | /* | ||||
** zdump has been made independent of the rest of the time | ** zdump has been made independent of the rest of the time | ||||
** conversion package to increase confidence in the verification it provides. | ** conversion package to increase confidence in the verification it provides. | ||||
** You can use zdump to help in verifying other implementations. | ** You can use zdump to help in verifying other implementations. | ||||
** To do this, compile with -DUSE_LTZ=0 and link without the tz library. | ** To do this, compile with -DUSE_LTZ=0 and link without the tz library. | ||||
*/ | */ | ||||
#ifndef USE_LTZ | #ifndef USE_LTZ | ||||
# define USE_LTZ 1 | # define USE_LTZ 1 | ||||
#endif | #endif | ||||
/* This string was in the Factory zone through version 2016f. */ | /* This string was in the Factory zone through version 2016f. */ | ||||
#define GRANDPARENTED "Local time zone must be set--use tzsetup" | #define GRANDPARENTED "Local time zone must be set--use tzsetup" | ||||
/* | /* | ||||
** Defaults for preprocessor symbols. | ** Defaults for preprocessor symbols. | ||||
** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'. | ** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'. | ||||
*/ | */ | ||||
#ifndef HAVE_DECL_ASCTIME_R | #ifndef HAVE_DECL_ASCTIME_R | ||||
# define HAVE_DECL_ASCTIME_R 1 | # define HAVE_DECL_ASCTIME_R 1 | ||||
#endif | #endif | ||||
#if !defined HAVE_GENERIC && defined __has_extension | #if !defined HAVE__GENERIC && defined __has_extension | ||||
# if __has_extension(c_generic_selections) | # if __has_extension(c_generic_selections) | ||||
# define HAVE_GENERIC 1 | # define HAVE__GENERIC 1 | ||||
# else | # else | ||||
# define HAVE_GENERIC 0 | # define HAVE__GENERIC 0 | ||||
# endif | # endif | ||||
#endif | #endif | ||||
/* _Generic is buggy in pre-4.9 GCC. */ | /* _Generic is buggy in pre-4.9 GCC. */ | ||||
#if !defined HAVE_GENERIC && defined __GNUC__ && !defined __STRICT_ANSI__ | #if !defined HAVE__GENERIC && defined __GNUC__ && !defined __STRICT_ANSI__ | ||||
# define HAVE_GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__)) | # define HAVE__GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__)) | ||||
#endif | #endif | ||||
#ifndef HAVE_GENERIC | #ifndef HAVE__GENERIC | ||||
# define HAVE_GENERIC (201112 <= __STDC_VERSION__) | # define HAVE__GENERIC (201112 <= __STDC_VERSION__) | ||||
#endif | #endif | ||||
#if !defined HAVE_GETTEXT && defined __has_include | #if !defined HAVE_GETTEXT && defined __has_include | ||||
# if __has_include(<libintl.h>) | # if __has_include(<libintl.h>) | ||||
# define HAVE_GETTEXT true | # define HAVE_GETTEXT true | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef HAVE_GETTEXT | #ifndef HAVE_GETTEXT | ||||
Show All 19 Lines | |||||
#ifndef HAVE_SETENV | #ifndef HAVE_SETENV | ||||
# define HAVE_SETENV 1 | # define HAVE_SETENV 1 | ||||
#endif | #endif | ||||
#ifndef HAVE_STRDUP | #ifndef HAVE_STRDUP | ||||
# define HAVE_STRDUP 1 | # define HAVE_STRDUP 1 | ||||
#endif | #endif | ||||
#ifndef HAVE_STRTOLL | |||||
# define HAVE_STRTOLL 1 | |||||
#endif | |||||
#ifndef HAVE_SYMLINK | #ifndef HAVE_SYMLINK | ||||
# define HAVE_SYMLINK 1 | # define HAVE_SYMLINK 1 | ||||
#endif /* !defined HAVE_SYMLINK */ | #endif /* !defined HAVE_SYMLINK */ | ||||
#if !defined HAVE_SYS_STAT_H && defined __has_include | #if !defined HAVE_SYS_STAT_H && defined __has_include | ||||
# if !__has_include(<sys/stat.h>) | # if !__has_include(<sys/stat.h>) | ||||
# define HAVE_SYS_STAT_H false | # define HAVE_SYS_STAT_H false | ||||
# endif | # endif | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
# undef timezone | # undef timezone | ||||
#endif | #endif | ||||
#undef timezone_t | #undef timezone_t | ||||
#undef tzalloc | #undef tzalloc | ||||
#undef tzfree | #undef tzfree | ||||
#include <stddef.h> | #include <stddef.h> | ||||
#include <string.h> | #include <string.h> | ||||
#if !PORT_TO_C89 | |||||
# include <inttypes.h> | |||||
#endif | |||||
#include <limits.h> /* for CHAR_BIT et al. */ | #include <limits.h> /* for CHAR_BIT et al. */ | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#ifndef EINVAL | #ifndef EINVAL | ||||
# define EINVAL ERANGE | # define EINVAL ERANGE | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
# define ALTZONE 0 | # define ALTZONE 0 | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef R_OK | #ifndef R_OK | ||||
# define R_OK 4 | # define R_OK 4 | ||||
#endif /* !defined R_OK */ | #endif /* !defined R_OK */ | ||||
#if PORT_TO_C89 | |||||
/* | /* | ||||
** Define HAVE_STDINT_H's default value here, rather than at the | ** Define HAVE_STDINT_H's default value here, rather than at the | ||||
** start, since __GLIBC__ and INTMAX_MAX's values depend on | ** start, since __GLIBC__ and INTMAX_MAX's values depend on | ||||
** previously-included files. glibc 2.1 and Solaris 10 and later have | ** previously included files. glibc 2.1 and Solaris 10 and later have | ||||
** stdint.h, even with pre-C99 compilers. | ** stdint.h, even with pre-C99 compilers. | ||||
*/ | */ | ||||
#if !defined HAVE_STDINT_H && defined __has_include | #if !defined HAVE_STDINT_H && defined __has_include | ||||
# define HAVE_STDINT_H true /* C23 __has_include implies C99 stdint.h. */ | # define HAVE_STDINT_H true /* C23 __has_include implies C99 stdint.h. */ | ||||
#endif | #endif | ||||
#ifndef HAVE_STDINT_H | #ifndef HAVE_STDINT_H | ||||
# define HAVE_STDINT_H \ | # define HAVE_STDINT_H \ | ||||
(199901 <= __STDC_VERSION__ \ | (199901 <= __STDC_VERSION__ \ | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
# define INT_FAST32_MAX INT_MAX | # define INT_FAST32_MAX INT_MAX | ||||
# define INT_FAST32_MIN INT_MIN | # define INT_FAST32_MIN INT_MIN | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef INTMAX_MAX | #ifndef INTMAX_MAX | ||||
# ifdef LLONG_MAX | # ifdef LLONG_MAX | ||||
typedef long long intmax_t; | typedef long long intmax_t; | ||||
# ifndef HAVE_STRTOLL | |||||
# define HAVE_STRTOLL true | |||||
# endif | |||||
# if HAVE_STRTOLL | # if HAVE_STRTOLL | ||||
# define strtoimax strtoll | # define strtoimax strtoll | ||||
# endif | # endif | ||||
# define INTMAX_MAX LLONG_MAX | # define INTMAX_MAX LLONG_MAX | ||||
# define INTMAX_MIN LLONG_MIN | # define INTMAX_MIN LLONG_MIN | ||||
# else | # else | ||||
typedef long intmax_t; | typedef long intmax_t; | ||||
# define INTMAX_MAX LONG_MAX | # define INTMAX_MAX LONG_MAX | ||||
Show All 29 Lines | |||||
typedef unsigned long long uint_fast64_t; | typedef unsigned long long uint_fast64_t; | ||||
# define UINT_FAST64_MAX ULLONG_MAX | # define UINT_FAST64_MAX ULLONG_MAX | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef UINTMAX_MAX | #ifndef UINTMAX_MAX | ||||
# ifdef ULLONG_MAX | # ifdef ULLONG_MAX | ||||
typedef unsigned long long uintmax_t; | typedef unsigned long long uintmax_t; | ||||
# define UINTMAX_MAX ULLONG_MAX | |||||
# else | # else | ||||
typedef unsigned long uintmax_t; | typedef unsigned long uintmax_t; | ||||
# define UINTMAX_MAX ULONG_MAX | |||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef PRIuMAX | #ifndef PRIuMAX | ||||
# ifdef ULLONG_MAX | # ifdef ULLONG_MAX | ||||
# define PRIuMAX "llu" | # define PRIuMAX "llu" | ||||
# else | # else | ||||
# define PRIuMAX "lu" | # define PRIuMAX "lu" | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef SIZE_MAX | #ifndef SIZE_MAX | ||||
# define SIZE_MAX ((size_t) -1) | # define SIZE_MAX ((size_t) -1) | ||||
#endif | #endif | ||||
#endif /* PORT_TO_C89 */ | |||||
/* The maximum size of any created object, as a signed integer. | |||||
Although the C standard does not outright prohibit larger objects, | |||||
behavior is undefined if the result of pointer subtraction does not | |||||
fit into ptrdiff_t, and the code assumes in several places that | |||||
pointer subtraction works. As a practical matter it's OK to not | |||||
support objects larger than this. */ | |||||
#define INDEX_MAX ((ptrdiff_t) min(PTRDIFF_MAX, SIZE_MAX)) | |||||
/* Support ckd_add, ckd_sub, ckd_mul on C23 or recent-enough GCC-like | /* Support ckd_add, ckd_sub, ckd_mul on C23 or recent-enough GCC-like | ||||
hosts, unless compiled with -DHAVE_STDCKDINT_H=0 or with pre-C23 EDG. */ | hosts, unless compiled with -DHAVE_STDCKDINT_H=0 or with pre-C23 EDG. */ | ||||
#if !defined HAVE_STDCKDINT_H && defined __has_include | #if !defined HAVE_STDCKDINT_H && defined __has_include | ||||
# if __has_include(<stdckdint.h>) | # if __has_include(<stdckdint.h>) | ||||
# define HAVE_STDCKDINT_H true | # define HAVE_STDCKDINT_H true | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifdef HAVE_STDCKDINT_H | #ifdef HAVE_STDCKDINT_H | ||||
Show All 23 Lines | |||||
# define ATTRIBUTE_FORMAT(spec) __attribute__((format spec)) | # define ATTRIBUTE_FORMAT(spec) __attribute__((format spec)) | ||||
#else | #else | ||||
# define ATTRIBUTE_MALLOC /* empty */ | # define ATTRIBUTE_MALLOC /* empty */ | ||||
# define ATTRIBUTE_FORMAT(spec) /* empty */ | # define ATTRIBUTE_FORMAT(spec) /* empty */ | ||||
#endif | #endif | ||||
#if (defined __has_c_attribute \ | #if (defined __has_c_attribute \ | ||||
&& (202311 <= __STDC_VERSION__ || !defined __STRICT_ANSI__)) | && (202311 <= __STDC_VERSION__ || !defined __STRICT_ANSI__)) | ||||
# define HAVE_HAS_C_ATTRIBUTE true | # define HAVE___HAS_C_ATTRIBUTE true | ||||
#else | #else | ||||
# define HAVE_HAS_C_ATTRIBUTE false | # define HAVE___HAS_C_ATTRIBUTE false | ||||
#endif | #endif | ||||
#if HAVE_HAS_C_ATTRIBUTE | #if HAVE___HAS_C_ATTRIBUTE | ||||
# if __has_c_attribute(deprecated) | |||||
# define ATTRIBUTE_DEPRECATED [[deprecated]] | |||||
# endif | |||||
#endif | |||||
#ifndef ATTRIBUTE_DEPRECATED | |||||
# if 3 < __GNUC__ + (2 <= __GNUC_MINOR__) | |||||
# define ATTRIBUTE_DEPRECATED __attribute__((deprecated)) | |||||
# else | |||||
# define ATTRIBUTE_DEPRECATED /* empty */ | |||||
# endif | |||||
#endif | |||||
#if HAVE___HAS_C_ATTRIBUTE | |||||
# if __has_c_attribute(fallthrough) | # if __has_c_attribute(fallthrough) | ||||
# define ATTRIBUTE_FALLTHROUGH [[fallthrough]] | # define ATTRIBUTE_FALLTHROUGH [[fallthrough]] | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef ATTRIBUTE_FALLTHROUGH | #ifndef ATTRIBUTE_FALLTHROUGH | ||||
# if 7 <= __GNUC__ | # if 7 <= __GNUC__ | ||||
# define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough)) | # define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough)) | ||||
# else | # else | ||||
# define ATTRIBUTE_FALLTHROUGH ((void) 0) | # define ATTRIBUTE_FALLTHROUGH ((void) 0) | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#if HAVE_HAS_C_ATTRIBUTE | #if HAVE___HAS_C_ATTRIBUTE | ||||
# if __has_c_attribute(maybe_unused) | # if __has_c_attribute(maybe_unused) | ||||
# define ATTRIBUTE_MAYBE_UNUSED [[maybe_unused]] | # define ATTRIBUTE_MAYBE_UNUSED [[maybe_unused]] | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef ATTRIBUTE_MAYBE_UNUSED | #ifndef ATTRIBUTE_MAYBE_UNUSED | ||||
# if 2 < __GNUC__ + (7 <= __GNUC_MINOR__) | # if 2 < __GNUC__ + (7 <= __GNUC_MINOR__) | ||||
# define ATTRIBUTE_MAYBE_UNUSED __attribute__((unused)) | # define ATTRIBUTE_MAYBE_UNUSED __attribute__((unused)) | ||||
# else | # else | ||||
# define ATTRIBUTE_MAYBE_UNUSED /* empty */ | # define ATTRIBUTE_MAYBE_UNUSED /* empty */ | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#if HAVE_HAS_C_ATTRIBUTE | #if HAVE___HAS_C_ATTRIBUTE | ||||
# if __has_c_attribute(noreturn) | # if __has_c_attribute(noreturn) | ||||
# define ATTRIBUTE_NORETURN [[noreturn]] | # define ATTRIBUTE_NORETURN [[noreturn]] | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef ATTRIBUTE_NORETURN | #ifndef ATTRIBUTE_NORETURN | ||||
# if 201112 <= __STDC_VERSION__ | # if 201112 <= __STDC_VERSION__ | ||||
# define ATTRIBUTE_NORETURN _Noreturn | # define ATTRIBUTE_NORETURN _Noreturn | ||||
# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) | # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) | ||||
# define ATTRIBUTE_NORETURN __attribute__((noreturn)) | # define ATTRIBUTE_NORETURN __attribute__((noreturn)) | ||||
# else | # else | ||||
# define ATTRIBUTE_NORETURN /* empty */ | # define ATTRIBUTE_NORETURN /* empty */ | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#if HAVE_HAS_C_ATTRIBUTE | #if HAVE___HAS_C_ATTRIBUTE | ||||
# if __has_c_attribute(reproducible) | # if __has_c_attribute(reproducible) | ||||
# define ATTRIBUTE_REPRODUCIBLE [[reproducible]] | # define ATTRIBUTE_REPRODUCIBLE [[reproducible]] | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef ATTRIBUTE_REPRODUCIBLE | #ifndef ATTRIBUTE_REPRODUCIBLE | ||||
# if 3 <= __GNUC__ | # if 3 <= __GNUC__ | ||||
# define ATTRIBUTE_REPRODUCIBLE __attribute__((pure)) | # define ATTRIBUTE_REPRODUCIBLE __attribute__((pure)) | ||||
# else | # else | ||||
# define ATTRIBUTE_REPRODUCIBLE /* empty */ | # define ATTRIBUTE_REPRODUCIBLE /* empty */ | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#if HAVE_HAS_C_ATTRIBUTE | #if HAVE___HAS_C_ATTRIBUTE | ||||
# if __has_c_attribute(unsequenced) | # if __has_c_attribute(unsequenced) | ||||
# define ATTRIBUTE_UNSEQUENCED [[unsequenced]] | # define ATTRIBUTE_UNSEQUENCED [[unsequenced]] | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#ifndef ATTRIBUTE_UNSEQUENCED | #ifndef ATTRIBUTE_UNSEQUENCED | ||||
# if 3 <= __GNUC__ | # if 3 <= __GNUC__ | ||||
# define ATTRIBUTE_UNSEQUENCED __attribute__((const)) | # define ATTRIBUTE_UNSEQUENCED __attribute__((const)) | ||||
# else | # else | ||||
# define ATTRIBUTE_UNSEQUENCED /* empty */ | # define ATTRIBUTE_UNSEQUENCED /* empty */ | ||||
# endif | # endif | ||||
#endif | #endif | ||||
#if __STDC_VERSION__ < 199901 && !defined restrict | #if (__STDC_VERSION__ < 199901 && !defined restrict \ | ||||
&& (PORT_TO_C89 || defined _MSC_VER)) | |||||
# define restrict /* empty */ | # define restrict /* empty */ | ||||
#endif | #endif | ||||
/* | /* | ||||
** Workarounds for compilers/systems. | ** Workarounds for compilers/systems. | ||||
*/ | */ | ||||
#ifndef EPOCH_LOCAL | #ifndef EPOCH_LOCAL | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
# undef localtime_rz | # undef localtime_rz | ||||
# define localtime_rz tz_localtime_rz | # define localtime_rz tz_localtime_rz | ||||
# undef mktime | # undef mktime | ||||
# define mktime tz_mktime | # define mktime tz_mktime | ||||
# undef mktime_z | # undef mktime_z | ||||
# define mktime_z tz_mktime_z | # define mktime_z tz_mktime_z | ||||
# undef offtime | # undef offtime | ||||
# define offtime tz_offtime | # define offtime tz_offtime | ||||
# undef offtime_r | |||||
# define offtime_r tz_offtime_r | |||||
# undef posix2time | # undef posix2time | ||||
# define posix2time tz_posix2time | # define posix2time tz_posix2time | ||||
# undef posix2time_z | # undef posix2time_z | ||||
# define posix2time_z tz_posix2time_z | # define posix2time_z tz_posix2time_z | ||||
# undef strftime | # undef strftime | ||||
# define strftime tz_strftime | # define strftime tz_strftime | ||||
# undef time | # undef time | ||||
# define time tz_time | # define time tz_time | ||||
Show All 29 Lines | |||||
# undef timezone | # undef timezone | ||||
# define timezone tz_timezone | # define timezone tz_timezone | ||||
# endif | # endif | ||||
# if ALTZONE | # if ALTZONE | ||||
# undef altzone | # undef altzone | ||||
# define altzone tz_altzone | # define altzone tz_altzone | ||||
# endif | # endif | ||||
char *asctime(struct tm const *); | # if __STDC_VERSION__ < 202311 | ||||
# define DEPRECATED_IN_C23 /* empty */ | |||||
# else | |||||
# define DEPRECATED_IN_C23 ATTRIBUTE_DEPRECATED | |||||
# endif | |||||
DEPRECATED_IN_C23 char *asctime(struct tm const *); | |||||
char *asctime_r(struct tm const *restrict, char *restrict); | char *asctime_r(struct tm const *restrict, char *restrict); | ||||
char *ctime(time_t const *); | DEPRECATED_IN_C23 char *ctime(time_t const *); | ||||
char *ctime_r(time_t const *, char *); | char *ctime_r(time_t const *, char *); | ||||
double difftime(time_t, time_t) ATTRIBUTE_UNSEQUENCED; | ATTRIBUTE_UNSEQUENCED double difftime(time_t, time_t); | ||||
size_t strftime(char *restrict, size_t, char const *restrict, | size_t strftime(char *restrict, size_t, char const *restrict, | ||||
struct tm const *restrict); | struct tm const *restrict); | ||||
# if HAVE_STRFTIME_L | # if HAVE_STRFTIME_L | ||||
size_t strftime_l(char *restrict, size_t, char const *restrict, | size_t strftime_l(char *restrict, size_t, char const *restrict, | ||||
struct tm const *restrict, locale_t); | struct tm const *restrict, locale_t); | ||||
# endif | # endif | ||||
struct tm *gmtime(time_t const *); | struct tm *gmtime(time_t const *); | ||||
struct tm *gmtime_r(time_t const *restrict, struct tm *restrict); | struct tm *gmtime_r(time_t const *restrict, struct tm *restrict); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
extern long altzone; | extern long altzone; | ||||
#endif | #endif | ||||
/* | /* | ||||
** The STD_INSPIRED functions are similar, but most also need | ** The STD_INSPIRED functions are similar, but most also need | ||||
** declarations if time_tz is defined. | ** declarations if time_tz is defined. | ||||
*/ | */ | ||||
#ifdef STD_INSPIRED | #ifndef STD_INSPIRED | ||||
# define STD_INSPIRED 0 | |||||
#endif | |||||
#if STD_INSPIRED | |||||
# if TZ_TIME_T || !defined offtime | # if TZ_TIME_T || !defined offtime | ||||
struct tm *offtime(time_t const *, long); | struct tm *offtime(time_t const *, long); | ||||
# endif | # endif | ||||
# if TZ_TIME_T || !defined offtime_r | |||||
struct tm *offtime_r(time_t const *, long, struct tm *); | |||||
# endif | |||||
# if TZ_TIME_T || !defined timelocal | # if TZ_TIME_T || !defined timelocal | ||||
time_t timelocal(struct tm *); | time_t timelocal(struct tm *); | ||||
# endif | # endif | ||||
# if TZ_TIME_T || !defined timeoff | # if TZ_TIME_T || !defined timeoff | ||||
time_t timeoff(struct tm *, long); | time_t timeoff(struct tm *, long); | ||||
# endif | # endif | ||||
# if TZ_TIME_T || !defined time2posix | # if TZ_TIME_T || !defined time2posix | ||||
time_t time2posix(time_t); | time_t time2posix(time_t); | ||||
Show All 27 Lines | |||||
*/ | */ | ||||
#if NETBSD_INSPIRED | #if NETBSD_INSPIRED | ||||
typedef struct state *timezone_t; | typedef struct state *timezone_t; | ||||
struct tm *localtime_rz(timezone_t restrict, time_t const *restrict, | struct tm *localtime_rz(timezone_t restrict, time_t const *restrict, | ||||
struct tm *restrict); | struct tm *restrict); | ||||
time_t mktime_z(timezone_t restrict, struct tm *restrict); | time_t mktime_z(timezone_t restrict, struct tm *restrict); | ||||
timezone_t tzalloc(char const *); | timezone_t tzalloc(char const *); | ||||
void tzfree(timezone_t); | void tzfree(timezone_t); | ||||
# ifdef STD_INSPIRED | # if STD_INSPIRED | ||||
# if TZ_TIME_T || !defined posix2time_z | # if TZ_TIME_T || !defined posix2time_z | ||||
time_t posix2time_z(timezone_t, time_t) ATTRIBUTE_REPRODUCIBLE; | ATTRIBUTE_REPRODUCIBLE time_t posix2time_z(timezone_t, time_t); | ||||
# endif | # endif | ||||
# if TZ_TIME_T || !defined time2posix_z | # if TZ_TIME_T || !defined time2posix_z | ||||
time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_REPRODUCIBLE; | ATTRIBUTE_REPRODUCIBLE time_t time2posix_z(timezone_t, time_t); | ||||
# endif | # endif | ||||
# endif | # endif | ||||
#endif | #endif | ||||
/* | /* | ||||
** Finally, some convenience items. | ** Finally, some convenience items. | ||||
*/ | */ | ||||
#define TYPE_BIT(type) (sizeof(type) * CHAR_BIT) | #define TYPE_BIT(type) (CHAR_BIT * (ptrdiff_t) sizeof(type)) | ||||
#define TYPE_SIGNED(type) (((type) -1) < 0) | #define TYPE_SIGNED(type) (((type) -1) < 0) | ||||
#define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0) | #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0) | ||||
/* Minimum and maximum of two values. Use lower case to avoid | /* Minimum and maximum of two values. Use lower case to avoid | ||||
naming clashes with standard include files. */ | naming clashes with standard include files. */ | ||||
#define max(a, b) ((a) > (b) ? (a) : (b)) | #define max(a, b) ((a) > (b) ? (a) : (b)) | ||||
#define min(a, b) ((a) < (b) ? (a) : (b)) | #define min(a, b) ((a) < (b) ? (a) : (b)) | ||||
Show All 11 Lines | |||||
#define TIME_T_MAX_NO_PADDING MAXVAL(time_t, TYPE_BIT(time_t)) | #define TIME_T_MAX_NO_PADDING MAXVAL(time_t, TYPE_BIT(time_t)) | ||||
/* The extreme time values. These are macros, not constants, so that | /* The extreme time values. These are macros, not constants, so that | ||||
any portability problems occur only when compiling .c files that use | any portability problems occur only when compiling .c files that use | ||||
the macros, which is safer for applications that need only zdump and zic. | the macros, which is safer for applications that need only zdump and zic. | ||||
This implementation assumes no padding if time_t is signed and | This implementation assumes no padding if time_t is signed and | ||||
either the compiler lacks support for _Generic or time_t is not one | either the compiler lacks support for _Generic or time_t is not one | ||||
of the standard signed integer types. */ | of the standard signed integer types. */ | ||||
#if HAVE_GENERIC | #if HAVE__GENERIC | ||||
# define TIME_T_MIN \ | # define TIME_T_MIN \ | ||||
_Generic((time_t) 0, \ | _Generic((time_t) 0, \ | ||||
signed char: SCHAR_MIN, short: SHRT_MIN, \ | signed char: SCHAR_MIN, short: SHRT_MIN, \ | ||||
int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \ | int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \ | ||||
default: TIME_T_MIN_NO_PADDING) | default: TIME_T_MIN_NO_PADDING) | ||||
# define TIME_T_MAX \ | # define TIME_T_MAX \ | ||||
(TYPE_SIGNED(time_t) \ | (TYPE_SIGNED(time_t) \ | ||||
? _Generic((time_t) 0, \ | ? _Generic((time_t) 0, \ | ||||
signed char: SCHAR_MAX, short: SHRT_MAX, \ | signed char: SCHAR_MAX, short: SHRT_MAX, \ | ||||
int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \ | int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \ | ||||
default: TIME_T_MAX_NO_PADDING) \ | default: TIME_T_MAX_NO_PADDING) \ | ||||
: (time_t) -1) | : (time_t) -1) | ||||
enum { SIGNED_PADDING_CHECK_NEEDED | |||||
= _Generic((time_t) 0, | |||||
signed char: false, short: false, | |||||
int: false, long: false, long long: false, | |||||
default: true) }; | |||||
#else | #else | ||||
# define TIME_T_MIN TIME_T_MIN_NO_PADDING | # define TIME_T_MIN TIME_T_MIN_NO_PADDING | ||||
# define TIME_T_MAX TIME_T_MAX_NO_PADDING | # define TIME_T_MAX TIME_T_MAX_NO_PADDING | ||||
enum { SIGNED_PADDING_CHECK_NEEDED = true }; | |||||
#endif | #endif | ||||
/* Try to check the padding assumptions. Although TIME_T_MAX and the | |||||
following check can both have undefined behavior on oddball | |||||
platforms due to shifts exceeding widths of signed integers, these | |||||
platforms' compilers are likely to diagnose these issues in integer | |||||
constant expressions, so it shouldn't hurt to check statically. */ | |||||
static_assert(! TYPE_SIGNED(time_t) || ! SIGNED_PADDING_CHECK_NEEDED | |||||
|| TIME_T_MAX >> (TYPE_BIT(time_t) - 2) == 1); | |||||
/* | /* | ||||
** 302 / 1000 is log10(2.0) rounded up. | ** 302 / 1000 is log10(2.0) rounded up. | ||||
** Subtract one for the sign bit if the type is signed; | ** Subtract one for the sign bit if the type is signed; | ||||
** add one for integer division truncation; | ** add one for integer division truncation; | ||||
** add one more for a minus sign if the type is signed. | ** add one more for a minus sign if the type is signed. | ||||
*/ | */ | ||||
#define INT_STRLEN_MAXIMUM(type) \ | #define INT_STRLEN_MAXIMUM(type) \ | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
#if !defined TZ_DOMAIN && defined HAVE_GETTEXT | #if !defined TZ_DOMAIN && defined HAVE_GETTEXT | ||||
# define TZ_DOMAIN "tz" | # define TZ_DOMAIN "tz" | ||||
#endif | #endif | ||||
#if HAVE_INCOMPATIBLE_CTIME_R | #if HAVE_INCOMPATIBLE_CTIME_R | ||||
#undef asctime_r | #undef asctime_r | ||||
#undef ctime_r | #undef ctime_r | ||||
char *asctime_r(struct tm const *, char *); | char *asctime_r(struct tm const *restrict, char *restrict); | ||||
char *ctime_r(time_t const *, char *); | char *ctime_r(time_t const *, char *); | ||||
#endif /* HAVE_INCOMPATIBLE_CTIME_R */ | #endif /* HAVE_INCOMPATIBLE_CTIME_R */ | ||||
/* Handy macros that are independent of tzfile implementation. */ | /* Handy macros that are independent of tzfile implementation. */ | ||||
enum { | enum { | ||||
SECSPERMIN = 60, | SECSPERMIN = 60, | ||||
MINSPERHOUR = 60, | MINSPERHOUR = 60, | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |