6 ** This file is in the public domain, so clarified as of
7 ** 1996-06-05 by Arthur David Olson.
11 ** This header is for use ONLY with the time conversion code.
12 ** There is no guarantee that it will remain unchanged,
13 ** or that it will remain at all.
14 ** Do NOT copy it to any system include directory.
18 #define GRANDPARENTED "Local time zone must be set--see zic manual page"
21 ** Defaults for preprocessor symbols.
22 ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
26 #define HAVE_ADJTIME 1
27 #endif /* !defined HAVE_ADJTIME */
30 #define HAVE_GETTEXT 0
31 #endif /* !defined HAVE_GETTEXT */
33 #ifndef HAVE_INCOMPATIBLE_CTIME_R
34 #define HAVE_INCOMPATIBLE_CTIME_R 0
35 #endif /* !defined INCOMPATIBLE_CTIME_R */
39 #endif /* !defined HAVE_LINK */
41 #ifndef HAVE_SETTIMEOFDAY
42 #define HAVE_SETTIMEOFDAY 3
43 #endif /* !defined HAVE_SETTIMEOFDAY */
46 #define HAVE_SYMLINK 1
47 #endif /* !defined HAVE_SYMLINK */
49 #ifndef HAVE_SYS_STAT_H
50 #define HAVE_SYS_STAT_H 1
51 #endif /* !defined HAVE_SYS_STAT_H */
53 #ifndef HAVE_SYS_WAIT_H
54 #define HAVE_SYS_WAIT_H 1
55 #endif /* !defined HAVE_SYS_WAIT_H */
58 #define HAVE_UNISTD_H 1
59 #endif /* !defined HAVE_UNISTD_H */
62 #define HAVE_UTMPX_H 0
63 #endif /* !defined HAVE_UTMPX_H */
66 #define LOCALE_HOME "/usr/lib/locale"
67 #endif /* !defined LOCALE_HOME */
69 #if HAVE_INCOMPATIBLE_CTIME_R
70 #define asctime_r _incompatible_asctime_r
71 #define ctime_r _incompatible_ctime_r
72 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
78 #include "sys/types.h" /* for time_t */
82 #include "limits.h" /* for CHAR_BIT et al. */
88 #endif /* HAVE_GETTEXT */
91 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
92 #endif /* HAVE_SYS_WAIT_H */
95 #define WIFEXITED(status) (((status) & 0xff) == 0)
96 #endif /* !defined WIFEXITED */
98 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
99 #endif /* !defined WEXITSTATUS */
102 #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
103 #endif /* HAVE_UNISTD_H */
107 #endif /* !defined F_OK */
110 #endif /* !defined R_OK */
112 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
113 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
116 ** Define HAVE_STDINT_H's default value here, rather than at the
117 ** start, since __GLIBC__'s value depends on previously-included
119 ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
121 #ifndef HAVE_STDINT_H
122 #define HAVE_STDINT_H \
123 (199901 <= __STDC_VERSION__ || \
124 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
125 #endif /* !defined HAVE_STDINT_H */
129 #endif /* !HAVE_STDINT_H */
131 #ifndef HAVE_INTTYPES_H
132 # define HAVE_INTTYPES_H HAVE_STDINT_H
135 # include <inttypes.h>
138 #ifndef INT_FAST64_MAX
139 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
140 #if defined LLONG_MAX || defined __LONG_LONG_MAX__
141 typedef long long int_fast64_t;
143 # define INT_FAST64_MIN LLONG_MIN
144 # define INT_FAST64_MAX LLONG_MAX
146 # define INT_FAST64_MIN __LONG_LONG_MIN__
147 # define INT_FAST64_MAX __LONG_LONG_MAX__
149 # define SCNdFAST64 "lld"
150 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
151 #if (LONG_MAX >> 31) < 0xffffffff
152 Please use a compiler that supports a
64-bit integer
type (or wider
);
153 you may need to compile with
"-DHAVE_STDINT_H".
154 #endif /* (LONG_MAX >> 31) < 0xffffffff */
155 typedef long int_fast64_t;
156 # define INT_FAST64_MIN LONG_MIN
157 # define INT_FAST64_MAX LONG_MAX
158 # define SCNdFAST64 "ld"
159 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
160 #endif /* !defined INT_FAST64_MAX */
162 #ifndef INT_FAST32_MAX
163 # if INT_MAX >> 31 == 0
164 typedef long int_fast32_t;
166 typedef int int_fast32_t;
171 # if defined LLONG_MAX || defined __LONG_LONG_MAX__
172 typedef long long intmax_t;
173 # define strtoimax strtoll
174 # define PRIdMAX "lld"
176 # define INTMAX_MAX LLONG_MAX
177 # define INTMAX_MIN LLONG_MIN
179 # define INTMAX_MAX __LONG_LONG_MAX__
180 # define INTMAX_MIN __LONG_LONG_MIN__
183 typedef long intmax_t;
184 # define strtoimax strtol
185 # define PRIdMAX "ld"
186 # define INTMAX_MAX LONG_MAX
187 # define INTMAX_MIN LONG_MIN
192 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
193 typedef unsigned long long uintmax_t;
194 # define PRIuMAX "llu"
196 typedef unsigned long uintmax_t;
197 # define PRIuMAX "lu"
202 #define INT32_MAX 0x7fffffff
203 #endif /* !defined INT32_MAX */
205 #define INT32_MIN (-1 - INT32_MAX)
206 #endif /* !defined INT32_MIN */
208 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
209 # define ATTRIBUTE_CONST __attribute__ ((const))
210 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
211 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
213 # define ATTRIBUTE_CONST /* empty */
214 # define ATTRIBUTE_PURE /* empty */
215 # define ATTRIBUTE_FORMAT(spec) /* empty */
218 #if !defined _Noreturn && __STDC_VERSION__ < 201112
219 # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
220 # define _Noreturn __attribute__ ((__noreturn__))
226 #if __STDC_VERSION__ < 199901 && !defined restrict
227 # define restrict /* empty */
231 ** Workarounds for compilers/systems.
235 ** Some time.h implementations don't declare asctime_r.
236 ** Others might define it as a macro.
237 ** Fix the former without affecting the latter.
241 extern char * asctime_r(struct tm
const *, char *);
245 ** Compile with -Dtime_tz=T to build the tz package with a private
246 ** time_t type equivalent to T rather than the system-supplied time_t.
247 ** This debugging feature can test unusual design decisions
248 ** (e.g., time_t wider than 'long', or unsigned time_t) even on
249 ** typical platforms.
252 static time_t sys_time(time_t *x
) { return time(x
); }
255 # define ctime tz_ctime
257 # define ctime_r tz_ctime_r
259 # define difftime tz_difftime
261 # define gmtime tz_gmtime
263 # define gmtime_r tz_gmtime_r
265 # define localtime tz_localtime
267 # define localtime_r tz_localtime_r
269 # define mktime tz_mktime
271 # define time tz_time
273 # define time_t tz_time_t
275 typedef time_tz
time_t;
277 char *ctime(time_t const *);
278 char *ctime_r(time_t const *, char *);
279 double difftime(time_t, time_t);
280 struct tm
*gmtime(time_t const *);
281 struct tm
*gmtime_r(time_t const *restrict
, struct tm
*restrict
);
282 struct tm
*localtime(time_t const *);
283 struct tm
*localtime_r(time_t const *restrict
, struct tm
*restrict
);
284 time_t mktime(struct tm
*);
289 time_t r
= sys_time(0);
297 ** Private function declarations.
300 char * icatalloc(char * old
, const char * new);
301 char * icpyalloc(const char * string
);
302 const char * scheck(const char * string
, const char * format
);
305 ** Finally, some convenience items.
310 #endif /* !defined TRUE */
314 #endif /* !defined FALSE */
317 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
318 #endif /* !defined TYPE_BIT */
321 #define TYPE_SIGNED(type) (((type) -1) < 0)
322 #endif /* !defined TYPE_SIGNED */
324 /* The minimum and maximum finite time values. */
325 static time_t const time_t_min
=
327 ? (time_t) -1 << (CHAR_BIT
* sizeof (time_t) - 1)
329 static time_t const time_t_max
=
331 ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT
* sizeof (time_t) - 1))
334 #ifndef INT_STRLEN_MAXIMUM
336 ** 302 / 1000 is log10(2.0) rounded up.
337 ** Subtract one for the sign bit if the type is signed;
338 ** add one for integer division truncation;
339 ** add one more for a minus sign if the type is signed.
341 #define INT_STRLEN_MAXIMUM(type) \
342 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
343 1 + TYPE_SIGNED(type))
344 #endif /* !defined INT_STRLEN_MAXIMUM */
353 #endif /* defined lint */
357 #endif /* defined __GNUC__ */
358 #endif /* !defined lint */
359 #endif /* !defined GNUC_or_lint */
363 #define INITIALIZE(x) ((x) = 0)
364 #endif /* defined GNUC_or_lint */
366 #define INITIALIZE(x)
367 #endif /* !defined GNUC_or_lint */
368 #endif /* !defined INITIALIZE */
371 ** For the benefit of GNU folk...
372 ** `_(MSGID)' uses the current locale's message library string for MSGID.
373 ** The default is to use gettext if available, and use MSGID otherwise.
378 #define _(msgid) gettext(msgid)
379 #else /* !HAVE_GETTEXT */
380 #define _(msgid) msgid
381 #endif /* !HAVE_GETTEXT */
382 #endif /* !defined _ */
385 #define TZ_DOMAIN "tz"
386 #endif /* !defined TZ_DOMAIN */
388 #if HAVE_INCOMPATIBLE_CTIME_R
391 char *asctime_r(struct tm
const *, char *);
392 char *ctime_r(time_t const *, char *);
393 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
395 #ifndef YEARSPERREPEAT
396 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
397 #endif /* !defined YEARSPERREPEAT */
400 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
403 #ifndef AVGSECSPERYEAR
404 #define AVGSECSPERYEAR 31556952L
405 #endif /* !defined AVGSECSPERYEAR */
407 #ifndef SECSPERREPEAT
408 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
409 #endif /* !defined SECSPERREPEAT */
411 #ifndef SECSPERREPEAT_BITS
412 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
413 #endif /* !defined SECSPERREPEAT_BITS */
416 ** UNIX was a registered trademark of The Open Group in 2003.
419 #endif /* !defined PRIVATE_H */