2 * Rummage through the system header files using the C compiler itself
3 * as a parser, extracting stuff like preprocessor constants and the
4 * sizes and signedness of basic system types, and write it out as
9 * This software is part of the SBCL system. See the README file for
12 * While most of SBCL is derived from the CMU CL system, many
13 * utilities for the build process (like this one) were written from
14 * scratch after the fork from CMU CL.
16 * This software is in the public domain and is provided with
17 * absolutely no warranty. See the COPYING and CREDITS files for
23 #include <sys/types.h>
25 #define WIN32_LEAN_AND_MEAN
29 #include <sys/times.h>
31 #include <sys/ioctl.h>
32 #include <sys/termios.h>
34 #include "../src/runtime/darwin-dlshim.h"
35 #include "../src/runtime/darwin-langinfo.h"
48 #include "genesis/config.h"
50 #ifdef LISP_FEATURE_HPUX
51 #include <sys/bsdtty.h> /* for TIOCGPGRP */
54 #ifdef LISP_FEATURE_BSD
55 #include <sys/param.h>
56 #include <sys/sysctl.h>
61 #define DEFTYPE(lispname,cname) { cname foo; \
62 printf("(define-alien-type " lispname " (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); }
65 defconstant(char* lisp_name, unsigned long unix_number)
67 printf("(defconstant %s %lu) ; #x%lx\n",
68 lisp_name, unix_number, unix_number);
71 void deferrno(char* lisp_name, unsigned long unix_number)
73 defconstant(lisp_name, unix_number);
76 void defsignal(char* lisp_name, unsigned long unix_number)
78 defconstant(lisp_name, unix_number);
82 main(int argc, char *argv[])
84 /* don't need no steenking command line arguments */
86 fprintf(stderr, "argh! command line argument(s)\n");
90 /* don't need no steenking hand-editing */
92 ";;;; This is an automatically generated file, please do not hand-edit it.\n\
93 ;;;; See the program \"grovel-headers.c\".\n\
97 printf("(in-package \"SB!WIN32\")\n\n");
99 defconstant ("input-record-size", sizeof (INPUT_RECORD));
101 defconstant ("MAX_PATH", MAX_PATH);
103 printf(";;; CSIDL\n");
105 defconstant ("CSIDL_DESKTOP", CSIDL_DESKTOP);
106 defconstant ("CSIDL_INTERNET", CSIDL_INTERNET);
107 defconstant ("CSIDL_PROGRAMS", CSIDL_PROGRAMS);
108 defconstant ("CSIDL_CONTROLS", CSIDL_CONTROLS);
109 defconstant ("CSIDL_PRINTERS", CSIDL_PRINTERS);
110 defconstant ("CSIDL_PERSONAL", CSIDL_PERSONAL);
111 defconstant ("CSIDL_FAVORITES", CSIDL_FAVORITES);
112 defconstant ("CSIDL_STARTUP", CSIDL_STARTUP);
113 defconstant ("CSIDL_RECENT", CSIDL_RECENT);
114 defconstant ("CSIDL_SENDTO", CSIDL_SENDTO);
115 defconstant ("CSIDL_BITBUCKET", CSIDL_BITBUCKET);
116 defconstant ("CSIDL_STARTMENU", CSIDL_STARTMENU);
117 defconstant ("CSIDL_DESKTOPDIRECTORY", CSIDL_DESKTOPDIRECTORY);
118 defconstant ("CSIDL_DRIVES", CSIDL_DRIVES);
119 defconstant ("CSIDL_NETWORK", CSIDL_NETWORK);
120 defconstant ("CSIDL_NETHOOD", CSIDL_NETHOOD);
121 defconstant ("CSIDL_FONTS", CSIDL_FONTS);
122 defconstant ("CSIDL_TEMPLATES", CSIDL_TEMPLATES);
123 defconstant ("CSIDL_COMMON_STARTMENU", CSIDL_COMMON_STARTMENU);
124 defconstant ("CSIDL_COMMON_PROGRAMS", CSIDL_COMMON_PROGRAMS);
125 defconstant ("CSIDL_COMMON_STARTUP", CSIDL_COMMON_STARTUP);
126 defconstant ("CSIDL_COMMON_DESKTOPDIRECTORY", CSIDL_COMMON_DESKTOPDIRECTORY);
127 defconstant ("CSIDL_APPDATA", CSIDL_APPDATA);
128 defconstant ("CSIDL_PRINTHOOD", CSIDL_PRINTHOOD);
129 defconstant ("CSIDL_LOCAL_APPDATA", CSIDL_LOCAL_APPDATA);
130 defconstant ("CSIDL_ALTSTARTUP", CSIDL_ALTSTARTUP);
131 defconstant ("CSIDL_COMMON_ALTSTARTUP", CSIDL_COMMON_ALTSTARTUP);
132 defconstant ("CSIDL_COMMON_FAVORITES", CSIDL_COMMON_FAVORITES);
133 defconstant ("CSIDL_INTERNET_CACHE", CSIDL_INTERNET_CACHE);
134 defconstant ("CSIDL_COOKIES", CSIDL_COOKIES);
135 defconstant ("CSIDL_HISTORY", CSIDL_HISTORY);
136 defconstant ("CSIDL_COMMON_APPDATA", CSIDL_COMMON_APPDATA);
137 defconstant ("CSIDL_WINDOWS", CSIDL_WINDOWS);
138 defconstant ("CSIDL_SYSTEM", CSIDL_SYSTEM);
139 defconstant ("CSIDL_PROGRAM_FILES", CSIDL_PROGRAM_FILES);
140 defconstant ("CSIDL_MYPICTURES", CSIDL_MYPICTURES);
141 defconstant ("CSIDL_PROFILE", CSIDL_PROFILE);
142 defconstant ("CSIDL_SYSTEMX86", CSIDL_SYSTEMX86);
143 defconstant ("CSIDL_PROGRAM_FILESX86", CSIDL_PROGRAM_FILESX86);
144 defconstant ("CSIDL_PROGRAM_FILES_COMMON", CSIDL_PROGRAM_FILES_COMMON);
145 defconstant ("CSIDL_PROGRAM_FILES_COMMONX86", CSIDL_PROGRAM_FILES_COMMONX86);
146 defconstant ("CSIDL_COMMON_TEMPLATES", CSIDL_COMMON_TEMPLATES);
147 defconstant ("CSIDL_COMMON_DOCUMENTS", CSIDL_COMMON_DOCUMENTS);
148 defconstant ("CSIDL_COMMON_ADMINTOOLS", CSIDL_COMMON_ADMINTOOLS);
149 defconstant ("CSIDL_ADMINTOOLS", CSIDL_ADMINTOOLS);
150 defconstant ("CSIDL_CONNECTIONS", CSIDL_CONNECTIONS);
151 defconstant ("CSIDL_COMMON_MUSIC", CSIDL_COMMON_MUSIC);
152 defconstant ("CSIDL_COMMON_PICTURES", CSIDL_COMMON_PICTURES);
153 defconstant ("CSIDL_COMMON_VIDEO", CSIDL_COMMON_VIDEO);
154 defconstant ("CSIDL_RESOURCES", CSIDL_RESOURCES);
155 defconstant ("CSIDL_RESOURCES_LOCALIZED", CSIDL_RESOURCES_LOCALIZED);
156 defconstant ("CSIDL_COMMON_OEM_LINKS", CSIDL_COMMON_OEM_LINKS);
157 defconstant ("CSIDL_CDBURN_AREA", CSIDL_CDBURN_AREA);
158 defconstant ("CSIDL_COMPUTERSNEARME", CSIDL_COMPUTERSNEARME);
159 defconstant ("CSIDL_FLAG_DONT_VERIFY", CSIDL_FLAG_DONT_VERIFY);
160 defconstant ("CSIDL_FLAG_CREATE", CSIDL_FLAG_CREATE);
161 defconstant ("CSIDL_FLAG_MASK", CSIDL_FLAG_MASK);
163 printf(";;; Exception codes\n");
164 defconstant("+exception-access-violation+", EXCEPTION_ACCESS_VIOLATION);
165 defconstant("+exception-array-bounds-exceeded+", EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
166 defconstant("+exception-breakpoint+", EXCEPTION_BREAKPOINT);
167 defconstant("+exception-datatype-misalignment+", EXCEPTION_DATATYPE_MISALIGNMENT);
168 defconstant("+exception-flt-denormal-operand+", EXCEPTION_FLT_DENORMAL_OPERAND);
169 defconstant("+exception-flt-divide-by-zero+", EXCEPTION_FLT_DIVIDE_BY_ZERO);
170 defconstant("+exception-flt-inexact-result+", EXCEPTION_FLT_INEXACT_RESULT);
171 defconstant("+exception-flt-invalid-operation+", EXCEPTION_FLT_INVALID_OPERATION);
172 defconstant("+exception-flt-overflow+", EXCEPTION_FLT_OVERFLOW);
173 defconstant("+exception-flt-stack-check+", EXCEPTION_FLT_STACK_CHECK);
174 defconstant("+exception-flt-underflow+", EXCEPTION_FLT_UNDERFLOW);
175 defconstant("+exception-illegal-instruction+", EXCEPTION_ILLEGAL_INSTRUCTION);
176 defconstant("+exception-in-page-error+", EXCEPTION_IN_PAGE_ERROR);
177 defconstant("+exception-int-divide-by-zero+", EXCEPTION_INT_DIVIDE_BY_ZERO);
178 defconstant("+exception-int-overflow+", EXCEPTION_INT_OVERFLOW);
179 defconstant("+exception-invalid-disposition+", EXCEPTION_INVALID_DISPOSITION);
180 defconstant("+exception-noncontinuable-exception+", EXCEPTION_NONCONTINUABLE_EXCEPTION);
181 defconstant("+exception-priv-instruction+", EXCEPTION_PRIV_INSTRUCTION);
182 defconstant("+exception-single-step+", EXCEPTION_SINGLE_STEP);
183 defconstant("+exception-stack-overflow+", EXCEPTION_STACK_OVERFLOW);
185 printf(";;; FormatMessage\n");
187 defconstant ("FORMAT_MESSAGE_ALLOCATE_BUFFER", FORMAT_MESSAGE_ALLOCATE_BUFFER);
188 defconstant ("FORMAT_MESSAGE_FROM_SYSTEM", FORMAT_MESSAGE_FROM_SYSTEM);
190 printf(";;; Errors\n");
192 defconstant ("ERROR_ENVVAR_NOT_FOUND", ERROR_ENVVAR_NOT_FOUND);
194 printf(";;; GetComputerName\n");
196 defconstant ("MAX_COMPUTERNAME_LENGTH", MAX_COMPUTERNAME_LENGTH);
197 defconstant ("ERROR_BUFFER_OVERFLOW", ERROR_BUFFER_OVERFLOW);
199 printf(";;; Windows Types\n");
200 DEFTYPE("int-ptr", INT_PTR);
201 DEFTYPE("dword", DWORD);
202 DEFTYPE("bool", BOOL);
203 DEFTYPE("uint", UINT);
204 DEFTYPE("ulong", ULONG);
206 /* FIXME: SB-UNIX and SB-WIN32 really need to be untangled. */
207 printf("(in-package \"SB!UNIX\")\n\n");
208 printf(";;; Unix-like constants and types on Windows\n");
209 defconstant("o_rdonly", _O_RDONLY);
210 defconstant("o_wronly", _O_WRONLY);
211 defconstant("o_rdwr", _O_RDWR);
212 defconstant("o_creat", _O_CREAT);
213 defconstant("o_trunc", _O_TRUNC);
214 defconstant("o_append", _O_APPEND);
215 defconstant("o_excl", _O_EXCL);
216 defconstant("o_binary", _O_BINARY);
218 defconstant("enoent", ENOENT);
219 defconstant("eexist", EEXIST);
220 defconstant("eintr", EINTR);
221 defconstant("eagain", EAGAIN);
223 defconstant("s-ifmt", S_IFMT);
224 defconstant("s-ifdir", S_IFDIR);
225 defconstant("s-ifreg", S_IFREG);
227 DEFTYPE("ino-t", ino_t);
228 DEFTYPE("time-t", time_t);
229 DEFTYPE("off-t", off_t);
230 DEFTYPE("size-t", size_t);
231 DEFTYPE("mode-t", mode_t);
233 DEFTYPE("wst-dev-t", wst_dev_t);
234 DEFTYPE("wst-off-t", wst_off_t);
235 DEFTYPE("wst-blksize-t", wst_blksize_t);
236 DEFTYPE("wst-blkcnt-t", wst_blkcnt_t);
237 DEFTYPE("wst-nlink-t", wst_nlink_t);
238 DEFTYPE("wst-uid-t", wst_uid_t);
239 DEFTYPE("wst-gid-t", wst_gid_t);
242 printf("(in-package \"SB!ALIEN\")\n\n");
244 printf (";;;flags for dlopen()\n");
246 defconstant ("rtld-lazy", RTLD_LAZY);
247 defconstant ("rtld-now", RTLD_NOW);
248 defconstant ("rtld-global", RTLD_GLOBAL);
250 printf("(in-package \"SB!UNIX\")\n\n");
252 printf(";;; langinfo\n");
253 defconstant("codeset", CODESET);
255 printf(";;; types, types, types\n");
256 DEFTYPE("clock-t", clock_t);
257 DEFTYPE("dev-t", dev_t);
258 DEFTYPE("gid-t", gid_t);
259 DEFTYPE("ino-t", ino_t);
260 DEFTYPE("mode-t", mode_t);
261 DEFTYPE("nlink-t", nlink_t);
262 DEFTYPE("off-t", off_t);
263 DEFTYPE("size-t", size_t);
264 DEFTYPE("time-t", time_t);
265 #if !defined(LISP_FEATURE_OS_PROVIDES_SUSECONDS_T)
266 /* Similar kludge in sb-posix. */
267 DEFTYPE("suseconds-t", long);
269 DEFTYPE("suseconds-t", suseconds_t);
271 DEFTYPE("uid-t", uid_t);
272 printf(";; Types in src/runtime/wrap.h. See that file for explantion.\n");
273 printf(";; Don't use these types for anything other than the stat wrapper.\n");
274 DEFTYPE("wst-dev-t", wst_dev_t);
275 DEFTYPE("wst-off-t", wst_off_t);
276 DEFTYPE("wst-blksize-t", wst_blksize_t);
277 DEFTYPE("wst-blkcnt-t", wst_blkcnt_t);
278 DEFTYPE("wst-nlink-t", wst_nlink_t);
279 DEFTYPE("wst-uid-t", wst_uid_t);
280 DEFTYPE("wst-gid-t", wst_gid_t);
283 printf(";;; fcntl.h (or unistd.h on OpenBSD and NetBSD)\n");
284 defconstant("r_ok", R_OK);
285 defconstant("w_ok", W_OK);
286 defconstant("x_ok", X_OK);
287 defconstant("f_ok", F_OK);
290 printf(";;; fcntlbits.h\n");
291 defconstant("o_rdonly", O_RDONLY);
292 defconstant("o_wronly", O_WRONLY);
293 defconstant("o_rdwr", O_RDWR);
294 defconstant("o_accmode", O_ACCMODE);
295 defconstant("o_creat", O_CREAT);
296 defconstant("o_excl", O_EXCL);
297 defconstant("o_noctty", O_NOCTTY);
298 defconstant("o_trunc", O_TRUNC);
299 defconstant("o_append", O_APPEND);
300 #ifdef LISP_FEATURE_LARGEFILE
301 defconstant("o_largefile", O_LARGEFILE);
305 defconstant("s-ifmt", S_IFMT);
306 defconstant("s-ififo", S_IFIFO);
307 defconstant("s-ifchr", S_IFCHR);
308 defconstant("s-ifdir", S_IFDIR);
309 defconstant("s-ifblk", S_IFBLK);
310 defconstant("s-ifreg", S_IFREG);
313 defconstant("s-iflnk", S_IFLNK);
314 defconstant("s-ifsock", S_IFSOCK);
317 printf(";;; error numbers\n");
318 deferrno("ebadf", EBADF);
319 deferrno("enoent", ENOENT);
320 deferrno("eintr", EINTR);
321 deferrno("eagain", EAGAIN);
322 deferrno("eio", EIO);
323 deferrno("eexist", EEXIST);
324 deferrno("eloop", ELOOP);
325 deferrno("espipe", ESPIPE);
326 deferrno("ewouldblock", EWOULDBLOCK);
329 printf(";;; for wait3(2) in run-program.lisp\n");
330 defconstant("wnohang", WNOHANG);
331 defconstant("wuntraced", WUNTRACED);
334 printf(";;; various ioctl(2) flags\n");
335 defconstant("tiocgpgrp", TIOCGPGRP);
336 defconstant("tiocspgrp", TIOCSPGRP);
337 defconstant("tiocgwinsz", TIOCGWINSZ);
338 defconstant("tiocswinsz", TIOCSWINSZ);
339 /* KLUDGE: These are referenced by old CMUCL-derived code, but
340 * Linux doesn't define them.
342 * I think these are the BSD names, but I don't know what the
343 * corresponding SysV/Linux names are. As a point of reference,
344 * CMUCL doesn't have these defined either (although the defining
345 * forms *do* exist in src/code/unix.lisp), so I don't feel nearly
346 * so bad about not hunting them down. Insight into renamed
347 * obscure ioctl(2) flags appreciated. --njf, 2002-08-26
349 * I note that the first one I grepped for, TIOCSIGSEND, is
350 * referenced in SBCL conditional on #+HPUX. Maybe the porters of
351 * Oxbridge know more about things like that? And even if they
352 * don't, one benefit of the Rhodes crusade to heal the worthy
353 * ports should be that afterwards, if we grep for something like
354 * this in CVS and it's not there, we can lightheartedly nuke it.
355 * -- WHN 2002-08-30 */
357 defconstant("tiocsigsend", TIOCSIGSEND);
358 defconstant("tiocflush", TIOCFLUSH);
359 defconstant("tiocgetp", TIOCGETP);
360 defconstant("tiocsetp", TIOCSETP);
361 defconstant("tiocgetc", TIOCGETC);
362 defconstant("tiocsetc", TIOCSETC);
363 defconstant("tiocgltc", TIOCGLTC);
364 defconstant("tiocsltc", TIOCSLTC);
368 printf(";;; signals\n");
369 defconstant("sig-dfl", (unsigned long)SIG_DFL);
370 defconstant("sig-ign", (unsigned long)SIG_IGN);
372 defsignal("sigalrm", SIGALRM);
373 defsignal("sigbus", SIGBUS);
374 defsignal("sigchld", SIGCHLD);
375 defsignal("sigcont", SIGCONT);
377 defsignal("sigemt", SIGEMT);
379 defsignal("sigfpe", SIGFPE);
380 defsignal("sighup", SIGHUP);
381 defsignal("sigill", SIGILL);
382 defsignal("sigint", SIGINT);
383 defsignal("sigio", SIGIO);
384 defsignal("sigiot", SIGIOT);
385 defsignal("sigkill", SIGKILL);
386 defsignal("sigpipe", SIGPIPE);
387 defsignal("sigprof", SIGPROF);
388 defsignal("sigquit", SIGQUIT);
389 defsignal("sigsegv", SIGSEGV);
391 defsignal("sigstkflt", SIGSTKFLT);
393 defsignal("sigstop", SIGSTOP);
395 defsignal("sigsys", SIGSYS);
397 defsignal("sigterm", SIGTERM);
398 defsignal("sigtrap", SIGTRAP);
399 defsignal("sigtstp", SIGTSTP);
400 defsignal("sigttin", SIGTTIN);
401 defsignal("sigttou", SIGTTOU);
402 defsignal("sigurg", SIGURG);
403 defsignal("sigusr1", SIGUSR1);
404 defsignal("sigusr2", SIGUSR2);
405 defsignal("sigvtalrm", SIGVTALRM);
407 defsignal("sigwaiting", SIGWAITING);
409 defsignal("sigwinch", SIGWINCH);
411 defsignal("sigxcpu", SIGXCPU);
414 defsignal("sigxfsz", SIGXFSZ);
417 /* Floating point exception codes. Some of these
418 * are missing on Darwin. */
420 defconstant("fpe-intovf", FPE_INTOVF);
422 defconstant("fpe-intovf", -1);
425 defconstant("fpe-intdiv", FPE_INTDIV);
427 defconstant("fpe-intdiv", -1);
429 defconstant("fpe-fltdiv", FPE_FLTDIV);
430 defconstant("fpe-fltovf", FPE_FLTOVF);
431 defconstant("fpe-fltund", FPE_FLTUND);
432 defconstant("fpe-fltres", FPE_FLTRES);
433 defconstant("fpe-fltinv", FPE_FLTINV);
435 defconstant("fpe-fltsub", FPE_FLTSUB);
437 defconstant("fpe-fltsub", -1);
441 #ifdef LISP_FEATURE_BSD
442 printf(";;; sysctl(3) names\n");
443 printf("(in-package \"SB!IMPL\")\n\n");
444 defconstant("ctl-kern", CTL_KERN);
445 defconstant("ctl-hw", CTL_HW);
446 defconstant("ctl-maxname", CTL_MAXNAME);
447 defconstant("kern-ostype", KERN_OSTYPE);
448 defconstant("kern-osrelease", KERN_OSRELEASE);
449 defconstant("hw-model", HW_MODEL);
450 defconstant("hw-pagesize", HW_PAGESIZE);