Fix __getcwd rewinddir namespace (bug 17584).
[glibc.git] / timezone / private.h
blob4e8f4ae7bc63554dda9983b07a40f68a19318442
1 #ifndef PRIVATE_H
3 #define PRIVATE_H
5 /*
6 ** This file is in the public domain, so clarified as of
7 ** 1996-06-05 by Arthur David Olson.
8 */
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!
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'.
25 #ifndef HAVE_ADJTIME
26 #define HAVE_ADJTIME 1
27 #endif /* !defined HAVE_ADJTIME */
29 #ifndef HAVE_GETTEXT
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 */
37 #ifndef HAVE_LINK
38 #define HAVE_LINK 1
39 #endif /* !defined HAVE_LINK */
41 #ifndef HAVE_SETTIMEOFDAY
42 #define HAVE_SETTIMEOFDAY 3
43 #endif /* !defined HAVE_SETTIMEOFDAY */
45 #ifndef HAVE_SYMLINK
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 */
57 #ifndef HAVE_UNISTD_H
58 #define HAVE_UNISTD_H 1
59 #endif /* !defined HAVE_UNISTD_H */
61 #ifndef HAVE_UTMPX_H
62 #define HAVE_UTMPX_H 0
63 #endif /* !defined HAVE_UTMPX_H */
65 #ifndef LOCALE_HOME
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 */
75 ** Nested includes
78 #include "sys/types.h" /* for time_t */
79 #include "stdio.h"
80 #include "errno.h"
81 #include "string.h"
82 #include "limits.h" /* for CHAR_BIT et al. */
83 #include "time.h"
84 #include "stdlib.h"
86 #if HAVE_GETTEXT
87 #include "libintl.h"
88 #endif /* HAVE_GETTEXT */
90 #if HAVE_SYS_WAIT_H
91 #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
92 #endif /* HAVE_SYS_WAIT_H */
94 #ifndef WIFEXITED
95 #define WIFEXITED(status) (((status) & 0xff) == 0)
96 #endif /* !defined WIFEXITED */
97 #ifndef WEXITSTATUS
98 #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
99 #endif /* !defined WEXITSTATUS */
101 #if HAVE_UNISTD_H
102 #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */
103 #endif /* HAVE_UNISTD_H */
105 #ifndef F_OK
106 #define F_OK 0
107 #endif /* !defined F_OK */
108 #ifndef R_OK
109 #define R_OK 4
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
118 ** files.
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__ + (1 <= __GLIBC_MINOR__) \
125 || __CYGWIN__)
126 #endif /* !defined HAVE_STDINT_H */
128 #if HAVE_STDINT_H
129 #include "stdint.h"
130 #endif /* !HAVE_STDINT_H */
132 #ifndef HAVE_INTTYPES_H
133 # define HAVE_INTTYPES_H HAVE_STDINT_H
134 #endif
135 #if HAVE_INTTYPES_H
136 # include <inttypes.h>
137 #endif
139 #ifndef INT_FAST64_MAX
140 /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
141 #if defined LLONG_MAX || defined __LONG_LONG_MAX__
142 typedef long long int_fast64_t;
143 # ifdef LLONG_MAX
144 # define INT_FAST64_MIN LLONG_MIN
145 # define INT_FAST64_MAX LLONG_MAX
146 # else
147 # define INT_FAST64_MIN __LONG_LONG_MIN__
148 # define INT_FAST64_MAX __LONG_LONG_MAX__
149 # endif
150 # define SCNdFAST64 "lld"
151 #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
152 #if (LONG_MAX >> 31) < 0xffffffff
153 Please use a compiler that supports a 64-bit integer type (or wider);
154 you may need to compile with "-DHAVE_STDINT_H".
155 #endif /* (LONG_MAX >> 31) < 0xffffffff */
156 typedef long int_fast64_t;
157 # define INT_FAST64_MIN LONG_MIN
158 # define INT_FAST64_MAX LONG_MAX
159 # define SCNdFAST64 "ld"
160 #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
161 #endif /* !defined INT_FAST64_MAX */
163 #ifndef INT_FAST32_MAX
164 # if INT_MAX >> 31 == 0
165 typedef long int_fast32_t;
166 # else
167 typedef int int_fast32_t;
168 # endif
169 #endif
171 #ifndef INTMAX_MAX
172 # if defined LLONG_MAX || defined __LONG_LONG_MAX__
173 typedef long long intmax_t;
174 # define strtoimax strtoll
175 # define PRIdMAX "lld"
176 # ifdef LLONG_MAX
177 # define INTMAX_MAX LLONG_MAX
178 # define INTMAX_MIN LLONG_MIN
179 # else
180 # define INTMAX_MAX __LONG_LONG_MAX__
181 # define INTMAX_MIN __LONG_LONG_MIN__
182 # endif
183 # else
184 typedef long intmax_t;
185 # define strtoimax strtol
186 # define PRIdMAX "ld"
187 # define INTMAX_MAX LONG_MAX
188 # define INTMAX_MIN LONG_MIN
189 # endif
190 #endif
192 #ifndef UINTMAX_MAX
193 # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
194 typedef unsigned long long uintmax_t;
195 # define PRIuMAX "llu"
196 # else
197 typedef unsigned long uintmax_t;
198 # define PRIuMAX "lu"
199 # endif
200 #endif
202 #ifndef INT32_MAX
203 #define INT32_MAX 0x7fffffff
204 #endif /* !defined INT32_MAX */
205 #ifndef INT32_MIN
206 #define INT32_MIN (-1 - INT32_MAX)
207 #endif /* !defined INT32_MIN */
209 #ifndef SIZE_MAX
210 #define SIZE_MAX ((size_t) -1)
211 #endif
213 #if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
214 # define ATTRIBUTE_CONST __attribute__ ((const))
215 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
216 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
217 #else
218 # define ATTRIBUTE_CONST /* empty */
219 # define ATTRIBUTE_PURE /* empty */
220 # define ATTRIBUTE_FORMAT(spec) /* empty */
221 #endif
223 #if !defined _Noreturn && __STDC_VERSION__ < 201112
224 # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
225 # define _Noreturn __attribute__ ((__noreturn__))
226 # else
227 # define _Noreturn
228 # endif
229 #endif
231 #if __STDC_VERSION__ < 199901 && !defined restrict
232 # define restrict /* empty */
233 #endif
236 ** Workarounds for compilers/systems.
240 ** Some time.h implementations don't declare asctime_r.
241 ** Others might define it as a macro.
242 ** Fix the former without affecting the latter.
245 #ifndef asctime_r
246 extern char * asctime_r(struct tm const *, char *);
247 #endif
250 ** Compile with -Dtime_tz=T to build the tz package with a private
251 ** time_t type equivalent to T rather than the system-supplied time_t.
252 ** This debugging feature can test unusual design decisions
253 ** (e.g., time_t wider than 'long', or unsigned time_t) even on
254 ** typical platforms.
256 #ifdef time_tz
257 static time_t sys_time(time_t *x) { return time(x); }
259 # undef ctime
260 # define ctime tz_ctime
261 # undef ctime_r
262 # define ctime_r tz_ctime_r
263 # undef difftime
264 # define difftime tz_difftime
265 # undef gmtime
266 # define gmtime tz_gmtime
267 # undef gmtime_r
268 # define gmtime_r tz_gmtime_r
269 # undef localtime
270 # define localtime tz_localtime
271 # undef localtime_r
272 # define localtime_r tz_localtime_r
273 # undef mktime
274 # define mktime tz_mktime
275 # undef time
276 # define time tz_time
277 # undef time_t
278 # define time_t tz_time_t
280 typedef time_tz time_t;
282 char *ctime(time_t const *);
283 char *ctime_r(time_t const *, char *);
284 double difftime(time_t, time_t);
285 struct tm *gmtime(time_t const *);
286 struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
287 struct tm *localtime(time_t const *);
288 struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
289 time_t mktime(struct tm *);
291 static time_t
292 time(time_t *p)
294 time_t r = sys_time(0);
295 if (p)
296 *p = r;
297 return r;
299 #endif
302 ** Private function declarations.
305 char * icatalloc(char * old, const char * new);
306 char * icpyalloc(const char * string);
307 const char * scheck(const char * string, const char * format);
310 ** Finally, some convenience items.
313 #ifndef TRUE
314 #define TRUE 1
315 #endif /* !defined TRUE */
317 #ifndef FALSE
318 #define FALSE 0
319 #endif /* !defined FALSE */
321 #ifndef TYPE_BIT
322 #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
323 #endif /* !defined TYPE_BIT */
325 #ifndef TYPE_SIGNED
326 #define TYPE_SIGNED(type) (((type) -1) < 0)
327 #endif /* !defined TYPE_SIGNED */
329 /* The minimum and maximum finite time values. */
330 static time_t const time_t_min =
331 (TYPE_SIGNED(time_t)
332 ? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
333 : 0);
334 static time_t const time_t_max =
335 (TYPE_SIGNED(time_t)
336 ? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
337 : -1);
339 #ifndef INT_STRLEN_MAXIMUM
341 ** 302 / 1000 is log10(2.0) rounded up.
342 ** Subtract one for the sign bit if the type is signed;
343 ** add one for integer division truncation;
344 ** add one more for a minus sign if the type is signed.
346 #define INT_STRLEN_MAXIMUM(type) \
347 ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
348 1 + TYPE_SIGNED(type))
349 #endif /* !defined INT_STRLEN_MAXIMUM */
352 ** INITIALIZE(x)
355 #ifndef GNUC_or_lint
356 #ifdef lint
357 #define GNUC_or_lint
358 #endif /* defined lint */
359 #ifndef lint
360 #ifdef __GNUC__
361 #define GNUC_or_lint
362 #endif /* defined __GNUC__ */
363 #endif /* !defined lint */
364 #endif /* !defined GNUC_or_lint */
366 #ifndef INITIALIZE
367 #ifdef GNUC_or_lint
368 #define INITIALIZE(x) ((x) = 0)
369 #endif /* defined GNUC_or_lint */
370 #ifndef GNUC_or_lint
371 #define INITIALIZE(x)
372 #endif /* !defined GNUC_or_lint */
373 #endif /* !defined INITIALIZE */
376 ** For the benefit of GNU folk...
377 ** `_(MSGID)' uses the current locale's message library string for MSGID.
378 ** The default is to use gettext if available, and use MSGID otherwise.
381 #ifndef _
382 #if HAVE_GETTEXT
383 #define _(msgid) gettext(msgid)
384 #else /* !HAVE_GETTEXT */
385 #define _(msgid) msgid
386 #endif /* !HAVE_GETTEXT */
387 #endif /* !defined _ */
389 #ifndef TZ_DOMAIN
390 #define TZ_DOMAIN "tz"
391 #endif /* !defined TZ_DOMAIN */
393 #if HAVE_INCOMPATIBLE_CTIME_R
394 #undef asctime_r
395 #undef ctime_r
396 char *asctime_r(struct tm const *, char *);
397 char *ctime_r(time_t const *, char *);
398 #endif /* HAVE_INCOMPATIBLE_CTIME_R */
400 #ifndef YEARSPERREPEAT
401 #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
402 #endif /* !defined YEARSPERREPEAT */
405 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
408 #ifndef AVGSECSPERYEAR
409 #define AVGSECSPERYEAR 31556952L
410 #endif /* !defined AVGSECSPERYEAR */
412 #ifndef SECSPERREPEAT
413 #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
414 #endif /* !defined SECSPERREPEAT */
416 #ifndef SECSPERREPEAT_BITS
417 #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
418 #endif /* !defined SECSPERREPEAT_BITS */
421 ** UNIX was a registered trademark of The Open Group in 2003.
424 #endif /* !defined PRIVATE_H */