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