private.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /* Private header for tzdb code. */
  2. #ifndef PRIVATE_H
  3. #define PRIVATE_H
  4. /*
  5. ** This file is in the public domain, so clarified as of
  6. ** 1996-06-05 by Arthur David Olson.
  7. */
  8. /*
  9. ** This header is for use ONLY with the time conversion code.
  10. ** There is no guarantee that it will remain unchanged,
  11. ** or that it will remain at all.
  12. ** Do NOT copy it to any system include directory.
  13. ** Thank you!
  14. */
  15. /*
  16. ** zdump has been made independent of the rest of the time
  17. ** conversion package to increase confidence in the verification it provides.
  18. ** You can use zdump to help in verifying other implementations.
  19. ** To do this, compile with -DUSE_LTZ=0 and link without the tz library.
  20. */
  21. #ifndef USE_LTZ
  22. # define USE_LTZ 1
  23. #endif
  24. /* This string was in the Factory zone through version 2016f. */
  25. #define GRANDPARENTED "Local time zone must be set--see zic manual page"
  26. /*
  27. ** Defaults for preprocessor symbols.
  28. ** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'.
  29. */
  30. #ifndef HAVE_DECL_ASCTIME_R
  31. #define HAVE_DECL_ASCTIME_R 1
  32. #endif
  33. #if !defined HAVE_GENERIC && defined __has_extension
  34. # if __has_extension(c_generic_selections)
  35. # define HAVE_GENERIC 1
  36. # else
  37. # define HAVE_GENERIC 0
  38. # endif
  39. #endif
  40. /* _Generic is buggy in pre-4.9 GCC. */
  41. #if !defined HAVE_GENERIC && defined __GNUC__
  42. # define HAVE_GENERIC (4 < __GNUC__ + (9 <= __GNUC_MINOR__))
  43. #endif
  44. #ifndef HAVE_GENERIC
  45. # define HAVE_GENERIC (201112 <= __STDC_VERSION__)
  46. #endif
  47. #ifndef HAVE_GETTEXT
  48. #define HAVE_GETTEXT 0
  49. #endif /* !defined HAVE_GETTEXT */
  50. #ifndef HAVE_INCOMPATIBLE_CTIME_R
  51. #define HAVE_INCOMPATIBLE_CTIME_R 0
  52. #endif
  53. #ifndef HAVE_LINK
  54. #define HAVE_LINK 1
  55. #endif /* !defined HAVE_LINK */
  56. #ifndef HAVE_POSIX_DECLS
  57. #define HAVE_POSIX_DECLS 1
  58. #endif
  59. #ifndef HAVE_STDBOOL_H
  60. #define HAVE_STDBOOL_H (199901 <= __STDC_VERSION__)
  61. #endif
  62. #ifndef HAVE_STRDUP
  63. #define HAVE_STRDUP 1
  64. #endif
  65. #ifndef HAVE_STRTOLL
  66. #define HAVE_STRTOLL 1
  67. #endif
  68. #ifndef HAVE_SYMLINK
  69. #define HAVE_SYMLINK 1
  70. #endif /* !defined HAVE_SYMLINK */
  71. #ifndef HAVE_SYS_STAT_H
  72. #define HAVE_SYS_STAT_H 1
  73. #endif /* !defined HAVE_SYS_STAT_H */
  74. #ifndef HAVE_SYS_WAIT_H
  75. #define HAVE_SYS_WAIT_H 1
  76. #endif /* !defined HAVE_SYS_WAIT_H */
  77. #ifndef HAVE_UNISTD_H
  78. #define HAVE_UNISTD_H 1
  79. #endif /* !defined HAVE_UNISTD_H */
  80. #ifndef HAVE_UTMPX_H
  81. #define HAVE_UTMPX_H 1
  82. #endif /* !defined HAVE_UTMPX_H */
  83. #ifndef NETBSD_INSPIRED
  84. # define NETBSD_INSPIRED 1
  85. #endif
  86. #if HAVE_INCOMPATIBLE_CTIME_R
  87. #define asctime_r _incompatible_asctime_r
  88. #define ctime_r _incompatible_ctime_r
  89. #endif /* HAVE_INCOMPATIBLE_CTIME_R */
  90. /* Enable tm_gmtoff, tm_zone, and environ on GNUish systems. */
  91. #define _GNU_SOURCE 1
  92. /* Fix asctime_r on Solaris 11. */
  93. #define _POSIX_PTHREAD_SEMANTICS 1
  94. /* Enable strtoimax on pre-C99 Solaris 11. */
  95. #define __EXTENSIONS__ 1
  96. /* To avoid having 'stat' fail unnecessarily with errno == EOVERFLOW,
  97. enable large files on GNUish systems ... */
  98. #ifndef _FILE_OFFSET_BITS
  99. # define _FILE_OFFSET_BITS 64
  100. #endif
  101. /* ... and on AIX ... */
  102. #define _LARGE_FILES 1
  103. /* ... and enable large inode numbers on Mac OS X 10.5 and later. */
  104. #define _DARWIN_USE_64_BIT_INODE 1
  105. /*
  106. ** Nested includes
  107. */
  108. /* Avoid clashes with NetBSD by renaming NetBSD's declarations. */
  109. #define localtime_rz sys_localtime_rz
  110. #define mktime_z sys_mktime_z
  111. #define posix2time_z sys_posix2time_z
  112. #define time2posix_z sys_time2posix_z
  113. #define timezone_t sys_timezone_t
  114. #define tzalloc sys_tzalloc
  115. #define tzfree sys_tzfree
  116. #include <time.h>
  117. #undef localtime_rz
  118. #undef mktime_z
  119. #undef posix2time_z
  120. #undef time2posix_z
  121. #undef timezone_t
  122. #undef tzalloc
  123. #undef tzfree
  124. #include <sys/types.h> /* for time_t */
  125. #include <string.h>
  126. #include <limits.h> /* for CHAR_BIT et al. */
  127. #include <stdlib.h>
  128. #include <errno.h>
  129. #ifndef ENAMETOOLONG
  130. # define ENAMETOOLONG EINVAL
  131. #endif
  132. #ifndef ENOTSUP
  133. # define ENOTSUP EINVAL
  134. #endif
  135. #ifndef EOVERFLOW
  136. # define EOVERFLOW EINVAL
  137. #endif
  138. #if HAVE_GETTEXT
  139. #include <libintl.h>
  140. #endif /* HAVE_GETTEXT */
  141. #if HAVE_UNISTD_H
  142. #include <unistd.h> /* for R_OK, and other POSIX goodness */
  143. #endif /* HAVE_UNISTD_H */
  144. #ifndef HAVE_STRFTIME_L
  145. # if _POSIX_VERSION < 200809
  146. # define HAVE_STRFTIME_L 0
  147. # else
  148. # define HAVE_STRFTIME_L 1
  149. # endif
  150. #endif
  151. #ifndef USG_COMPAT
  152. # ifndef _XOPEN_VERSION
  153. # define USG_COMPAT 0
  154. # else
  155. # define USG_COMPAT 1
  156. # endif
  157. #endif
  158. #ifndef HAVE_TZNAME
  159. # if _POSIX_VERSION < 198808 && !USG_COMPAT
  160. # define HAVE_TZNAME 0
  161. # else
  162. # define HAVE_TZNAME 1
  163. # endif
  164. #endif
  165. #ifndef R_OK
  166. #define R_OK 4
  167. #endif /* !defined R_OK */
  168. /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
  169. #define is_digit(c) ((unsigned)(c) - '0' <= 9)
  170. /*
  171. ** Define HAVE_STDINT_H's default value here, rather than at the
  172. ** start, since __GLIBC__ and INTMAX_MAX's values depend on
  173. ** previously-included files. glibc 2.1 and Solaris 10 and later have
  174. ** stdint.h, even with pre-C99 compilers.
  175. */
  176. #ifndef HAVE_STDINT_H
  177. #define HAVE_STDINT_H \
  178. (199901 <= __STDC_VERSION__ \
  179. || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \
  180. || __CYGWIN__ || INTMAX_MAX)
  181. #endif /* !defined HAVE_STDINT_H */
  182. #if HAVE_STDINT_H
  183. #include <stdint.h>
  184. #endif /* !HAVE_STDINT_H */
  185. #ifndef HAVE_INTTYPES_H
  186. # define HAVE_INTTYPES_H HAVE_STDINT_H
  187. #endif
  188. #if HAVE_INTTYPES_H
  189. # include <inttypes.h>
  190. #endif
  191. /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
  192. #ifdef __LONG_LONG_MAX__
  193. # ifndef LLONG_MAX
  194. # define LLONG_MAX __LONG_LONG_MAX__
  195. # endif
  196. # ifndef LLONG_MIN
  197. # define LLONG_MIN (-1 - LLONG_MAX)
  198. # endif
  199. #endif
  200. #ifndef INT_FAST64_MAX
  201. # ifdef LLONG_MAX
  202. typedef long long int_fast64_t;
  203. # define INT_FAST64_MIN LLONG_MIN
  204. # define INT_FAST64_MAX LLONG_MAX
  205. # else
  206. # if LONG_MAX >> 31 < 0xffffffff
  207. Please use a compiler that supports a 64-bit integer type (or wider);
  208. you may need to compile with "-DHAVE_STDINT_H".
  209. # endif
  210. typedef long int_fast64_t;
  211. # define INT_FAST64_MIN LONG_MIN
  212. # define INT_FAST64_MAX LONG_MAX
  213. # endif
  214. #endif
  215. #ifndef PRIdFAST64
  216. # if INT_FAST64_MAX == LLONG_MAX
  217. # define PRIdFAST64 "lld"
  218. # else
  219. # define PRIdFAST64 "ld"
  220. # endif
  221. #endif
  222. #ifndef SCNdFAST64
  223. # define SCNdFAST64 PRIdFAST64
  224. #endif
  225. #ifndef INT_FAST32_MAX
  226. # if INT_MAX >> 31 == 0
  227. typedef long int_fast32_t;
  228. # define INT_FAST32_MAX LONG_MAX
  229. # define INT_FAST32_MIN LONG_MIN
  230. # else
  231. typedef int int_fast32_t;
  232. # define INT_FAST32_MAX INT_MAX
  233. # define INT_FAST32_MIN INT_MIN
  234. # endif
  235. #endif
  236. #ifndef INTMAX_MAX
  237. # ifdef LLONG_MAX
  238. typedef long long intmax_t;
  239. # if HAVE_STRTOLL
  240. # define strtoimax strtoll
  241. # endif
  242. # define INTMAX_MAX LLONG_MAX
  243. # define INTMAX_MIN LLONG_MIN
  244. # else
  245. typedef long intmax_t;
  246. # define INTMAX_MAX LONG_MAX
  247. # define INTMAX_MIN LONG_MIN
  248. # endif
  249. # ifndef strtoimax
  250. # define strtoimax strtol
  251. # endif
  252. #endif
  253. #ifndef PRIdMAX
  254. # if INTMAX_MAX == LLONG_MAX
  255. # define PRIdMAX "lld"
  256. # else
  257. # define PRIdMAX "ld"
  258. # endif
  259. #endif
  260. #ifndef UINT_FAST64_MAX
  261. # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
  262. typedef unsigned long long uint_fast64_t;
  263. # else
  264. # if ULONG_MAX >> 31 >> 1 < 0xffffffff
  265. Please use a compiler that supports a 64-bit integer type (or wider);
  266. you may need to compile with "-DHAVE_STDINT_H".
  267. # endif
  268. typedef unsigned long uint_fast64_t;
  269. # endif
  270. #endif
  271. #ifndef UINTMAX_MAX
  272. # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
  273. typedef unsigned long long uintmax_t;
  274. # else
  275. typedef unsigned long uintmax_t;
  276. # endif
  277. #endif
  278. #ifndef PRIuMAX
  279. # if defined ULLONG_MAX || defined __LONG_LONG_MAX__
  280. # define PRIuMAX "llu"
  281. # else
  282. # define PRIuMAX "lu"
  283. # endif
  284. #endif
  285. #ifndef INT32_MAX
  286. #define INT32_MAX 0x7fffffff
  287. #endif /* !defined INT32_MAX */
  288. #ifndef INT32_MIN
  289. #define INT32_MIN (-1 - INT32_MAX)
  290. #endif /* !defined INT32_MIN */
  291. #ifndef SIZE_MAX
  292. #define SIZE_MAX ((size_t) -1)
  293. #endif
  294. #if 3 <= __GNUC__
  295. # define ATTRIBUTE_CONST __attribute__ ((const))
  296. # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
  297. # define ATTRIBUTE_PURE __attribute__ ((__pure__))
  298. # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
  299. #else
  300. # define ATTRIBUTE_CONST /* empty */
  301. # define ATTRIBUTE_MALLOC /* empty */
  302. # define ATTRIBUTE_PURE /* empty */
  303. # define ATTRIBUTE_FORMAT(spec) /* empty */
  304. #endif
  305. #if !defined _Noreturn && __STDC_VERSION__ < 201112
  306. # if 2 < __GNUC__ + (8 <= __GNUC_MINOR__)
  307. # define _Noreturn __attribute__ ((__noreturn__))
  308. # else
  309. # define _Noreturn
  310. # endif
  311. #endif
  312. #if __STDC_VERSION__ < 199901 && !defined restrict
  313. # define restrict /* empty */
  314. #endif
  315. /*
  316. ** Workarounds for compilers/systems.
  317. */
  318. #ifndef EPOCH_LOCAL
  319. # define EPOCH_LOCAL 0
  320. #endif
  321. #ifndef EPOCH_OFFSET
  322. # define EPOCH_OFFSET 0
  323. #endif
  324. #ifndef RESERVE_STD_EXT_IDS
  325. # define RESERVE_STD_EXT_IDS 0
  326. #endif
  327. /* If standard C identifiers with external linkage (e.g., localtime)
  328. are reserved and are not already being renamed anyway, rename them
  329. as if compiling with '-Dtime_tz=time_t'. */
  330. #if !defined time_tz && RESERVE_STD_EXT_IDS && USE_LTZ
  331. # define time_tz time_t
  332. #endif
  333. /*
  334. ** Compile with -Dtime_tz=T to build the tz package with a private
  335. ** time_t type equivalent to T rather than the system-supplied time_t.
  336. ** This debugging feature can test unusual design decisions
  337. ** (e.g., time_t wider than 'long', or unsigned time_t) even on
  338. ** typical platforms.
  339. */
  340. #if defined time_tz || EPOCH_LOCAL || EPOCH_OFFSET != 0
  341. # define TZ_TIME_T 1
  342. #else
  343. # define TZ_TIME_T 0
  344. #endif
  345. #if TZ_TIME_T
  346. # ifdef LOCALTIME_IMPLEMENTATION
  347. static time_t sys_time(time_t *x) { return time(x); }
  348. # endif
  349. typedef time_tz tz_time_t;
  350. # undef ctime
  351. # define ctime tz_ctime
  352. # undef ctime_r
  353. # define ctime_r tz_ctime_r
  354. # undef difftime
  355. # define difftime tz_difftime
  356. # undef gmtime
  357. # define gmtime tz_gmtime
  358. # undef gmtime_r
  359. # define gmtime_r tz_gmtime_r
  360. # undef localtime
  361. # define localtime tz_localtime
  362. # undef localtime_r
  363. # define localtime_r tz_localtime_r
  364. # undef localtime_rz
  365. # define localtime_rz tz_localtime_rz
  366. # undef mktime
  367. # define mktime tz_mktime
  368. # undef mktime_z
  369. # define mktime_z tz_mktime_z
  370. # undef offtime
  371. # define offtime tz_offtime
  372. # undef posix2time
  373. # define posix2time tz_posix2time
  374. # undef posix2time_z
  375. # define posix2time_z tz_posix2time_z
  376. # undef strftime
  377. # define strftime tz_strftime
  378. # undef time
  379. # define time tz_time
  380. # undef time2posix
  381. # define time2posix tz_time2posix
  382. # undef time2posix_z
  383. # define time2posix_z tz_time2posix_z
  384. # undef time_t
  385. # define time_t tz_time_t
  386. # undef timegm
  387. # define timegm tz_timegm
  388. # undef timelocal
  389. # define timelocal tz_timelocal
  390. # undef timeoff
  391. # define timeoff tz_timeoff
  392. # undef tzalloc
  393. # define tzalloc tz_tzalloc
  394. # undef tzfree
  395. # define tzfree tz_tzfree
  396. # undef tzset
  397. # define tzset tz_tzset
  398. # undef tzsetwall
  399. # define tzsetwall tz_tzsetwall
  400. # if HAVE_STRFTIME_L
  401. # undef strftime_l
  402. # define strftime_l tz_strftime_l
  403. # endif
  404. # if HAVE_TZNAME
  405. # undef tzname
  406. # define tzname tz_tzname
  407. # endif
  408. # if USG_COMPAT
  409. # undef daylight
  410. # define daylight tz_daylight
  411. # undef timezone
  412. # define timezone tz_timezone
  413. # endif
  414. # ifdef ALTZONE
  415. # undef altzone
  416. # define altzone tz_altzone
  417. # endif
  418. char *ctime(time_t const *);
  419. char *ctime_r(time_t const *, char *);
  420. double difftime(time_t, time_t) ATTRIBUTE_CONST;
  421. size_t strftime(char *restrict, size_t, char const *restrict,
  422. struct tm const *restrict);
  423. # if HAVE_STRFTIME_L
  424. size_t strftime_l(char *restrict, size_t, char const *restrict,
  425. struct tm const *restrict, locale_t);
  426. # endif
  427. struct tm *gmtime(time_t const *);
  428. struct tm *gmtime_r(time_t const *restrict, struct tm *restrict);
  429. struct tm *localtime(time_t const *);
  430. struct tm *localtime_r(time_t const *restrict, struct tm *restrict);
  431. time_t mktime(struct tm *);
  432. time_t time(time_t *);
  433. void tzset(void);
  434. #endif
  435. #if !HAVE_DECL_ASCTIME_R && !defined asctime_r
  436. extern char *asctime_r(struct tm const *restrict, char *restrict);
  437. #endif
  438. #ifndef HAVE_DECL_ENVIRON
  439. # if defined environ || defined __USE_GNU
  440. # define HAVE_DECL_ENVIRON 1
  441. # else
  442. # define HAVE_DECL_ENVIRON 0
  443. # endif
  444. #endif
  445. #if !HAVE_DECL_ENVIRON
  446. extern char **environ;
  447. #endif
  448. #if TZ_TIME_T || !HAVE_POSIX_DECLS
  449. # if HAVE_TZNAME
  450. extern char *tzname[];
  451. # endif
  452. # if USG_COMPAT
  453. extern long timezone;
  454. extern int daylight;
  455. # endif
  456. #endif
  457. #ifdef ALTZONE
  458. extern long altzone;
  459. #endif
  460. /*
  461. ** The STD_INSPIRED functions are similar, but most also need
  462. ** declarations if time_tz is defined.
  463. */
  464. #ifdef STD_INSPIRED
  465. # if TZ_TIME_T || !defined tzsetwall
  466. void tzsetwall(void);
  467. # endif
  468. # if TZ_TIME_T || !defined offtime
  469. struct tm *offtime(time_t const *, long);
  470. # endif
  471. # if TZ_TIME_T || !defined timegm
  472. time_t timegm(struct tm *);
  473. # endif
  474. # if TZ_TIME_T || !defined timelocal
  475. time_t timelocal(struct tm *);
  476. # endif
  477. # if TZ_TIME_T || !defined timeoff
  478. time_t timeoff(struct tm *, long);
  479. # endif
  480. # if TZ_TIME_T || !defined time2posix
  481. time_t time2posix(time_t);
  482. # endif
  483. # if TZ_TIME_T || !defined posix2time
  484. time_t posix2time(time_t);
  485. # endif
  486. #endif
  487. /* Infer TM_ZONE on systems where this information is known, but suppress
  488. guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
  489. #if (defined __GLIBC__ \
  490. || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
  491. || (defined __APPLE__ && defined __MACH__))
  492. # if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
  493. # define TM_GMTOFF tm_gmtoff
  494. # endif
  495. # if !defined TM_ZONE && !defined NO_TM_ZONE
  496. # define TM_ZONE tm_zone
  497. # endif
  498. #endif
  499. /*
  500. ** Define functions that are ABI compatible with NetBSD but have
  501. ** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t
  502. ** and labors under the misconception that 'const timezone_t' is a
  503. ** pointer to a constant. This use of 'const' is ineffective, so it
  504. ** is not done here. What we call 'struct state' NetBSD calls
  505. ** 'struct __state', but this is a private name so it doesn't matter.
  506. */
  507. #if NETBSD_INSPIRED
  508. typedef struct state *timezone_t;
  509. struct tm *localtime_rz(timezone_t restrict, time_t const *restrict,
  510. struct tm *restrict);
  511. time_t mktime_z(timezone_t restrict, struct tm *restrict);
  512. timezone_t tzalloc(char const *);
  513. void tzfree(timezone_t);
  514. # ifdef STD_INSPIRED
  515. # if TZ_TIME_T || !defined posix2time_z
  516. time_t posix2time_z(timezone_t, time_t) ATTRIBUTE_PURE;
  517. # endif
  518. # if TZ_TIME_T || !defined time2posix_z
  519. time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE;
  520. # endif
  521. # endif
  522. #endif
  523. /*
  524. ** Finally, some convenience items.
  525. */
  526. #if HAVE_STDBOOL_H
  527. # include <stdbool.h>
  528. #else
  529. # define true 1
  530. # define false 0
  531. # define bool int
  532. #endif
  533. #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
  534. #define TYPE_SIGNED(type) (((type) -1) < 0)
  535. #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
  536. /* Max and min values of the integer type T, of which only the bottom
  537. B bits are used, and where the highest-order used bit is considered
  538. to be a sign bit if T is signed. */
  539. #define MAXVAL(t, b) \
  540. ((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
  541. - 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
  542. #define MINVAL(t, b) \
  543. ((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
  544. /* The extreme time values, assuming no padding. */
  545. #define TIME_T_MIN_NO_PADDING MINVAL(time_t, TYPE_BIT(time_t))
  546. #define TIME_T_MAX_NO_PADDING MAXVAL(time_t, TYPE_BIT(time_t))
  547. /* The extreme time values. These are macros, not constants, so that
  548. any portability problem occur only when compiling .c files that use
  549. the macros, which is safer for applications that need only zdump and zic.
  550. This implementation assumes no padding if time_t is signed and
  551. either the compiler lacks support for _Generic or time_t is not one
  552. of the standard signed integer types. */
  553. #if HAVE_GENERIC
  554. # define TIME_T_MIN \
  555. _Generic((time_t) 0, \
  556. signed char: SCHAR_MIN, short: SHRT_MIN, \
  557. int: INT_MIN, long: LONG_MIN, long long: LLONG_MIN, \
  558. default: TIME_T_MIN_NO_PADDING)
  559. # define TIME_T_MAX \
  560. (TYPE_SIGNED(time_t) \
  561. ? _Generic((time_t) 0, \
  562. signed char: SCHAR_MAX, short: SHRT_MAX, \
  563. int: INT_MAX, long: LONG_MAX, long long: LLONG_MAX, \
  564. default: TIME_T_MAX_NO_PADDING) \
  565. : (time_t) -1)
  566. #else
  567. # define TIME_T_MIN TIME_T_MIN_NO_PADDING
  568. # define TIME_T_MAX TIME_T_MAX_NO_PADDING
  569. #endif
  570. /*
  571. ** 302 / 1000 is log10(2.0) rounded up.
  572. ** Subtract one for the sign bit if the type is signed;
  573. ** add one for integer division truncation;
  574. ** add one more for a minus sign if the type is signed.
  575. */
  576. #define INT_STRLEN_MAXIMUM(type) \
  577. ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
  578. 1 + TYPE_SIGNED(type))
  579. /*
  580. ** INITIALIZE(x)
  581. */
  582. #ifdef GCC_LINT
  583. # define INITIALIZE(x) ((x) = 0)
  584. #else
  585. # define INITIALIZE(x)
  586. #endif
  587. #ifndef UNINIT_TRAP
  588. # define UNINIT_TRAP 0
  589. #endif
  590. /*
  591. ** For the benefit of GNU folk...
  592. ** '_(MSGID)' uses the current locale's message library string for MSGID.
  593. ** The default is to use gettext if available, and use MSGID otherwise.
  594. */
  595. #if HAVE_GETTEXT
  596. #define _(msgid) gettext(msgid)
  597. #else /* !HAVE_GETTEXT */
  598. #define _(msgid) msgid
  599. #endif /* !HAVE_GETTEXT */
  600. #if !defined TZ_DOMAIN && defined HAVE_GETTEXT
  601. # define TZ_DOMAIN "tz"
  602. #endif
  603. #if HAVE_INCOMPATIBLE_CTIME_R
  604. #undef asctime_r
  605. #undef ctime_r
  606. char *asctime_r(struct tm const *, char *);
  607. char *ctime_r(time_t const *, char *);
  608. #endif /* HAVE_INCOMPATIBLE_CTIME_R */
  609. /* Handy macros that are independent of tzfile implementation. */
  610. #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
  611. #define SECSPERMIN 60
  612. #define MINSPERHOUR 60
  613. #define HOURSPERDAY 24
  614. #define DAYSPERWEEK 7
  615. #define DAYSPERNYEAR 365
  616. #define DAYSPERLYEAR 366
  617. #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
  618. #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
  619. #define MONSPERYEAR 12
  620. #define TM_SUNDAY 0
  621. #define TM_MONDAY 1
  622. #define TM_TUESDAY 2
  623. #define TM_WEDNESDAY 3
  624. #define TM_THURSDAY 4
  625. #define TM_FRIDAY 5
  626. #define TM_SATURDAY 6
  627. #define TM_JANUARY 0
  628. #define TM_FEBRUARY 1
  629. #define TM_MARCH 2
  630. #define TM_APRIL 3
  631. #define TM_MAY 4
  632. #define TM_JUNE 5
  633. #define TM_JULY 6
  634. #define TM_AUGUST 7
  635. #define TM_SEPTEMBER 8
  636. #define TM_OCTOBER 9
  637. #define TM_NOVEMBER 10
  638. #define TM_DECEMBER 11
  639. #define TM_YEAR_BASE 1900
  640. #define EPOCH_YEAR 1970
  641. #define EPOCH_WDAY TM_THURSDAY
  642. #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
  643. /*
  644. ** Since everything in isleap is modulo 400 (or a factor of 400), we know that
  645. ** isleap(y) == isleap(y % 400)
  646. ** and so
  647. ** isleap(a + b) == isleap((a + b) % 400)
  648. ** or
  649. ** isleap(a + b) == isleap(a % 400 + b % 400)
  650. ** This is true even if % means modulo rather than Fortran remainder
  651. ** (which is allowed by C89 but not by C99 or later).
  652. ** We use this to avoid addition overflow problems.
  653. */
  654. #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
  655. /*
  656. ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
  657. */
  658. #define AVGSECSPERYEAR 31556952L
  659. #define SECSPERREPEAT \
  660. ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
  661. #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
  662. #endif /* !defined PRIVATE_H */