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
49 #define BITSIZE(TYPE) \
51 int b = 0; TYPE x = 1, zero = 0; const char *pre = "u"; \
52 char tmp[128], tmp2[128]; \
53 while(x){ x <<= 1; b++; if(x < zero) pre=""; } \
56 sprintf(tmp, "%sint%d_t" , pre, len); \
57 sprintf(tmp2, "typedef %s %s;", #TYPE, tmp); \
58 tabs = 5 - strlen(tmp2) / 8; \
59 fprintf(f, "%s", tmp2); \
60 while(tabs-- > 0) fprintf(f, "\t"); \
61 fprintf(f, "/* %2d bits */\n", b); \
66 #ifndef HAVE___ATTRIBUTE__
67 #define __attribute__(x)
71 try_signed(FILE *f
, int len
) __attribute__ ((__unused__
));
74 try_unsigned(FILE *f
, int len
) __attribute__ ((__unused__
));
77 print_bt(FILE *f
, int flag
) __attribute__ ((__unused__
));
80 try_signed(FILE *f
, int len
)
89 fprintf(f
, "/* There is no %d bit type */\n", len
);
93 try_unsigned(FILE *f
, int len
)
95 BITSIZE(unsigned char);
96 BITSIZE(unsigned short);
97 BITSIZE(unsigned int);
98 BITSIZE(unsigned long);
100 BITSIZE(unsigned long long);
102 fprintf(f
, "/* There is no %d bit type */\n", len
);
106 print_bt(FILE *f
, int flag
)
109 fprintf(f
, "/* For compatibility with various type definitions */\n");
110 fprintf(f
, "#ifndef __BIT_TYPES_DEFINED__\n");
111 fprintf(f
, "#define __BIT_TYPES_DEFINED__\n");
117 int main(int argc
, char **argv
)
124 if (argc
> 1 && strcmp(argv
[1], "--version") == 0) {
125 printf("some version");
133 p
= malloc(strlen(argv
[1]) + 5);
134 sprintf(p
, "__%s__", argv
[1]);
137 if(!isalnum((unsigned char)*p
))
140 f
= fopen(argv
[1], "w");
142 fprintf(f
, "#ifndef %s\n", hb
);
143 fprintf(f
, "#define %s\n", hb
);
145 #ifdef HAVE_INTTYPES_H
146 fprintf(f
, "#include <inttypes.h>\n");
148 #ifdef HAVE_SYS_TYPES_H
149 fprintf(f
, "#include <sys/types.h>\n");
151 #ifdef HAVE_SYS_BITYPES_H
152 fprintf(f
, "#include <sys/bitypes.h>\n");
154 #ifdef HAVE_BIND_BITYPES_H
155 fprintf(f
, "#include <bind/bitypes.h>\n");
157 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
158 fprintf(f
, "#include <netinet/in6_machtypes.h>\n");
160 #ifdef HAVE_SOCKLEN_T
162 fprintf(f
, "#include <sys/socket.h>\n");
164 fprintf(f
, "#include <winsock2.h>\n");
165 fprintf(f
, "#include <ws2tcpip.h>\n");
172 flag
= print_bt(f
, flag
);
174 #endif /* HAVE_INT8_T */
176 flag
= print_bt(f
, flag
);
178 #endif /* HAVE_INT16_T */
180 flag
= print_bt(f
, flag
);
182 #endif /* HAVE_INT32_T */
184 flag
= print_bt(f
, flag
);
186 #endif /* HAVE_INT64_T */
189 flag
= print_bt(f
, flag
);
191 #endif /* HAVE_UINT8_T */
192 #ifndef HAVE_UINT16_T
193 flag
= print_bt(f
, flag
);
194 try_unsigned (f
, 16);
195 #endif /* HAVE_UINT16_T */
196 #ifndef HAVE_UINT32_T
197 flag
= print_bt(f
, flag
);
198 try_unsigned (f
, 32);
199 #endif /* HAVE_UINT32_T */
200 #ifndef HAVE_UINT64_T
201 flag
= print_bt(f
, flag
);
202 try_unsigned (f
, 64);
203 #endif /* HAVE_UINT64_T */
205 #define X(S) fprintf(f, "typedef uint" #S "_t u_int" #S "_t;\n")
206 #ifndef HAVE_U_INT8_T
207 flag
= print_bt(f
, flag
);
209 #endif /* HAVE_U_INT8_T */
210 #ifndef HAVE_U_INT16_T
211 flag
= print_bt(f
, flag
);
213 #endif /* HAVE_U_INT16_T */
214 #ifndef HAVE_U_INT32_T
215 flag
= print_bt(f
, flag
);
217 #endif /* HAVE_U_INT32_T */
218 #ifndef HAVE_U_INT64_T
219 flag
= print_bt(f
, flag
);
221 #endif /* HAVE_U_INT64_T */
225 fprintf(f
, "#endif /* __BIT_TYPES_DEFINED__ */\n\n");
229 #if defined(HAVE_SOCKLEN_T)
230 fprintf(f
, "typedef socklen_t krb5_socklen_t;\n");
232 fprintf(f
, "typedef int krb5_socklen_t;\n");
234 #if defined(HAVE_SSIZE_T)
236 fprintf(f
, "#include <unistd.h>\n");
238 fprintf(f
, "typedef ssize_t krb5_ssize_t;\n");
240 fprintf(f
, "typedef int krb5_ssize_t;\n");
245 fprintf(f
, "typedef SOCKET krb5_socket_t;\n");
247 fprintf(f
, "typedef int krb5_socket_t;\n");
253 fprintf(f
, "#if !defined(__has_extension)\n");
254 fprintf(f
, "#define __has_extension(x) 0\n");
255 fprintf(f
, "#endif\n\n");
257 fprintf(f
, "#ifndef KRB5TYPES_REQUIRE_GNUC\n");
258 fprintf(f
, "#define KRB5TYPES_REQUIRE_GNUC(m,n,p) \\\n");
259 fprintf(f
, " (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100) + __GNUC_PATCHLEVEL__) >= \\\n");
260 fprintf(f
, " (((m) * 10000) + ((n) * 100) + (p)))\n");
261 fprintf(f
, "#endif\n\n");
263 fprintf(f
, "#ifndef HEIMDAL_DEPRECATED\n");
264 fprintf(f
, "#if __has_extension(deprecated) || KRB5TYPES_REQUIRE_GNUC(3,1,0)\n");
265 fprintf(f
, "#define HEIMDAL_DEPRECATED __attribute__ ((__deprecated__))\n");
266 fprintf(f
, "#elif defined(_MSC_VER) && (_MSC_VER>1200)\n");
267 fprintf(f
, "#define HEIMDAL_DEPRECATED __declspec(deprecated)\n");
268 fprintf(f
, "#else\n");
269 fprintf(f
, "#define HEIMDAL_DEPRECATED\n");
270 fprintf(f
, "#endif\n");
271 fprintf(f
, "#endif\n\n");
273 fprintf(f
, "#ifndef HEIMDAL_PRINTF_ATTRIBUTE\n");
274 fprintf(f
, "#if __has_extension(format) || KRB5TYPES_REQUIRE_GNUC(3,1,0)\n");
275 fprintf(f
, "#define HEIMDAL_PRINTF_ATTRIBUTE(x) __attribute__ ((__format__ x))\n");
276 fprintf(f
, "#else\n");
277 fprintf(f
, "#define HEIMDAL_PRINTF_ATTRIBUTE(x)\n");
278 fprintf(f
, "#endif\n");
279 fprintf(f
, "#endif\n\n");
281 fprintf(f
, "#ifndef HEIMDAL_NORETURN_ATTRIBUTE\n");
282 fprintf(f
, "#if __has_extension(noreturn) || KRB5TYPES_REQUIRE_GNUC(3,1,0)\n");
283 fprintf(f
, "#define HEIMDAL_NORETURN_ATTRIBUTE __attribute__ ((__noreturn__))\n");
284 fprintf(f
, "#else\n");
285 fprintf(f
, "#define HEIMDAL_NORETURN_ATTRIBUTE\n");
286 fprintf(f
, "#endif\n");
287 fprintf(f
, "#endif\n\n");
289 fprintf(f
, "#ifndef HEIMDAL_UNUSED_ATTRIBUTE\n");
290 fprintf(f
, "#if __has_extension(unused) || KRB5TYPES_REQUIRE_GNUC(3,1,0)\n");
291 fprintf(f
, "#define HEIMDAL_UNUSED_ATTRIBUTE __attribute__ ((__unused__))\n");
292 fprintf(f
, "#else\n");
293 fprintf(f
, "#define HEIMDAL_UNUSED_ATTRIBUTE\n");
294 fprintf(f
, "#endif\n");
295 fprintf(f
, "#endif\n\n");
297 fprintf(f
, "#ifndef HEIMDAL_WARN_UNUSED_RESULT_ATTRIBUTE\n");
298 fprintf(f
, "#if __has_extension(warn_unused_result) || KRB5TYPES_REQUIRE_GNUC(3,3,0)\n");
299 fprintf(f
, "#define HEIMDAL_WARN_UNUSED_RESULT_ATTRIBUTE __attribute__ ((__warn_unused_result__))\n");
300 fprintf(f
, "#else\n");
301 fprintf(f
, "#define HEIMDAL_WARN_UNUSED_RESULT_ATTRIBUTE\n");
302 fprintf(f
, "#endif\n");
303 fprintf(f
, "#endif\n\n");
305 fprintf(f
, "#endif /* %s */\n", hb
);