blob: 941e91b2f3da2a16f82ff0e4718e39df5a48da30 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001#ifndef PRIVATE_H
2
3#define PRIVATE_H
4
5/*
6** This file is in the public domain, so clarified as of
7** 1996-06-05 by Arthur David Olson.
8*/
9
10/*
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.
15** Thank you!
16*/
17
Elliott Hughesce4783c2013-07-12 17:31:11 -070018#define GRANDPARENTED "Local time zone must be set--see zic manual page"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080019
20/*
21** Defaults for preprocessor symbols.
Elliott Hughes9fb22a32015-10-07 17:13:40 -070022** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080023*/
24
Elliott Hughes0a610d02016-07-29 14:04:17 -070025#ifndef HAVE_DECL_ASCTIME_R
26#define HAVE_DECL_ASCTIME_R 1
27#endif
28
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef HAVE_GETTEXT
Elliott Hughesce4783c2013-07-12 17:31:11 -070030#define HAVE_GETTEXT 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080031#endif /* !defined HAVE_GETTEXT */
32
33#ifndef HAVE_INCOMPATIBLE_CTIME_R
Elliott Hughesce4783c2013-07-12 17:31:11 -070034#define HAVE_INCOMPATIBLE_CTIME_R 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035#endif /* !defined INCOMPATIBLE_CTIME_R */
36
Calin Juravle627d37c2014-02-28 11:46:03 +000037#ifndef HAVE_LINK
38#define HAVE_LINK 1
39#endif /* !defined HAVE_LINK */
40
Elliott Hughes0a610d02016-07-29 14:04:17 -070041#ifndef HAVE_POSIX_DECLS
42#define HAVE_POSIX_DECLS 1
43#endif
44
Elliott Hughes9fb22a32015-10-07 17:13:40 -070045#ifndef HAVE_STRDUP
46#define HAVE_STRDUP 1
47#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080048
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080049#ifndef HAVE_SYMLINK
Elliott Hughesce4783c2013-07-12 17:31:11 -070050#define HAVE_SYMLINK 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051#endif /* !defined HAVE_SYMLINK */
52
53#ifndef HAVE_SYS_STAT_H
Elliott Hughesce4783c2013-07-12 17:31:11 -070054#define HAVE_SYS_STAT_H 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055#endif /* !defined HAVE_SYS_STAT_H */
56
57#ifndef HAVE_SYS_WAIT_H
Elliott Hughesce4783c2013-07-12 17:31:11 -070058#define HAVE_SYS_WAIT_H 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080059#endif /* !defined HAVE_SYS_WAIT_H */
60
61#ifndef HAVE_UNISTD_H
Elliott Hughesce4783c2013-07-12 17:31:11 -070062#define HAVE_UNISTD_H 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080063#endif /* !defined HAVE_UNISTD_H */
64
65#ifndef HAVE_UTMPX_H
Elliott Hughes9fb22a32015-10-07 17:13:40 -070066#define HAVE_UTMPX_H 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080067#endif /* !defined HAVE_UTMPX_H */
68
Elliott Hughes9fb22a32015-10-07 17:13:40 -070069#ifndef NETBSD_INSPIRED
70# define NETBSD_INSPIRED 1
71#endif
Elliott Hughesce4783c2013-07-12 17:31:11 -070072
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080073#if HAVE_INCOMPATIBLE_CTIME_R
74#define asctime_r _incompatible_asctime_r
75#define ctime_r _incompatible_ctime_r
76#endif /* HAVE_INCOMPATIBLE_CTIME_R */
77
Elliott Hughes9fb22a32015-10-07 17:13:40 -070078/* Enable tm_gmtoff and tm_zone on GNUish systems. */
79#define _GNU_SOURCE 1
80/* Fix asctime_r on Solaris 10. */
81#define _POSIX_PTHREAD_SEMANTICS 1
82/* Enable strtoimax on Solaris 10. */
83#define __EXTENSIONS__ 1
84
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080085/*
86** Nested includes
87*/
88
Elliott Hughes9fb22a32015-10-07 17:13:40 -070089/* Avoid clashes with NetBSD by renaming NetBSD's declarations. */
90#define localtime_rz sys_localtime_rz
91#define mktime_z sys_mktime_z
92#define posix2time_z sys_posix2time_z
93#define time2posix_z sys_time2posix_z
94#define timezone_t sys_timezone_t
95#define tzalloc sys_tzalloc
96#define tzfree sys_tzfree
97#include <time.h>
98#undef localtime_rz
99#undef mktime_z
100#undef posix2time_z
101#undef time2posix_z
102#undef timezone_t
103#undef tzalloc
104#undef tzfree
105
Elliott Hughesce4783c2013-07-12 17:31:11 -0700106#include "sys/types.h" /* for time_t */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800107#include "stdio.h"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800108#include "string.h"
Elliott Hughesce4783c2013-07-12 17:31:11 -0700109#include "limits.h" /* for CHAR_BIT et al. */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800110#include "stdlib.h"
111
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700112#include "errno.h"
113
114#ifndef ENAMETOOLONG
115# define ENAMETOOLONG EINVAL
116#endif
Elliott Hughes0a610d02016-07-29 14:04:17 -0700117#ifndef ENOTSUP
118# define ENOTSUP EINVAL
119#endif
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700120#ifndef EOVERFLOW
121# define EOVERFLOW EINVAL
122#endif
123
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800124#if HAVE_GETTEXT
125#include "libintl.h"
126#endif /* HAVE_GETTEXT */
127
128#if HAVE_SYS_WAIT_H
Elliott Hughesce4783c2013-07-12 17:31:11 -0700129#include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800130#endif /* HAVE_SYS_WAIT_H */
131
132#ifndef WIFEXITED
Elliott Hughesce4783c2013-07-12 17:31:11 -0700133#define WIFEXITED(status) (((status) & 0xff) == 0)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800134#endif /* !defined WIFEXITED */
135#ifndef WEXITSTATUS
Elliott Hughesce4783c2013-07-12 17:31:11 -0700136#define WEXITSTATUS(status) (((status) >> 8) & 0xff)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800137#endif /* !defined WEXITSTATUS */
138
139#if HAVE_UNISTD_H
Elliott Hughesce4783c2013-07-12 17:31:11 -0700140#include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800141#endif /* HAVE_UNISTD_H */
142
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700143#ifndef HAVE_STRFTIME_L
144# if _POSIX_VERSION < 200809
145# define HAVE_STRFTIME_L 0
146# else
147# define HAVE_STRFTIME_L 1
148# endif
149#endif
150
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800151#ifndef F_OK
Elliott Hughesce4783c2013-07-12 17:31:11 -0700152#define F_OK 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800153#endif /* !defined F_OK */
154#ifndef R_OK
Elliott Hughesce4783c2013-07-12 17:31:11 -0700155#define R_OK 4
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800156#endif /* !defined R_OK */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800157
158/* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
159#define is_digit(c) ((unsigned)(c) - '0' <= 9)
160
161/*
162** Define HAVE_STDINT_H's default value here, rather than at the
163** start, since __GLIBC__'s value depends on previously-included
164** files.
165** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
166*/
167#ifndef HAVE_STDINT_H
168#define HAVE_STDINT_H \
Elliott Hughes5f564542014-06-19 13:54:10 -0700169 (199901 <= __STDC_VERSION__ \
170 || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
171 || __CYGWIN__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800172#endif /* !defined HAVE_STDINT_H */
173
174#if HAVE_STDINT_H
175#include "stdint.h"
176#endif /* !HAVE_STDINT_H */
177
Elliott Hughesce4783c2013-07-12 17:31:11 -0700178#ifndef HAVE_INTTYPES_H
179# define HAVE_INTTYPES_H HAVE_STDINT_H
180#endif
181#if HAVE_INTTYPES_H
182# include <inttypes.h>
183#endif
184
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800185/* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700186#ifdef __LONG_LONG_MAX__
187# ifndef LLONG_MAX
188# define LLONG_MAX __LONG_LONG_MAX__
189# endif
190# ifndef LLONG_MIN
191# define LLONG_MIN (-1 - LLONG_MAX)
192# endif
193#endif
194
195#ifndef INT_FAST64_MAX
Elliott Hughesce4783c2013-07-12 17:31:11 -0700196# ifdef LLONG_MAX
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700197typedef long long int_fast64_t;
Elliott Hughesce4783c2013-07-12 17:31:11 -0700198# define INT_FAST64_MIN LLONG_MIN
199# define INT_FAST64_MAX LLONG_MAX
200# else
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700201# if LONG_MAX >> 31 < 0xffffffff
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800202Please use a compiler that supports a 64-bit integer type (or wider);
203you may need to compile with "-DHAVE_STDINT_H".
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700204# endif
Elliott Hughesce4783c2013-07-12 17:31:11 -0700205typedef long int_fast64_t;
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700206# define INT_FAST64_MIN LONG_MIN
207# define INT_FAST64_MAX LONG_MAX
208# endif
209#endif
210
211#ifndef SCNdFAST64
212# if INT_FAST64_MAX == LLONG_MAX
213# define SCNdFAST64 "lld"
214# else
215# define SCNdFAST64 "ld"
216# endif
217#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800218
Elliott Hughesce4783c2013-07-12 17:31:11 -0700219#ifndef INT_FAST32_MAX
220# if INT_MAX >> 31 == 0
221typedef long int_fast32_t;
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700222# define INT_FAST32_MAX LONG_MAX
223# define INT_FAST32_MIN LONG_MIN
Elliott Hughesce4783c2013-07-12 17:31:11 -0700224# else
225typedef int int_fast32_t;
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700226# define INT_FAST32_MAX INT_MAX
227# define INT_FAST32_MIN INT_MIN
Elliott Hughesce4783c2013-07-12 17:31:11 -0700228# endif
229#endif
230
231#ifndef INTMAX_MAX
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700232# ifdef LLONG_MAX
Elliott Hughesce4783c2013-07-12 17:31:11 -0700233typedef long long intmax_t;
Elliott Hughese0d0b152013-09-27 00:04:30 -0700234# define strtoimax strtoll
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700235# define INTMAX_MAX LLONG_MAX
236# define INTMAX_MIN LLONG_MIN
Elliott Hughesce4783c2013-07-12 17:31:11 -0700237# else
238typedef long intmax_t;
Elliott Hughese0d0b152013-09-27 00:04:30 -0700239# define strtoimax strtol
Elliott Hughese0d0b152013-09-27 00:04:30 -0700240# define INTMAX_MAX LONG_MAX
241# define INTMAX_MIN LONG_MIN
Elliott Hughesce4783c2013-07-12 17:31:11 -0700242# endif
243#endif
244
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700245#ifndef PRIdMAX
246# if INTMAX_MAX == LLONG_MAX
247# define PRIdMAX "lld"
248# else
249# define PRIdMAX "ld"
250# endif
251#endif
252
253#ifndef UINT_FAST64_MAX
254# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
255typedef unsigned long long uint_fast64_t;
256# else
257# if ULONG_MAX >> 31 >> 1 < 0xffffffff
258Please use a compiler that supports a 64-bit integer type (or wider);
259you may need to compile with "-DHAVE_STDINT_H".
260# endif
261typedef unsigned long uint_fast64_t;
262# endif
263#endif
264
Elliott Hughesce4783c2013-07-12 17:31:11 -0700265#ifndef UINTMAX_MAX
266# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
267typedef unsigned long long uintmax_t;
Elliott Hughesce4783c2013-07-12 17:31:11 -0700268# else
269typedef unsigned long uintmax_t;
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700270# endif
271#endif
272
273#ifndef PRIuMAX
274# if defined ULLONG_MAX || defined __LONG_LONG_MAX__
275# define PRIuMAX "llu"
276# else
Elliott Hughesce4783c2013-07-12 17:31:11 -0700277# define PRIuMAX "lu"
278# endif
279#endif
280
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800281#ifndef INT32_MAX
282#define INT32_MAX 0x7fffffff
283#endif /* !defined INT32_MAX */
284#ifndef INT32_MIN
285#define INT32_MIN (-1 - INT32_MAX)
286#endif /* !defined INT32_MIN */
287
Elliott Hughes5f564542014-06-19 13:54:10 -0700288#ifndef SIZE_MAX
289#define SIZE_MAX ((size_t) -1)
290#endif
291
Elliott Hughesce4783c2013-07-12 17:31:11 -0700292#if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
293# define ATTRIBUTE_CONST __attribute__ ((const))
294# define ATTRIBUTE_PURE __attribute__ ((__pure__))
Elliott Hughese0d0b152013-09-27 00:04:30 -0700295# define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
Elliott Hughesce4783c2013-07-12 17:31:11 -0700296#else
297# define ATTRIBUTE_CONST /* empty */
298# define ATTRIBUTE_PURE /* empty */
Elliott Hughese0d0b152013-09-27 00:04:30 -0700299# define ATTRIBUTE_FORMAT(spec) /* empty */
Elliott Hughesce4783c2013-07-12 17:31:11 -0700300#endif
301
302#if !defined _Noreturn && __STDC_VERSION__ < 201112
303# if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
304# define _Noreturn __attribute__ ((__noreturn__))
305# else
306# define _Noreturn
307# endif
308#endif
309
310#if __STDC_VERSION__ < 199901 && !defined restrict
311# define restrict /* empty */
312#endif
313
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800314/*
315** Workarounds for compilers/systems.
316*/
317
318/*
Elliott Hughesce4783c2013-07-12 17:31:11 -0700319** Compile with -Dtime_tz=T to build the tz package with a private
320** time_t type equivalent to T rather than the system-supplied time_t.
321** This debugging feature can test unusual design decisions
322** (e.g., time_t wider than 'long', or unsigned time_t) even on
323** typical platforms.
324*/
325#ifdef time_tz
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700326# ifdef LOCALTIME_IMPLEMENTATION
Elliott Hughesce4783c2013-07-12 17:31:11 -0700327static time_t sys_time(time_t *x) { return time(x); }
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700328# endif
329
330typedef time_tz tz_time_t;
Elliott Hughesce4783c2013-07-12 17:31:11 -0700331
332# undef ctime
333# define ctime tz_ctime
334# undef ctime_r
335# define ctime_r tz_ctime_r
336# undef difftime
337# define difftime tz_difftime
338# undef gmtime
339# define gmtime tz_gmtime
340# undef gmtime_r
341# define gmtime_r tz_gmtime_r
342# undef localtime
343# define localtime tz_localtime
344# undef localtime_r
345# define localtime_r tz_localtime_r
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700346# undef localtime_rz
347# define localtime_rz tz_localtime_rz
Elliott Hughesce4783c2013-07-12 17:31:11 -0700348# undef mktime
349# define mktime tz_mktime
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700350# undef mktime_z
351# define mktime_z tz_mktime_z
352# undef offtime
353# define offtime tz_offtime
354# undef posix2time
355# define posix2time tz_posix2time
356# undef posix2time_z
357# define posix2time_z tz_posix2time_z
Elliott Hughesce4783c2013-07-12 17:31:11 -0700358# undef time
359# define time tz_time
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700360# undef time2posix
361# define time2posix tz_time2posix
362# undef time2posix_z
363# define time2posix_z tz_time2posix_z
Elliott Hughesce4783c2013-07-12 17:31:11 -0700364# undef time_t
365# define time_t tz_time_t
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700366# undef timegm
367# define timegm tz_timegm
368# undef timelocal
369# define timelocal tz_timelocal
370# undef timeoff
371# define timeoff tz_timeoff
372# undef tzalloc
373# define tzalloc tz_tzalloc
374# undef tzfree
375# define tzfree tz_tzfree
376# undef tzset
377# define tzset tz_tzset
378# undef tzsetwall
379# define tzsetwall tz_tzsetwall
Elliott Hughesce4783c2013-07-12 17:31:11 -0700380
381char *ctime(time_t const *);
382char *ctime_r(time_t const *, char *);
383double difftime(time_t, time_t);
384struct tm *gmtime(time_t const *);
385struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
386struct tm *localtime(time_t const *);
387struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
388time_t mktime(struct tm *);
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700389time_t time(time_t *);
390void tzset(void);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800391#endif
392
Elliott Hughes0a610d02016-07-29 14:04:17 -0700393#if !HAVE_DECL_ASCTIME_R && !defined asctime_r
394extern char *asctime_r(struct tm const *restrict, char *restrict);
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700395#endif
396
Elliott Hughes0a610d02016-07-29 14:04:17 -0700397#if !HAVE_POSIX_DECLS
398# ifdef USG_COMPAT
399# ifndef timezone
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700400extern long timezone;
Elliott Hughes0a610d02016-07-29 14:04:17 -0700401# endif
402# ifndef daylight
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700403extern int daylight;
Elliott Hughes0a610d02016-07-29 14:04:17 -0700404# endif
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700405# endif
406#endif
Elliott Hughes0a610d02016-07-29 14:04:17 -0700407
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700408#if defined ALTZONE && !defined altzone
409extern long altzone;
410#endif
411
412/*
413** The STD_INSPIRED functions are similar, but most also need
414** declarations if time_tz is defined.
415*/
416
417#ifdef STD_INSPIRED
418# if !defined tzsetwall || defined time_tz
419void tzsetwall(void);
420# endif
421# if !defined offtime || defined time_tz
422struct tm *offtime(time_t const *, long);
423# endif
424# if !defined timegm || defined time_tz
425time_t timegm(struct tm *);
426# endif
427# if !defined timelocal || defined time_tz
428time_t timelocal(struct tm *);
429# endif
430# if !defined timeoff || defined time_tz
431time_t timeoff(struct tm *, long);
432# endif
433# if !defined time2posix || defined time_tz
434time_t time2posix(time_t);
435# endif
436# if !defined posix2time || defined time_tz
437time_t posix2time(time_t);
438# endif
439#endif
440
441/* Infer TM_ZONE on systems where this information is known, but suppress
442 guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
443#if (defined __GLIBC__ \
444 || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
445 || (defined __APPLE__ && defined __MACH__))
446# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
447# define TM_GMTOFF tm_gmtoff
448# endif
449# if !defined TM_ZONE && !defined NO_TM_ZONE
450# define TM_ZONE tm_zone
451# endif
452#endif
453
454/*
455** Define functions that are ABI compatible with NetBSD but have
456** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t
457** and labors under the misconception that 'const timezone_t' is a
458** pointer to a constant. This use of 'const' is ineffective, so it
459** is not done here. What we call 'struct state' NetBSD calls
460** 'struct __state', but this is a private name so it doesn't matter.
461*/
462#if NETBSD_INSPIRED
463typedef struct state *timezone_t;
464struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
465 struct tm *restrict);
466time_t mktime_z(timezone_t restrict, struct tm *restrict);
467timezone_t tzalloc(char const *);
468void tzfree(timezone_t);
469# ifdef STD_INSPIRED
470# if !defined posix2time_z || defined time_tz
471time_t posix2time_z(timezone_t, time_t) ATTRIBUTE_PURE;
472# endif
473# if !defined time2posix_z || defined time_tz
474time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE;
475# endif
476# endif
477#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800478
479/*
480** Finally, some convenience items.
481*/
482
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700483#if __STDC_VERSION__ < 199901
484# define true 1
485# define false 0
486# define bool int
487#else
488# include <stdbool.h>
489#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800490
491#ifndef TYPE_BIT
Elliott Hughesce4783c2013-07-12 17:31:11 -0700492#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800493#endif /* !defined TYPE_BIT */
494
495#ifndef TYPE_SIGNED
496#define TYPE_SIGNED(type) (((type) -1) < 0)
497#endif /* !defined TYPE_SIGNED */
498
Stephen Hines23360cc2015-09-29 09:28:41 -0700499#define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
500
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700501/* Max and min values of the integer type T, of which only the bottom
502 B bits are used, and where the highest-order used bit is considered
503 to be a sign bit if T is signed. */
504#define MAXVAL(t, b) \
505 ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
506 - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
507#define MINVAL(t, b) \
508 ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
Stephen Hines23360cc2015-09-29 09:28:41 -0700509
510/* The minimum and maximum finite time values. This assumes no padding. */
511static time_t const time_t_min = MINVAL(time_t, TYPE_BIT(time_t));
512static time_t const time_t_max = MAXVAL(time_t, TYPE_BIT(time_t));
Elliott Hughes713fe642013-08-22 14:13:50 -0700513
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800514#ifndef INT_STRLEN_MAXIMUM
515/*
516** 302 / 1000 is log10(2.0) rounded up.
517** Subtract one for the sign bit if the type is signed;
518** add one for integer division truncation;
519** add one more for a minus sign if the type is signed.
520*/
521#define INT_STRLEN_MAXIMUM(type) \
Elliott Hughesce4783c2013-07-12 17:31:11 -0700522 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
523 1 + TYPE_SIGNED(type))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800524#endif /* !defined INT_STRLEN_MAXIMUM */
525
526/*
527** INITIALIZE(x)
528*/
529
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800530#ifdef lint
Elliott Hughes5f564542014-06-19 13:54:10 -0700531# define INITIALIZE(x) ((x) = 0)
532#else
533# define INITIALIZE(x)
534#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800535
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700536#ifndef UNINIT_TRAP
537# define UNINIT_TRAP 0
538#endif
539
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800540/*
541** For the benefit of GNU folk...
Elliott Hughes5f564542014-06-19 13:54:10 -0700542** '_(MSGID)' uses the current locale's message library string for MSGID.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800543** The default is to use gettext if available, and use MSGID otherwise.
544*/
545
546#ifndef _
547#if HAVE_GETTEXT
548#define _(msgid) gettext(msgid)
549#else /* !HAVE_GETTEXT */
550#define _(msgid) msgid
551#endif /* !HAVE_GETTEXT */
552#endif /* !defined _ */
553
Elliott Hughes9fb22a32015-10-07 17:13:40 -0700554#if !defined TZ_DOMAIN && defined HAVE_GETTEXT
Elliott Hughes5f564542014-06-19 13:54:10 -0700555# define TZ_DOMAIN "tz"
556#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800557
558#if HAVE_INCOMPATIBLE_CTIME_R
559#undef asctime_r
560#undef ctime_r
Elliott Hughesce4783c2013-07-12 17:31:11 -0700561char *asctime_r(struct tm const *, char *);
562char *ctime_r(time_t const *, char *);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800563#endif /* HAVE_INCOMPATIBLE_CTIME_R */
564
565#ifndef YEARSPERREPEAT
Elliott Hughesce4783c2013-07-12 17:31:11 -0700566#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800567#endif /* !defined YEARSPERREPEAT */
568
569/*
570** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
571*/
572
573#ifndef AVGSECSPERYEAR
Elliott Hughesce4783c2013-07-12 17:31:11 -0700574#define AVGSECSPERYEAR 31556952L
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800575#endif /* !defined AVGSECSPERYEAR */
576
577#ifndef SECSPERREPEAT
Elliott Hughesce4783c2013-07-12 17:31:11 -0700578#define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800579#endif /* !defined SECSPERREPEAT */
Elliott Hughesce4783c2013-07-12 17:31:11 -0700580
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800581#ifndef SECSPERREPEAT_BITS
Elliott Hughesce4783c2013-07-12 17:31:11 -0700582#define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800583#endif /* !defined SECSPERREPEAT_BITS */
584
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800585#endif /* !defined PRIVATE_H */