Files

374 lines
8.7 KiB
C
Raw Permalink Normal View History

2016-10-25 21:12:38 +00:00
#ifndef TZ_PRIVATE_H
#define TZ_PRIVATE_H
1995-01-03 11:08:20 -05:00
#ifndef HAVE_ADJTIME
1995-01-06 15:29:02 -05:00
#define HAVE_ADJTIME 1
1995-01-03 11:26:27 -05:00
#endif /* !defined HAVE_ADJTIME */
1995-01-06 15:29:02 -05:00
1996-02-21 15:47:23 -05:00
#ifndef HAVE_GETTEXT
#define HAVE_GETTEXT 0
#endif /* !defined HAVE_GETTEXT */
2000-04-17 12:53:08 -04:00
#ifndef HAVE_INCOMPATIBLE_CTIME_R
#define HAVE_INCOMPATIBLE_CTIME_R 0
#endif /* !defined INCOMPATIBLE_CTIME_R */
2013-09-25 17:49:49 -07:00
#ifndef HAVE_LINK
#define HAVE_LINK 1
2013-09-26 06:52:15 -07:00
#endif /* !defined HAVE_LINK */
2013-09-25 17:49:49 -07:00
1995-01-03 11:08:20 -05:00
#ifndef HAVE_SETTIMEOFDAY
#define HAVE_SETTIMEOFDAY 3
1995-01-03 11:26:27 -05:00
#endif /* !defined HAVE_SETTIMEOFDAY */
1995-01-03 11:08:20 -05:00
2015-05-01 01:51:11 +02:00
#ifndef HAVE_STRDUP
#define HAVE_STRDUP 1
#endif
1998-02-02 12:05:09 -05:00
#ifndef HAVE_SYMLINK
#define HAVE_SYMLINK 1
#endif /* !defined HAVE_SYMLINK */
2001-06-05 13:48:08 -04:00
#ifndef HAVE_SYS_STAT_H
#define HAVE_SYS_STAT_H 1
#endif /* !defined HAVE_SYS_STAT_H */
1999-08-17 14:09:05 -04:00
#ifndef HAVE_SYS_WAIT_H
#define HAVE_SYS_WAIT_H 1
#endif /* !defined HAVE_SYS_WAIT_H */
1995-03-04 11:22:05 -05:00
#ifndef HAVE_UNISTD_H
#define HAVE_UNISTD_H 1
#endif /* !defined HAVE_UNISTD_H */
1996-01-10 16:44:45 -05:00
#ifndef HAVE_UTMPX_H
1996-01-10 16:46:40 -05:00
#define HAVE_UTMPX_H 0
1996-01-10 16:44:45 -05:00
#endif /* !defined HAVE_UTMPX_H */
#ifndef NETBSD_INSPIRED
# define NETBSD_INSPIRED 1
#endif
2000-04-17 12:53:08 -04:00
#if HAVE_INCOMPATIBLE_CTIME_R
#define asctime_r _incompatible_asctime_r
#define ctime_r _incompatible_ctime_r
#endif /* HAVE_INCOMPATIBLE_CTIME_R */
/* Enable tm_gmtoff and tm_zone on GNUish systems. */
#define _GNU_SOURCE 1
2014-08-25 13:35:42 -07:00
/* Fix asctime_r on Solaris 10. */
#define _POSIX_PTHREAD_SEMANTICS 1
/* Enable strtoimax on Solaris 10. */
#define __EXTENSIONS__ 1
2016-10-25 21:12:38 +00:00
#ifndef __LONG_LONG_MAX__
#define __LONG_LONG_MAX__ 0x7fffffffffffffffLL
#endif
1995-03-04 11:22:05 -05:00
#include "sys/types.h" /* for time_t */
#include "stdio.h"
#include "string.h"
2006-02-20 09:53:12 -05:00
#include "limits.h" /* for CHAR_BIT et al. */
1995-03-04 11:22:05 -05:00
#include "stdlib.h"
#include "errno.h"
#ifndef ENAMETOOLONG
# define ENAMETOOLONG EINVAL
#endif
#ifndef EOVERFLOW
# define EOVERFLOW EINVAL
#endif
2005-01-31 14:06:06 -05:00
#if HAVE_GETTEXT
1996-02-21 15:47:23 -05:00
#include "libintl.h"
2005-01-31 14:06:06 -05:00
#endif /* HAVE_GETTEXT */
1996-02-21 15:47:23 -05:00
2005-01-31 14:06:06 -05:00
#if HAVE_SYS_WAIT_H
1999-08-17 14:09:05 -04:00
#include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
2005-01-31 14:06:06 -05:00
#endif /* HAVE_SYS_WAIT_H */
1999-08-17 14:09:05 -04:00
#ifndef WIFEXITED
#define WIFEXITED(status) (((status) & 0xff) == 0)
#endif /* !defined WIFEXITED */
#ifndef WEXITSTATUS
#define WEXITSTATUS(status) (((status) >> 8) & 0xff)
#endif /* !defined WEXITSTATUS */
2005-01-31 14:06:06 -05:00
#if HAVE_UNISTD_H
2007-12-03 09:42:13 -05:00
#include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
2005-01-31 14:06:06 -05:00
#endif /* HAVE_UNISTD_H */
1995-03-04 11:22:05 -05:00
#ifndef HAVE_STRFTIME_L
# if _POSIX_VERSION < 200809
# define HAVE_STRFTIME_L 0
# else
# define HAVE_STRFTIME_L 1
# endif
#endif
1995-03-04 11:22:05 -05:00
#ifndef F_OK
#define F_OK 0
#endif /* !defined F_OK */
#ifndef R_OK
#define R_OK 4
#endif /* !defined R_OK */
2005-01-31 14:06:06 -05:00
/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
1995-10-30 10:19:57 -05:00
#define is_digit(c) ((unsigned)(c) - '0' <= 9)
2006-03-14 13:38:55 -05:00
/*
** Define HAVE_STDINT_H's default value here, rather than at the
** start, since __GLIBC__'s value depends on previously-included
** files.
** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
*/
#ifndef HAVE_STDINT_H
#define HAVE_STDINT_H \
(199901 <= __STDC_VERSION__ \
|| 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
|| __CYGWIN__)
2006-03-14 13:38:55 -05:00
#endif /* !defined HAVE_STDINT_H */
2006-02-20 09:53:12 -05:00
#if HAVE_STDINT_H
2006-03-14 13:38:55 -05:00
#include "stdint.h"
2006-02-20 09:53:12 -05:00
#endif /* !HAVE_STDINT_H */
#ifndef HAVE_INTTYPES_H
# define HAVE_INTTYPES_H HAVE_STDINT_H
#endif
#if HAVE_INTTYPES_H
# include <inttypes.h>
#endif
2006-03-14 13:38:55 -05:00
/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
2014-08-25 13:35:42 -07:00
#ifdef __LONG_LONG_MAX__
# ifndef LLONG_MAX
# define LLONG_MAX __LONG_LONG_MAX__
# endif
# ifndef LLONG_MIN
# define LLONG_MIN (-1 - LLONG_MAX)
# endif
#endif
#ifndef INT_FAST64_MAX
# ifdef LLONG_MAX
2014-08-25 13:35:42 -07:00
typedef long long int_fast64_t;
# define INT_FAST64_MIN LLONG_MIN
# define INT_FAST64_MAX LLONG_MAX
# else
2014-08-25 13:35:42 -07:00
# if (LONG_MAX >> 31) < 0xffffffff
2006-03-14 13:38:55 -05:00
Please use a compiler that supports a 64-bit integer type (or wider);
you may need to compile with "-DHAVE_STDINT_H".
2014-08-25 13:35:42 -07:00
# endif
2006-02-20 09:53:12 -05:00
typedef long int_fast64_t;
2014-08-25 13:35:42 -07:00
# define INT_FAST64_MIN LONG_MIN
# define INT_FAST64_MAX LONG_MAX
# endif
#endif
#ifndef SCNdFAST64
# if INT_FAST64_MAX == LLONG_MAX
# define SCNdFAST64 "lld"
# else
# define SCNdFAST64 "ld"
# endif
#endif
2006-02-20 09:53:12 -05:00
#ifndef INT_FAST32_MAX
# if INT_MAX >> 31 == 0
typedef long int_fast32_t;
2014-08-14 21:52:01 -07:00
# define INT_FAST32_MAX LONG_MAX
# define INT_FAST32_MIN LONG_MIN
# else
typedef int int_fast32_t;
2014-08-14 21:52:01 -07:00
# define INT_FAST32_MAX INT_MAX
# define INT_FAST32_MIN INT_MIN
# endif
#endif
#ifndef INTMAX_MAX
2014-08-25 13:35:42 -07:00
# ifdef LLONG_MAX
typedef long long intmax_t;
2013-08-09 00:40:14 -07:00
# define strtoimax strtoll
2014-08-25 13:35:42 -07:00
# define INTMAX_MAX LLONG_MAX
# define INTMAX_MIN LLONG_MIN
# else
typedef long intmax_t;
2013-08-09 00:40:14 -07:00
# define strtoimax strtol
# define INTMAX_MAX LONG_MAX
# define INTMAX_MIN LONG_MIN
# endif
#endif
2014-08-25 13:35:42 -07:00
#ifndef PRIdMAX
# if INTMAX_MAX == LLONG_MAX
# define PRIdMAX "lld"
# else
# define PRIdMAX "ld"
# endif
#endif
#ifndef UINTMAX_MAX
# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
typedef unsigned long long uintmax_t;
# else
typedef unsigned long uintmax_t;
2014-08-25 13:35:42 -07:00
# endif
#endif
#ifndef PRIuMAX
# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
# define PRIuMAX "llu"
# else
# define PRIuMAX "lu"
# endif
#endif
2006-02-20 09:53:12 -05:00
#ifndef INT32_MAX
#define INT32_MAX 0x7fffffff
#endif /* !defined INT32_MAX */
#ifndef INT32_MIN
#define INT32_MIN (-1 - INT32_MAX)
#endif /* !defined INT32_MIN */
2014-03-20 14:34:32 -07:00
#ifndef SIZE_MAX
#define SIZE_MAX ((size_t) -1)
#endif
#if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
# define ATTRIBUTE_CONST __attribute__ ((const))
2012-10-12 07:53:12 -07:00
# define ATTRIBUTE_PURE __attribute__ ((__pure__))
# define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
2012-10-12 07:53:12 -07:00
#else
# define ATTRIBUTE_CONST /* empty */
2012-10-12 07:53:12 -07:00
# define ATTRIBUTE_PURE /* empty */
# define ATTRIBUTE_FORMAT(spec) /* empty */
2012-10-12 07:53:12 -07:00
#endif
#if !defined _Noreturn && __STDC_VERSION__ < 201112
# if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
# define _Noreturn __attribute__ ((__noreturn__))
# else
# define _Noreturn
# endif
#endif
#if __STDC_VERSION__ < 199901 && !defined restrict
# define restrict /* empty */
#endif
/* Infer TM_ZONE on systems where this information is known, but suppress
guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
#if (defined __GLIBC__ \
|| defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
|| (defined __APPLE__ && defined __MACH__))
# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
# define TM_GMTOFF tm_gmtoff
# endif
# if !defined TM_ZONE && !defined NO_TM_ZONE
# define TM_ZONE tm_zone
# endif
#endif
1995-01-06 16:21:56 -05:00
/*
** Finally, some convenience items.
*/
1989-03-17 21:42:05 -05:00
2014-08-20 08:13:31 -07:00
#if __STDC_VERSION__ < 199901
# define true 1
# define false 0
# define bool int
#else
# include <stdbool.h>
#endif
1989-03-22 18:09:56 -05:00
1996-01-06 13:41:43 -05:00
#ifndef TYPE_BIT
#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
#endif /* !defined TYPE_BIT */
#ifndef TYPE_SIGNED
#define TYPE_SIGNED(type) (((type) -1) < 0)
#endif /* !defined TYPE_SIGNED */
#define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
/* Max and min values of the integer type T, of which only the bottom
B bits are used, and where the highest-order used bit is considered
to be a sign bit if T is signed. */
#define MAXVAL(t, b) \
((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
- 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
#define MINVAL(t, b) \
((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
/* The minimum and maximum finite time values. This assumes no padding. */
static time_t const time_t_min = MINVAL(time_t, TYPE_BIT(time_t));
static time_t const time_t_max = MAXVAL(time_t, TYPE_BIT(time_t));
2013-08-09 00:40:14 -07:00
1993-05-29 20:18:37 -04:00
#ifndef INT_STRLEN_MAXIMUM
1993-05-30 16:25:00 -04:00
/*
** 302 / 1000 is log10(2.0) rounded up.
1996-01-06 13:28:07 -05:00
** Subtract one for the sign bit if the type is signed;
** add one for integer division truncation;
** add one more for a minus sign if the type is signed.
1993-05-30 16:25:00 -04:00
*/
#define INT_STRLEN_MAXIMUM(type) \
2005-01-31 14:06:06 -05:00
((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
1 + TYPE_SIGNED(type))
1993-05-29 20:18:37 -04:00
#endif /* !defined INT_STRLEN_MAXIMUM */
1995-01-06 16:21:56 -05:00
/*
** INITIALIZE(x)
*/
2015-07-25 23:35:51 +02:00
#if defined(lint) || defined(INITCLEAN)
# define INITIALIZE(x) ((x) = 0)
#else
# define INITIALIZE(x)
#endif
1995-01-06 16:21:56 -05:00
#ifndef UNINIT_TRAP
# define UNINIT_TRAP 0
#endif
1996-02-19 19:26:00 -05:00
/*
** For the benefit of GNU folk...
2014-06-15 13:27:37 -07:00
** '_(MSGID)' uses the current locale's message library string for MSGID.
1996-02-21 15:47:23 -05:00
** The default is to use gettext if available, and use MSGID otherwise.
1996-02-19 19:26:00 -05:00
*/
#ifndef _
2005-01-31 14:06:06 -05:00
#if HAVE_GETTEXT
1996-02-21 15:47:23 -05:00
#define _(msgid) gettext(msgid)
2005-01-31 14:06:06 -05:00
#else /* !HAVE_GETTEXT */
1996-02-21 15:47:23 -05:00
#define _(msgid) msgid
2005-01-31 14:06:06 -05:00
#endif /* !HAVE_GETTEXT */
1996-02-19 19:26:00 -05:00
#endif /* !defined _ */
#if !defined TZ_DOMAIN && defined HAVE_GETTEXT
# define TZ_DOMAIN "tz"
#endif
1996-02-21 15:47:23 -05:00
2006-02-20 09:53:12 -05:00
#ifndef YEARSPERREPEAT
#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
#endif /* !defined YEARSPERREPEAT */
/*
** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
*/
#ifndef AVGSECSPERYEAR
#define AVGSECSPERYEAR 31556952L
#endif /* !defined AVGSECSPERYEAR */
#ifndef SECSPERREPEAT
#define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
#endif /* !defined SECSPERREPEAT */
2007-03-15 09:55:13 -04:00
2006-02-20 09:53:12 -05:00
#ifndef SECSPERREPEAT_BITS
#define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
#endif /* !defined SECSPERREPEAT_BITS */
2016-10-25 21:12:38 +00:00
#endif /* !defined TZ_PRIVATE_H */