private.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #ifndef PRIVATE_H
  2. #define PRIVATE_H
  3. /*
  4. ** This file is in the public domain, so clarified as of
  5. ** 1996-06-05 by Arthur David Olson.
  6. */
  7. /*
  8. ** This header is for use ONLY with the time conversion code.
  9. ** There is no guarantee that it will remain unchanged,
  10. ** or that it will remain at all.
  11. ** Do NOT copy it to any system include directory.
  12. ** Thank you!
  13. */
  14. /*
  15. ** ID
  16. */
  17. #ifndef lint
  18. #ifndef NOID
  19. static char __attribute__((unused)) privatehid[] = "@(#)private.h 8.3";
  20. #endif /* !defined NOID */
  21. #endif /* !defined lint */
  22. #define GRANDPARENTED "Local time zone must be set--see zic manual page"
  23. /*
  24. ** Defaults for preprocessor symbols.
  25. ** You can override these in your C compiler options, e.g. `-DHAVE_ADJTIME=0'.
  26. */
  27. #ifndef HAVE_ADJTIME
  28. #define HAVE_ADJTIME 1
  29. #endif /* !defined HAVE_ADJTIME */
  30. #ifndef HAVE_GETTEXT
  31. #define HAVE_GETTEXT 0
  32. #endif /* !defined HAVE_GETTEXT */
  33. #ifndef HAVE_INCOMPATIBLE_CTIME_R
  34. #define HAVE_INCOMPATIBLE_CTIME_R 0
  35. #endif /* !defined INCOMPATIBLE_CTIME_R */
  36. #ifndef HAVE_SETTIMEOFDAY
  37. #define HAVE_SETTIMEOFDAY 3
  38. #endif /* !defined HAVE_SETTIMEOFDAY */
  39. #ifndef HAVE_STRERROR
  40. #define HAVE_STRERROR 1
  41. #endif /* !defined HAVE_STRERROR */
  42. #ifndef HAVE_SYMLINK
  43. #define HAVE_SYMLINK 1
  44. #endif /* !defined HAVE_SYMLINK */
  45. #ifndef HAVE_SYS_STAT_H
  46. #define HAVE_SYS_STAT_H 1
  47. #endif /* !defined HAVE_SYS_STAT_H */
  48. #ifndef HAVE_SYS_WAIT_H
  49. #define HAVE_SYS_WAIT_H 1
  50. #endif /* !defined HAVE_SYS_WAIT_H */
  51. #ifndef HAVE_UNISTD_H
  52. #define HAVE_UNISTD_H 1
  53. #endif /* !defined HAVE_UNISTD_H */
  54. #ifndef HAVE_UTMPX_H
  55. #define HAVE_UTMPX_H 0
  56. #endif /* !defined HAVE_UTMPX_H */
  57. #ifndef LOCALE_HOME
  58. #define LOCALE_HOME "/usr/lib/locale"
  59. #endif /* !defined LOCALE_HOME */
  60. #if HAVE_INCOMPATIBLE_CTIME_R
  61. #define asctime_r _incompatible_asctime_r
  62. #define ctime_r _incompatible_ctime_r
  63. #endif /* HAVE_INCOMPATIBLE_CTIME_R */
  64. /*
  65. ** Nested includes
  66. */
  67. #include "sys/types.h" /* for time_t */
  68. #include "stdio.h"
  69. #include "errno.h"
  70. #include "string.h"
  71. #include "limits.h" /* for CHAR_BIT et al. */
  72. #include "time.h"
  73. #include "stdlib.h"
  74. #if HAVE_GETTEXT
  75. #include "libintl.h"
  76. #endif /* HAVE_GETTEXT */
  77. #if HAVE_SYS_WAIT_H
  78. #include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
  79. #endif /* HAVE_SYS_WAIT_H */
  80. #ifndef WIFEXITED
  81. #define WIFEXITED(status) (((status) & 0xff) == 0)
  82. #endif /* !defined WIFEXITED */
  83. #ifndef WEXITSTATUS
  84. #define WEXITSTATUS(status) (((status) >> 8) & 0xff)
  85. #endif /* !defined WEXITSTATUS */
  86. #if HAVE_UNISTD_H
  87. #include "unistd.h" /* for F_OK and R_OK */
  88. #endif /* HAVE_UNISTD_H */
  89. #if !HAVE_UNISTD_H
  90. #ifndef F_OK
  91. #define F_OK 0
  92. #endif /* !defined F_OK */
  93. #ifndef R_OK
  94. #define R_OK 4
  95. #endif /* !defined R_OK */
  96. #endif /* !HAVE_UNISTD_H */
  97. /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
  98. #define is_digit(c) ((unsigned)(c) - '0' <= 9)
  99. /*
  100. ** Define HAVE_STDINT_H's default value here, rather than at the
  101. ** start, since __GLIBC__'s value depends on previously-included
  102. ** files.
  103. ** (glibc 2.1 and later have stdint.h, even with pre-C99 compilers.)
  104. */
  105. #ifndef HAVE_STDINT_H
  106. #define HAVE_STDINT_H \
  107. (199901 <= __STDC_VERSION__ || \
  108. 2 < (__GLIBC__ + (0 < __GLIBC_MINOR__)))
  109. #endif /* !defined HAVE_STDINT_H */
  110. #if HAVE_STDINT_H
  111. #include "stdint.h"
  112. #endif /* !HAVE_STDINT_H */
  113. #ifndef INT_FAST64_MAX
  114. /* Pre-C99 GCC compilers define __LONG_LONG_MAX__ instead of LLONG_MAX. */
  115. #if defined LLONG_MAX || defined __LONG_LONG_MAX__
  116. typedef long long int_fast64_t;
  117. #else /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
  118. #if (LONG_MAX >> 31) < 0xffffffff
  119. Please use a compiler that supports a 64-bit integer type (or wider);
  120. you may need to compile with "-DHAVE_STDINT_H".
  121. #endif /* (LONG_MAX >> 31) < 0xffffffff */
  122. typedef long int_fast64_t;
  123. #endif /* ! (defined LLONG_MAX || defined __LONG_LONG_MAX__) */
  124. #endif /* !defined INT_FAST64_MAX */
  125. #ifndef INT32_MAX
  126. #define INT32_MAX 0x7fffffff
  127. #endif /* !defined INT32_MAX */
  128. #ifndef INT32_MIN
  129. #define INT32_MIN (-1 - INT32_MAX)
  130. #endif /* !defined INT32_MIN */
  131. /*
  132. ** Workarounds for compilers/systems.
  133. */
  134. /*
  135. ** If your compiler lacks prototypes, "#define P(x) ()".
  136. */
  137. #ifndef P
  138. #define P(x) x
  139. #endif /* !defined P */
  140. /*
  141. ** SunOS 4.1.1 headers lack EXIT_SUCCESS.
  142. */
  143. #ifndef EXIT_SUCCESS
  144. #define EXIT_SUCCESS 0
  145. #endif /* !defined EXIT_SUCCESS */
  146. /*
  147. ** SunOS 4.1.1 headers lack EXIT_FAILURE.
  148. */
  149. #ifndef EXIT_FAILURE
  150. #define EXIT_FAILURE 1
  151. #endif /* !defined EXIT_FAILURE */
  152. /*
  153. ** SunOS 4.1.1 headers lack FILENAME_MAX.
  154. */
  155. #ifndef FILENAME_MAX
  156. #ifndef MAXPATHLEN
  157. #ifdef unix
  158. #include "sys/param.h"
  159. #endif /* defined unix */
  160. #endif /* !defined MAXPATHLEN */
  161. #ifdef MAXPATHLEN
  162. #define FILENAME_MAX MAXPATHLEN
  163. #endif /* defined MAXPATHLEN */
  164. #ifndef MAXPATHLEN
  165. #define FILENAME_MAX 1024 /* Pure guesswork */
  166. #endif /* !defined MAXPATHLEN */
  167. #endif /* !defined FILENAME_MAX */
  168. /*
  169. ** SunOS 4.1.1 libraries lack remove.
  170. */
  171. #ifndef remove
  172. extern int unlink P((const char * filename));
  173. #define remove unlink
  174. #endif /* !defined remove */
  175. /*
  176. ** Some ancient errno.h implementations don't declare errno.
  177. ** But some newer errno.h implementations define it as a macro.
  178. ** Fix the former without affecting the latter.
  179. */
  180. #ifndef errno
  181. extern int errno;
  182. #endif /* !defined errno */
  183. /*
  184. ** Private function declarations.
  185. */
  186. char * icalloc P((int nelem, int elsize));
  187. char * icatalloc P((char * old, const char * new));
  188. char * icpyalloc P((const char * string));
  189. char * imalloc P((int n));
  190. void * irealloc P((void * pointer, int size));
  191. void icfree P((char * pointer));
  192. void ifree P((char * pointer));
  193. const char * scheck P((const char * string, const char * format));
  194. /*
  195. ** Finally, some convenience items.
  196. */
  197. #ifndef TRUE
  198. #define TRUE 1
  199. #endif /* !defined TRUE */
  200. #ifndef FALSE
  201. #define FALSE 0
  202. #endif /* !defined FALSE */
  203. #ifndef TYPE_BIT
  204. #define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
  205. #endif /* !defined TYPE_BIT */
  206. #ifndef TYPE_SIGNED
  207. #define TYPE_SIGNED(type) (((type) -1) < 0)
  208. #endif /* !defined TYPE_SIGNED */
  209. /*
  210. ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
  211. ** it cannot be used in preprocessor directives.
  212. */
  213. #ifndef TYPE_INTEGRAL
  214. #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
  215. #endif /* !defined TYPE_INTEGRAL */
  216. #ifndef INT_STRLEN_MAXIMUM
  217. /*
  218. ** 302 / 1000 is log10(2.0) rounded up.
  219. ** Subtract one for the sign bit if the type is signed;
  220. ** add one for integer division truncation;
  221. ** add one more for a minus sign if the type is signed.
  222. */
  223. #define INT_STRLEN_MAXIMUM(type) \
  224. ((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
  225. 1 + TYPE_SIGNED(type))
  226. #endif /* !defined INT_STRLEN_MAXIMUM */
  227. /*
  228. ** INITIALIZE(x)
  229. */
  230. #ifndef GNUC_or_lint
  231. #ifdef lint
  232. #define GNUC_or_lint
  233. #endif /* defined lint */
  234. #ifndef lint
  235. #ifdef __GNUC__
  236. #define GNUC_or_lint
  237. #endif /* defined __GNUC__ */
  238. #endif /* !defined lint */
  239. #endif /* !defined GNUC_or_lint */
  240. #ifndef INITIALIZE
  241. #ifdef GNUC_or_lint
  242. #define INITIALIZE(x) ((x) = 0)
  243. #endif /* defined GNUC_or_lint */
  244. #ifndef GNUC_or_lint
  245. #define INITIALIZE(x)
  246. #endif /* !defined GNUC_or_lint */
  247. #endif /* !defined INITIALIZE */
  248. /*
  249. ** For the benefit of GNU folk...
  250. ** `_(MSGID)' uses the current locale's message library string for MSGID.
  251. ** The default is to use gettext if available, and use MSGID otherwise.
  252. */
  253. #ifndef _
  254. #if HAVE_GETTEXT
  255. #define _(msgid) gettext(msgid)
  256. #else /* !HAVE_GETTEXT */
  257. #define _(msgid) msgid
  258. #endif /* !HAVE_GETTEXT */
  259. #endif /* !defined _ */
  260. #ifndef TZ_DOMAIN
  261. #define TZ_DOMAIN "tz"
  262. #endif /* !defined TZ_DOMAIN */
  263. #if HAVE_INCOMPATIBLE_CTIME_R
  264. #undef asctime_r
  265. #undef ctime_r
  266. char *asctime_r P((struct tm const *, char *));
  267. char *ctime_r P((time_t const *, char *));
  268. #endif /* HAVE_INCOMPATIBLE_CTIME_R */
  269. #ifndef YEARSPERREPEAT
  270. #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */
  271. #endif /* !defined YEARSPERREPEAT */
  272. /*
  273. ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
  274. */
  275. #ifndef AVGSECSPERYEAR
  276. #define AVGSECSPERYEAR 31556952L
  277. #endif /* !defined AVGSECSPERYEAR */
  278. #ifndef SECSPERREPEAT
  279. #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
  280. #endif /* !defined SECSPERREPEAT */
  281. #ifndef SECSPERREPEAT_BITS
  282. #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */
  283. #endif /* !defined SECSPERREPEAT_BITS */
  284. /*
  285. ** UNIX was a registered trademark of The Open Group in 2003.
  286. */
  287. #endif /* !defined PRIVATE_H */