2 * Copyright (c) 1997-2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2010 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 #define BITSIZE(TYPE) \
52 int b = 0; TYPE x = 1, zero = 0; const char *pre = "u"; \
54 while(x){ x <<= 1; b++; if(x < zero) pre=""; } \
57 snprintf(tmp, sizeof(tmp), "typedef %s %sint%d_t;", #TYPE, \
59 tabs = 5 - strlen(tmp) / 8; \
60 fprintf(f, "%s", tmp); \
61 while(tabs-- > 0) fprintf(f, "\t"); \
62 fprintf(f, "/* %2d bits */\n", b); \
67 #define BITSIZE(TYPE) \
69 int b = 0; TYPE x = 1, zero = 0; const char *pre = "u"; \
70 char tmp[128], tmp2[128]; \
71 while(x){ x <<= 1; b++; if(x < zero) pre=""; } \
74 sprintf(tmp, "%sint%d_t" , pre, len); \
75 sprintf(tmp2, "typedef %s %s;", #TYPE, tmp); \
76 tabs = 5 - strlen(tmp2) / 8; \
77 fprintf(f, "%s", tmp2); \
80 fprintf(f, "/* %2d bits */\n", b); \
85 #ifndef HAVE___ATTRIBUTE__
86 #define __attribute__(x)
90 try_signed(FILE *f
, int len
) __attribute__ ((__unused__
));
93 try_unsigned(FILE *f
, int len
) __attribute__ ((__unused__
));
96 print_bt(FILE *f
, int flag
) __attribute__ ((__unused__
));
99 try_signed(FILE *f
, int len
)
101 BITSIZE(signed char);
105 #ifdef HAVE_LONG_LONG
108 fprintf(f
, "/* There is no %d bit type */\n", len
);
112 try_unsigned(FILE *f
, int len
)
114 BITSIZE(unsigned char);
115 BITSIZE(unsigned short);
116 BITSIZE(unsigned int);
117 BITSIZE(unsigned long);
118 #ifdef HAVE_LONG_LONG
119 BITSIZE(unsigned long long);
121 fprintf(f
, "/* There is no %d bit type */\n", len
);
125 print_bt(FILE *f
, int flag
)
128 fprintf(f
, "/* For compatibility with various type definitions */\n");
129 fprintf(f
, "#ifndef __BIT_TYPES_DEFINED__\n");
130 fprintf(f
, "#define __BIT_TYPES_DEFINED__\n");
136 int main(int argc
, char **argv
)
143 if (argc
> 1 && strcmp(argv
[1], "--version") == 0) {
144 printf("some version");
152 p
= malloc(strlen(argv
[1]) + 5);
153 sprintf(p
, "__%s__", argv
[1]);
156 if(!isalnum((unsigned char)*p
))
159 f
= fopen(argv
[1], "w");
161 fprintf(f
, "#ifndef %s\n", hb
);
162 fprintf(f
, "#define %s\n", hb
);
164 #ifdef HAVE_INTTYPES_H
165 fprintf(f
, "#include <inttypes.h>\n");
167 #ifdef HAVE_SYS_TYPES_H
168 fprintf(f
, "#include <sys/types.h>\n");
170 #ifdef HAVE_SYS_BITYPES_H
171 fprintf(f
, "#include <sys/bitypes.h>\n");
173 #ifdef HAVE_BIND_BITYPES_H
174 fprintf(f
, "#include <bind/bitypes.h>\n");
176 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
177 fprintf(f
, "#include <netinet/in6_machtypes.h>\n");
179 #ifdef HAVE_SOCKLEN_T
181 fprintf(f
, "#include <sys/socket.h>\n");
183 fprintf(f
, "#include <winsock2.h>\n");
184 fprintf(f
, "#include <ws2tcpip.h>\n");
191 flag
= print_bt(f
, flag
);
193 #endif /* HAVE_INT8_T */
195 flag
= print_bt(f
, flag
);
197 #endif /* HAVE_INT16_T */
199 flag
= print_bt(f
, flag
);
201 #endif /* HAVE_INT32_T */
203 flag
= print_bt(f
, flag
);
205 #endif /* HAVE_INT64_T */
208 flag
= print_bt(f
, flag
);
210 #endif /* HAVE_UINT8_T */
211 #ifndef HAVE_UINT16_T
212 flag
= print_bt(f
, flag
);
213 try_unsigned (f
, 16);
214 #endif /* HAVE_UINT16_T */
215 #ifndef HAVE_UINT32_T
216 flag
= print_bt(f
, flag
);
217 try_unsigned (f
, 32);
218 #endif /* HAVE_UINT32_T */
219 #ifndef HAVE_UINT64_T
220 flag
= print_bt(f
, flag
);
221 try_unsigned (f
, 64);
222 #endif /* HAVE_UINT64_T */
224 #define X(S) fprintf(f, "typedef uint" #S "_t u_int" #S "_t;\n")
225 #ifndef HAVE_U_INT8_T
226 flag
= print_bt(f
, flag
);
228 #endif /* HAVE_U_INT8_T */
229 #ifndef HAVE_U_INT16_T
230 flag
= print_bt(f
, flag
);
232 #endif /* HAVE_U_INT16_T */
233 #ifndef HAVE_U_INT32_T
234 flag
= print_bt(f
, flag
);
236 #endif /* HAVE_U_INT32_T */
237 #ifndef HAVE_U_INT64_T
238 flag
= print_bt(f
, flag
);
240 #endif /* HAVE_U_INT64_T */
244 fprintf(f
, "#endif /* __BIT_TYPES_DEFINED__ */\n\n");
248 #if defined(HAVE_SOCKLEN_T)
249 fprintf(f
, "typedef socklen_t krb5_socklen_t;\n");
251 fprintf(f
, "typedef int krb5_socklen_t;\n");
253 #if defined(HAVE_SSIZE_T)
255 fprintf(f
, "#include <unistd.h>\n");
257 fprintf(f
, "typedef ssize_t krb5_ssize_t;\n");
259 fprintf(f
, "typedef int krb5_ssize_t;\n");
264 fprintf(f
, "typedef SOCKET krb5_socket_t;\n");
266 fprintf(f
, "typedef int krb5_socket_t;\n");
272 fprintf(f
, "#if !defined(__has_extension)\n");
273 fprintf(f
, "#define __has_extension(x) 0\n");
274 fprintf(f
, "#endif\n\n");
276 fprintf(f
, "#ifndef KRB5TYPES_REQUIRE_GNUC\n");
277 fprintf(f
, "#define KRB5TYPES_REQUIRE_GNUC(m,n,p) \\\n");
278 fprintf(f
, " (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) >= \\\n");
279 fprintf(f
, " (((m) * 10000) + ((n) * 100) + (p)))\n");
280 fprintf(f
, "#endif\n\n");
282 fprintf(f
, "#ifndef HEIMDAL_DEPRECATED\n");
283 fprintf(f
, "#if __has_extension(deprecated) || KRB5TYPES_REQUIRE_GNUC(3,1,0)\n");
284 fprintf(f
, "#define HEIMDAL_DEPRECATED __attribute__ ((__deprecated__))\n");
285 fprintf(f
, "#elif defined(_MSC_VER) && (_MSC_VER>1200)\n");
286 fprintf(f
, "#define HEIMDAL_DEPRECATED __declspec(deprecated)\n");
287 fprintf(f
, "#else\n");
288 fprintf(f
, "#define HEIMDAL_DEPRECATED\n");
289 fprintf(f
, "#endif\n");
290 fprintf(f
, "#endif\n\n");
292 fprintf(f
, "#ifndef HEIMDAL_PRINTF_ATTRIBUTE\n");
293 fprintf(f
, "#if __has_extension(format) || KRB5TYPES_REQUIRE_GNUC(3,1,0)\n");
294 fprintf(f
, "#define HEIMDAL_PRINTF_ATTRIBUTE(x) __attribute__ ((__format__ x))\n");
295 fprintf(f
, "#else\n");
296 fprintf(f
, "#define HEIMDAL_PRINTF_ATTRIBUTE(x)\n");
297 fprintf(f
, "#endif\n");
298 fprintf(f
, "#endif\n\n");
300 fprintf(f
, "#ifndef HEIMDAL_NORETURN_ATTRIBUTE\n");
301 fprintf(f
, "#if __has_extension(noreturn) || KRB5TYPES_REQUIRE_GNUC(3,1,0)\n");
302 fprintf(f
, "#define HEIMDAL_NORETURN_ATTRIBUTE __attribute__ ((__noreturn__))\n");
303 fprintf(f
, "#else\n");
304 fprintf(f
, "#define HEIMDAL_NORETURN_ATTRIBUTE\n");
305 fprintf(f
, "#endif\n");
306 fprintf(f
, "#endif\n\n");
308 fprintf(f
, "#ifndef HEIMDAL_UNUSED_ATTRIBUTE\n");
309 fprintf(f
, "#if __has_extension(unused) || KRB5TYPES_REQUIRE_GNUC(3,1,0)\n");
310 fprintf(f
, "#define HEIMDAL_UNUSED_ATTRIBUTE __attribute__ ((__unused__))\n");
311 fprintf(f
, "#else\n");
312 fprintf(f
, "#define HEIMDAL_UNUSED_ATTRIBUTE\n");
313 fprintf(f
, "#endif\n");
314 fprintf(f
, "#endif\n\n");
316 fprintf(f
, "#ifndef HEIMDAL_WARN_UNUSED_RESULT_ATTRIBUTE\n");
317 fprintf(f
, "#if __has_extension(warn_unused_result) || KRB5TYPES_REQUIRE_GNUC(3,3,0)\n");
318 fprintf(f
, "#define HEIMDAL_WARN_UNUSED_RESULT_ATTRIBUTE __attribute__ ((__warn_unused_result__))\n");
319 fprintf(f
, "#else\n");
320 fprintf(f
, "#define HEIMDAL_WARN_UNUSED_RESULT_ATTRIBUTE\n");
321 fprintf(f
, "#endif\n");
322 fprintf(f
, "#endif\n\n");
324 fprintf(f
, "#endif /* %s */\n", hb
);