xref: /dragonfly/lib/libc/stdtime/private.h (revision e65bc1c3)
1 /*
2  * $FreeBSD: src/lib/libc/stdtime/private.h,v 1.6.8.1 2000/08/23 00:19:15 jhb Exp $
3  */
4 
5 #ifndef PRIVATE_H
6 
7 #define PRIVATE_H
8 /*
9 ** This file is in the public domain, so clarified as of
10 ** 1996-06-05 by Arthur David Olson.
11 */
12 
13 /* Stuff moved from Makefile.inc to reduce clutter */
14 #ifndef TM_GMTOFF
15 #define TM_GMTOFF	tm_gmtoff
16 #define TM_ZONE		tm_zone
17 #define TZDIR		"/usr/share/zoneinfo"
18 #endif /* ndef TM_GMTOFF */
19 
20 /*
21 ** This header is for use ONLY with the time conversion code.
22 ** There is no guarantee that it will remain unchanged,
23 ** or that it will remain at all.
24 ** Do NOT copy it to any system include directory.
25 ** Thank you!
26 */
27 
28 #define GRANDPARENTED	"Local time zone must be set--see zic manual page"
29 
30 /*
31 ** Nested includes
32 */
33 
34 #include "sys/types.h"	/* for time_t */
35 #include "stdio.h"
36 #include "errno.h"
37 #include "string.h"
38 #include "limits.h"	/* for CHAR_BIT et al. */
39 #include "time.h"
40 #include "stdlib.h"
41 
42 #include <sys/wait.h>	/* for WIFEXITED and WEXITSTATUS */
43 
44 #include "unistd.h"	/* for F_OK, R_OK, and other POSIX goodness */
45 
46 /* Unlike <ctype.h>'s isdigit, this also works if c < 0 | c > UCHAR_MAX. */
47 #define is_digit(c) ((unsigned)(c) - '0' <= 9)
48 
49 #include "stdint.h"
50 
51 /*
52 ** Private function declarations.
53 */
54 
55 char *		icalloc(int nelem, int elsize);
56 char *		icatalloc(char * old, const char * new);
57 char *		icpyalloc(const char * string);
58 char *		imalloc(int n);
59 void *		irealloc(void * pointer, int size);
60 void		icfree(char * pointer);
61 void		ifree(char * pointer);
62 const char *	scheck(const char * string, const char * format);
63 
64 /*
65 ** Finally, some convenience items.
66 */
67 
68 #ifndef TRUE
69 #define TRUE	1
70 #endif /* !defined TRUE */
71 
72 #ifndef FALSE
73 #define FALSE	0
74 #endif /* !defined FALSE */
75 
76 #ifndef TYPE_BIT
77 #define TYPE_BIT(type)	(sizeof (type) * CHAR_BIT)
78 #endif /* !defined TYPE_BIT */
79 
80 #ifndef TYPE_SIGNED
81 #define TYPE_SIGNED(type) (((type) -1) < 0)
82 #endif /* !defined TYPE_SIGNED */
83 
84 /*
85 ** Since the definition of TYPE_INTEGRAL contains floating point numbers,
86 ** it cannot be used in preprocessor directives.
87 */
88 
89 #ifndef TYPE_INTEGRAL
90 #define TYPE_INTEGRAL(type) (((type) 0.5) != 0.5)
91 #endif /* !defined TYPE_INTEGRAL */
92 
93 #ifndef INT_STRLEN_MAXIMUM
94 /*
95 ** 302 / 1000 is log10(2.0) rounded up.
96 ** Subtract one for the sign bit if the type is signed;
97 ** add one for integer division truncation;
98 ** add one more for a minus sign if the type is signed.
99 */
100 #define INT_STRLEN_MAXIMUM(type) \
101 	((TYPE_BIT(type) - TYPE_SIGNED(type)) * 302 / 1000 + \
102 	1 + TYPE_SIGNED(type))
103 #endif /* !defined INT_STRLEN_MAXIMUM */
104 
105 /*
106 ** INITIALIZE(x)
107 */
108 
109 #ifndef GNUC_or_lint
110 #ifdef lint
111 #define GNUC_or_lint
112 #endif /* defined lint */
113 #ifndef lint
114 #ifdef __GNUC__
115 #define GNUC_or_lint
116 #endif /* defined __GNUC__ */
117 #endif /* !defined lint */
118 #endif /* !defined GNUC_or_lint */
119 
120 #ifndef INITIALIZE
121 #ifdef GNUC_or_lint
122 #define INITIALIZE(x)	((x) = 0)
123 #endif /* defined GNUC_or_lint */
124 #ifndef GNUC_or_lint
125 #define INITIALIZE(x)
126 #endif /* !defined GNUC_or_lint */
127 #endif /* !defined INITIALIZE */
128 
129 /*
130 ** For the benefit of GNU folk...
131 ** `_(MSGID)' uses the current locale's message library string for MSGID.
132 ** The default is to use gettext if available, and use MSGID otherwise.
133 */
134 
135 #ifndef _
136 #define _(msgid) msgid
137 #endif /* !defined _ */
138 
139 #ifndef TZ_DOMAIN
140 #define TZ_DOMAIN "tz"
141 #endif /* !defined TZ_DOMAIN */
142 
143 #define YEARSPERREPEAT		400	/* years before a Gregorian repeat */
144 
145 /*
146 ** The Gregorian year averages 365.2425 days, which is 31556952 seconds.
147 */
148 
149 #define AVGSECSPERYEAR		31556952L
150 #define SECSPERREPEAT		((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR)
151 #define SECSPERREPEAT_BITS	34	/* ceil(log2(SECSPERREPEAT)) */
152 
153 /*
154 ** UNIX was a registered trademark of The Open Group in 2003.
155 */
156 
157 #endif /* !defined PRIVATE_H */
158