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_GETTEXT=1'.
26 #define HAVE_GETTEXT 0
27 #endif /* !defined HAVE_GETTEXT */
29 #ifndef HAVE_INCOMPATIBLE_CTIME_R
30 #define HAVE_INCOMPATIBLE_CTIME_R 0
31 #endif /* !defined INCOMPATIBLE_CTIME_R */
35 #endif /* !defined HAVE_LINK */
42 #define HAVE_SYMLINK 1
43 #endif /* !defined HAVE_SYMLINK */
45 #ifndef HAVE_SYS_STAT_H
46 #define HAVE_SYS_STAT_H 1
47 #endif /* !defined HAVE_SYS_STAT_H */
49 #ifndef HAVE_SYS_WAIT_H
50 #define HAVE_SYS_WAIT_H 1
51 #endif /* !defined HAVE_SYS_WAIT_H */
54 #define HAVE_UNISTD_H 1
55 #endif /* !defined HAVE_UNISTD_H */
58 #define HAVE_UTMPX_H 1
59 #endif /* !defined HAVE_UTMPX_H */
61 #ifndef NETBSD_INSPIRED
62 # define NETBSD_INSPIRED 1
65 #if HAVE_INCOMPATIBLE_CTIME_R
66 #define asctime_r _incompatible_asctime_r
67 #define ctime_r _incompatible_ctime_r
68 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
70 /* Enable tm_gmtoff and tm_zone on GNUish systems. */
72 /* Fix asctime_r on Solaris 10. */
73 #define _POSIX_PTHREAD_SEMANTICS 1
74 /* Enable strtoimax on Solaris 10. */
75 #define __EXTENSIONS__ 1
81 /* Avoid clashes with NetBSD by renaming NetBSD's declarations. */
82 #define localtime_rz sys_localtime_rz
83 #define mktime_z sys_mktime_z
84 #define posix2time_z sys_posix2time_z
85 #define time2posix_z sys_time2posix_z
86 #define timezone_t sys_timezone_t
87 #define tzalloc sys_tzalloc
88 #define tzfree sys_tzfree
98 #include "sys/types.h" /* for time_t */
101 #include "limits.h" /* for CHAR_BIT et al. */
107 # define ENAMETOOLONG EINVAL
110 # define EOVERFLOW EINVAL
115 #endif /* HAVE_GETTEXT */
118 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
119 #endif /* HAVE_SYS_WAIT_H */
122 #define WIFEXITED(status) (((status) & 0xff) == 0)
123 #endif /* !defined WIFEXITED */
125 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
126 #endif /* !defined WEXITSTATUS */
129 #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
130 #endif /* HAVE_UNISTD_H */
132 #ifndef HAVE_STRFTIME_L
133 # if _POSIX_VERSION < 200809
134 # define HAVE_STRFTIME_L 0
136 # define HAVE_STRFTIME_L 1
142 #endif /* !defined F_OK */
145 #endif /* !defined R_OK */
147 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
148 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
151 ** Define HAVE_STDINT_H's default value here, rather than at the
152 ** start, since __GLIBC__'s value depends on previously-included
154 ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
156 #ifndef HAVE_STDINT_H
157 #define HAVE_STDINT_H \
158 (199901 <= __STDC_VERSION__ \
159 || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
161 #endif /* !defined HAVE_STDINT_H */
165 #endif /* !HAVE_STDINT_H */
167 #ifndef HAVE_INTTYPES_H
168 # define HAVE_INTTYPES_H HAVE_STDINT_H
171 # include <inttypes.h>
174 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
175 #ifdef __LONG_LONG_MAX__
177 # define LLONG_MAX __LONG_LONG_MAX__
180 # define LLONG_MIN (-1 - LLONG_MAX)
184 #ifndef INT_FAST64_MAX
186 typedef long long int_fast64_t;
187 # define INT_FAST64_MIN LLONG_MIN
188 # define INT_FAST64_MAX LLONG_MAX
190 # if LONG_MAX >> 31 < 0xffffffff
191 Please use a compiler that supports a
64-bit integer
type (or wider
);
192 you may need to compile with
"-DHAVE_STDINT_H".
194 typedef long int_fast64_t;
195 # define INT_FAST64_MIN LONG_MIN
196 # define INT_FAST64_MAX LONG_MAX
201 # if INT_FAST64_MAX == LLONG_MAX
202 # define SCNdFAST64 "lld"
204 # define SCNdFAST64 "ld"
208 #ifndef INT_FAST32_MAX
209 # if INT_MAX >> 31 == 0
210 typedef long int_fast32_t;
211 # define INT_FAST32_MAX LONG_MAX
212 # define INT_FAST32_MIN LONG_MIN
214 typedef int int_fast32_t;
215 # define INT_FAST32_MAX INT_MAX
216 # define INT_FAST32_MIN INT_MIN
222 typedef long long intmax_t;
223 # define strtoimax strtoll
224 # define INTMAX_MAX LLONG_MAX
225 # define INTMAX_MIN LLONG_MIN
227 typedef long intmax_t;
228 # define strtoimax strtol
229 # define INTMAX_MAX LONG_MAX
230 # define INTMAX_MIN LONG_MIN
235 # if INTMAX_MAX == LLONG_MAX
236 # define PRIdMAX "lld"
238 # define PRIdMAX "ld"
242 #ifndef UINT_FAST64_MAX
243 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
244 typedef unsigned long long uint_fast64_t;
246 # if ULONG_MAX >> 31 >> 1 < 0xffffffff
247 Please use a compiler that supports a
64-bit integer
type (or wider
);
248 you may need to compile with
"-DHAVE_STDINT_H".
250 typedef unsigned long uint_fast64_t;
255 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
256 typedef unsigned long long uintmax_t;
258 typedef unsigned long uintmax_t;
263 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
264 # define PRIuMAX "llu"
266 # define PRIuMAX "lu"
271 #define INT32_MAX 0x7fffffff
272 #endif /* !defined INT32_MAX */
274 #define INT32_MIN (-1 - INT32_MAX)
275 #endif /* !defined INT32_MIN */
278 #define SIZE_MAX ((size_t) -1)
281 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
282 # define ATTRIBUTE_CONST __attribute__ ((const))
283 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
284 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
286 # define ATTRIBUTE_CONST /* empty */
287 # define ATTRIBUTE_PURE /* empty */
288 # define ATTRIBUTE_FORMAT(spec) /* empty */
291 #if !defined _Noreturn && __STDC_VERSION__ < 201112
292 # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
293 # define _Noreturn __attribute__ ((__noreturn__))
299 #if __STDC_VERSION__ < 199901 && !defined restrict
300 # define restrict /* empty */
304 ** Workarounds for compilers/systems.
308 ** Compile with -Dtime_tz=T to build the tz package with a private
309 ** time_t type equivalent to T rather than the system-supplied time_t.
310 ** This debugging feature can test unusual design decisions
311 ** (e.g., time_t wider than 'long', or unsigned time_t) even on
312 ** typical platforms.
315 # ifdef LOCALTIME_IMPLEMENTATION
316 static time_t sys_time(time_t *x
) { return time(x
); }
319 typedef time_tz tz_time_t
;
322 # define ctime tz_ctime
324 # define ctime_r tz_ctime_r
326 # define difftime tz_difftime
328 # define gmtime tz_gmtime
330 # define gmtime_r tz_gmtime_r
332 # define localtime tz_localtime
334 # define localtime_r tz_localtime_r
336 # define localtime_rz tz_localtime_rz
338 # define mktime tz_mktime
340 # define mktime_z tz_mktime_z
342 # define offtime tz_offtime
344 # define posix2time tz_posix2time
346 # define posix2time_z tz_posix2time_z
348 # define time tz_time
350 # define time2posix tz_time2posix
352 # define time2posix_z tz_time2posix_z
354 # define time_t tz_time_t
356 # define timegm tz_timegm
358 # define timelocal tz_timelocal
360 # define timeoff tz_timeoff
362 # define tzalloc tz_tzalloc
364 # define tzfree tz_tzfree
366 # define tzset tz_tzset
368 # define tzsetwall tz_tzsetwall
370 char *ctime(time_t const *);
371 char *ctime_r(time_t const *, char *);
372 double difftime(time_t, time_t);
373 struct tm
*gmtime(time_t const *);
374 struct tm
*gmtime_r(time_t const *restrict
, struct tm
*restrict
);
375 struct tm
*localtime(time_t const *);
376 struct tm
*localtime_r(time_t const *restrict
, struct tm
*restrict
);
377 time_t mktime(struct tm
*);
378 time_t time(time_t *);
383 ** Some time.h implementations don't declare asctime_r.
384 ** Others might define it as a macro.
385 ** Fix the former without affecting the latter.
386 ** Similarly for timezone, daylight, and altzone.
390 extern char * asctime_r(struct tm
const *restrict
, char *restrict
);
395 extern long timezone
;
401 #if defined ALTZONE && !defined altzone
406 ** The STD_INSPIRED functions are similar, but most also need
407 ** declarations if time_tz is defined.
411 # if !defined tzsetwall || defined time_tz
412 void tzsetwall(void);
414 # if !defined offtime || defined time_tz
415 struct tm
*offtime(time_t const *, long);
417 # if !defined timegm || defined time_tz
418 time_t timegm(struct tm
*);
420 # if !defined timelocal || defined time_tz
421 time_t timelocal(struct tm
*);
423 # if !defined timeoff || defined time_tz
424 time_t timeoff(struct tm
*, long);
426 # if !defined time2posix || defined time_tz
427 time_t time2posix(time_t);
429 # if !defined posix2time || defined time_tz
430 time_t posix2time(time_t);
434 /* Infer TM_ZONE on systems where this information is known, but suppress
435 guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
436 #if (defined __GLIBC__ \
437 || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
438 || (defined __APPLE__ && defined __MACH__))
439 # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
440 # define TM_GMTOFF tm_gmtoff
442 # if !defined TM_ZONE && !defined NO_TM_ZONE
443 # define TM_ZONE tm_zone
448 ** Define functions that are ABI compatible with NetBSD but have
449 ** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t
450 ** and labors under the misconception that 'const timezone_t' is a
451 ** pointer to a constant. This use of 'const' is ineffective, so it
452 ** is not done here. What we call 'struct state' NetBSD calls
453 ** 'struct __state', but this is a private name so it doesn't matter.
456 typedef struct state
*timezone_t
;
457 struct tm
*localtime_rz(timezone_t restrict
, time_t const *restrict
,
458 struct tm
*restrict
);
459 time_t mktime_z(timezone_t restrict
, struct tm
*restrict
);
460 timezone_t
tzalloc(char const *);
461 void tzfree(timezone_t
);
463 # if !defined posix2time_z || defined time_tz
464 time_t posix2time_z(timezone_t
, time_t) ATTRIBUTE_PURE
;
466 # if !defined time2posix_z || defined time_tz
467 time_t time2posix_z(timezone_t
, time_t) ATTRIBUTE_PURE
;
473 ** Finally, some convenience items.
476 #if __STDC_VERSION__ < 199901
481 # include <stdbool.h>
485 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
486 #endif /* !defined TYPE_BIT */
489 #define TYPE_SIGNED(type) (((type) -1) < 0)
490 #endif /* !defined TYPE_SIGNED */
492 #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
494 /* Max and min values of the integer type T, of which only the bottom
495 B bits are used, and where the highest-order used bit is considered
496 to be a sign bit if T is signed. */
497 #define MAXVAL(t, b) \
498 ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
499 - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
500 #define MINVAL(t, b) \
501 ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
503 /* The minimum and maximum finite time values. This assumes no padding. */
504 static time_t const time_t_min
= MINVAL(time_t, TYPE_BIT(time_t));
505 static time_t const time_t_max
= MAXVAL(time_t, TYPE_BIT(time_t));
507 #ifndef INT_STRLEN_MAXIMUM
509 ** 302 / 1000 is log10(2.0) rounded up.
510 ** Subtract one for the sign bit if the type is signed;
511 ** add one for integer division truncation;
512 ** add one more for a minus sign if the type is signed.
514 #define INT_STRLEN_MAXIMUM(type) \
515 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
516 1 + TYPE_SIGNED(type))
517 #endif /* !defined INT_STRLEN_MAXIMUM */
524 # define INITIALIZE(x) ((x) = 0)
526 # define INITIALIZE(x)
530 # define UNINIT_TRAP 0
534 ** For the benefit of GNU folk...
535 ** '_(MSGID)' uses the current locale's message library string for MSGID.
536 ** The default is to use gettext if available, and use MSGID otherwise.
541 #define _(msgid) gettext(msgid)
542 #else /* !HAVE_GETTEXT */
543 #define _(msgid) msgid
544 #endif /* !HAVE_GETTEXT */
545 #endif /* !defined _ */
547 #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
548 # define TZ_DOMAIN "tz"
551 #if HAVE_INCOMPATIBLE_CTIME_R
554 char *asctime_r(struct tm
const *, char *);
555 char *ctime_r(time_t const *, char *);
556 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
558 #ifndef YEARSPERREPEAT
559 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
560 #endif /* !defined YEARSPERREPEAT */
563 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
566 #ifndef AVGSECSPERYEAR
567 #define AVGSECSPERYEAR 31556952L
568 #endif /* !defined AVGSECSPERYEAR */
570 #ifndef SECSPERREPEAT
571 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
572 #endif /* !defined SECSPERREPEAT */
574 #ifndef SECSPERREPEAT_BITS
575 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
576 #endif /* !defined SECSPERREPEAT_BITS */
578 #endif /* !defined PRIVATE_H */