xref: /titanic_44/usr/src/lib/libast/common/features/limits.c (revision c39526b769298791ff5b0b6c5e761f49aabaeb4e)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Research
26  *
27  * generate limits features
28  *
29  *	FOPEN_MAX	POSIX says ANSI defines it but it's not in ANSI
30  *
31  * NOTE: two's complement binary integral representation assumed
32  */
33 
34 #if defined(__STDPP__directive) && defined(__STDPP__hide)
35 __STDPP__directive pragma pp:hide getpagesize getdtablesize
36 #else
37 #define getpagesize	______getpagesize
38 #define getdtablesize	______getdtablesize
39 #endif
40 
41 /*
42  * we'd like as many symbols as possible defined
43  * the standards push the vendors the other way
44  * but don't provide guard that lets everything through
45  * so each vendor adds their own guard
46  * many now include something like <standards.h> to
47  * get it straight in one place -- <sys/types.h> should
48  * kick that in
49  */
50 
51 #include "FEATURE/standards"
52 #include "FEATURE/lib"
53 
54 #ifdef __sun
55 #define _timespec	timespec
56 #endif
57 
58 #include <sys/types.h>
59 
60 #undef	_SGIAPI
61 #define _SGIAPI		1
62 
63 #if _hdr_limits
64 #include <limits.h>
65 #endif
66 
67 #undef	_SGIAPI
68 #define _SGIAPI		0
69 
70 #include "FEATURE/lib"
71 #include "FEATURE/common"
72 
73 #if _hdr_unistd
74 #include <unistd.h>
75 #endif
76 
77 #include "FEATURE/param"
78 
79 #if defined(__STDPP__directive) && defined(__STDPP__hide)
80 __STDPP__directive pragma pp:nohide getpagesize getdtablesize
81 #else
82 #undef	getpagesize
83 #undef	getdtablesize
84 #endif
85 
86 int main()
87 {
88 	char			c;
89 	unsigned char		uc;
90 	unsigned short		us;
91 	unsigned int		ui;
92 	unsigned long		ul;
93 	unsigned long		val;
94 #if _typ_uint64_t
95 	uint64_t		ull;
96 	uint64_t		vll;
97 #endif
98 
99 	/*
100 	 * <limits.h> with *constant* valued macros
101 	 */
102 
103 	printf("\n");
104 #ifndef CHAR_BIT
105 	uc = 0;
106 	uc = ~uc;
107 	val = 1;
108 	while (uc >>= 1) val++;
109 	printf("#define CHAR_BIT	%lu\n", val);
110 #endif
111 #ifndef MB_LEN_MAX
112 	val = 1;
113 	printf("#define MB_LEN_MAX	%lu\n", val);
114 #endif
115 
116 	c = 0;
117 	c = ~c;
118 	uc = 0;
119 	uc = ~uc;
120 	us = 0;
121 	us = ~us;
122 	ui = 0;
123 	ui = ~ui;
124 	ul = 0;
125 	ul = ~ul;
126 #if _typ_uint64_t
127 	ull = 0;
128 	ull = ~ull;
129 #endif
130 
131 #ifndef UCHAR_MAX
132 	val = uc;
133 	printf("#if defined(__STDC__)\n");
134 	printf("#define UCHAR_MAX	%luU\n", val);
135 	printf("#else\n");
136 	printf("#define UCHAR_MAX	%lu\n", val);
137 	printf("#endif\n");
138 #endif
139 
140 #ifndef SCHAR_MIN
141 	val = (unsigned char)(uc >> 1) + 1;
142 	printf("#define SCHAR_MIN	(-%lu)\n", val);
143 #endif
144 
145 #ifndef SCHAR_MAX
146 	val = (unsigned char)(uc >> 1);
147 	printf("#define SCHAR_MAX	%lu\n", val);
148 #endif
149 
150 	if (c < 0)
151 	{
152 #ifndef CHAR_MIN
153 		printf("#define CHAR_MIN	SCHAR_MIN\n");
154 #endif
155 
156 #ifndef CHAR_MAX
157 		printf("#define CHAR_MAX	SCHAR_MAX\n");
158 #endif
159 	}
160 	else
161 	{
162 #ifndef CHAR_MIN
163 		printf("#define CHAR_MIN	0\n");
164 #endif
165 
166 #ifndef CHAR_MAX
167 		printf("#define CHAR_MAX	UCHAR_MAX\n");
168 #endif
169 	}
170 
171 #ifndef USHRT_MAX
172 	val = us;
173 	printf("#if defined(__STDC__)\n");
174 	printf("#define USHRT_MAX	%luU\n", val);
175 	printf("#else\n");
176 	printf("#define USHRT_MAX	%lu\n", val);
177 	printf("#endif\n");
178 #endif
179 
180 #ifndef SHRT_MIN
181 	val = (unsigned short)(us >> 1) + 1;
182 	printf("#define SHRT_MIN	(-%lu)\n", val);
183 #endif
184 
185 #ifndef SHRT_MAX
186 	val = (unsigned short)(us >> 1);
187 	printf("#define SHRT_MAX	%lu\n", val);
188 #endif
189 
190 	if (ui == us)
191 	{
192 #ifndef UINT_MAX
193 		printf("#define UINT_MAX	USHRT_MAX\n");
194 #endif
195 
196 #ifndef INT_MIN
197 		printf("#define INT_MIN		SHRT_MIN\n");
198 #endif
199 
200 #ifndef INT_MAX
201 		printf("#define INT_MAX		SHRT_MAX\n");
202 #endif
203 	}
204 	else
205 	{
206 #ifndef UINT_MAX
207 		val = ui;
208 		printf("#if defined(__STDC__)\n");
209 		printf("#define UINT_MAX	%luU\n", val);
210 		printf("#else\n");
211 		printf("#define UINT_MAX	%lu\n", val);
212 		printf("#endif\n");
213 #endif
214 
215 #ifndef INT_MIN
216 		val = (unsigned int)(ui >> 1) + 1;
217 		if (ui == ul) printf("#define INT_MIN		(-%lu-1)\n", val - 1);
218 		else printf("#define INT_MIN		(-%lu)\n", val);
219 #endif
220 
221 #ifndef INT_MAX
222 		val = (unsigned int)(ui >> 1);
223 		printf("#define INT_MAX		%lu\n", val);
224 #endif
225 	}
226 
227 	if (ul == ui)
228 	{
229 #ifndef ULONG_MAX
230 		printf("#define ULONG_MAX	UINT_MAX\n");
231 #endif
232 
233 #ifndef LONG_MIN
234 		printf("#define LONG_MIN	INT_MIN\n");
235 #endif
236 
237 #ifndef LONG_MAX
238 		printf("#define LONG_MAX	INT_MAX\n");
239 #endif
240 	}
241 	else
242 	{
243 #ifndef ULONG_MAX
244 		val = ul;
245 		printf("#if defined(__STDC__)\n");
246 		printf("#define ULONG_MAX	%luLU\n", val);
247 		printf("#else\n");
248 		printf("#define ULONG_MAX	%lu\n", val);
249 		printf("#endif\n");
250 #endif
251 
252 #ifndef LONG_MIN
253 		val = (unsigned long)(ul >> 1) + 1;
254 		printf("#define LONG_MIN	(-%luL-1L)\n", val - 1);
255 #endif
256 
257 #ifndef LONG_MAX
258 		val = (unsigned long)(ul >> 1);
259 		printf("#define LONG_MAX	%luL\n", val);
260 #endif
261 	}
262 
263 #if _typ_uint64_t && !_ast_intmax_long
264 	if (ull == ul)
265 	{
266 #ifndef ULLONG_MAX
267 		printf("#define ULLONG_MAX	ULONG_MAX\n");
268 #endif
269 
270 #ifndef LLONG_MIN
271 		printf("#define LLONG_MIN	LONG_MIN\n");
272 #endif
273 
274 #ifndef LLONG_MAX
275 		printf("#define LLONG_MAX	LONG_MAX\n");
276 #endif
277 	}
278 	else
279 	{
280 #ifndef ULLONG_MAX
281 		vll = ull;
282 		printf("#ifndef ULLONG_MAX\n");
283 		printf("#if defined(__STDC__) && _ast_LL\n");
284 		printf("#define ULLONG_MAX	%lluULL\n", vll);
285 		printf("#else\n");
286 		printf("#define ULLONG_MAX	%llu\n", vll);
287 		printf("#endif\n");
288 		printf("#endif\n");
289 #endif
290 
291 #ifndef LLONG_MIN
292 		vll = (uint64_t)(ull >> 1) + 1;
293 		printf("#ifndef LLONG_MIN\n");
294 		printf("#if defined(__STDC__) && _ast_LL\n");
295 		printf("#define LLONG_MIN	(-%lluLL-1LL)\n", vll - 1);
296 		printf("#else\n");
297 		printf("#define LLONG_MIN	(-%llu-1)\n", vll - 1);
298 		printf("#endif\n");
299 		printf("#endif\n");
300 #endif
301 
302 #ifndef LLONG_MAX
303 		vll = (uint64_t)(ull >> 1);
304 		printf("#ifndef LLONG_MAX\n");
305 		printf("#if defined(__STDC__) && _ast_LL\n");
306 		printf("#define LLONG_MAX	%lluLL\n", vll);
307 		printf("#else\n");
308 		printf("#define LLONG_MAX	%llu\n", vll);
309 		printf("#endif\n");
310 		printf("#endif\n");
311 #endif
312 	}
313 #endif
314 
315 	printf("\n");
316 #ifdef _UWIN
317 	printf("#ifdef _UWIN\n");
318 	printf("#ifndef DBL_DIG\n");
319 	printf("#define DBL_DIG		15\n");
320 	printf("#endif\n");
321 	printf("#ifndef DBL_MAX\n");
322 	printf("#define DBL_MAX		1.7976931348623158e+308\n");
323 	printf("#endif\n");
324 	printf("#ifndef FLT_DIG\n");
325 	printf("#define FLT_DIG		6\n");
326 	printf("#endif\n");
327 	printf("#ifndef FLT_MAX\n");
328 	printf("#define FLT_MAX		3.402823466e+38F\n");
329 	printf("#endif\n");
330 	printf("#endif\n");
331 	printf("\n");
332 #endif
333 
334 #include "conflim.h"
335 
336 	printf("\n");
337 
338 	return 0;
339 }
340