[win32] fix POSIX for mingw32
[p5sagit/p5-mst-13.2.git] / ext / POSIX / POSIX.xs
1 #ifdef WIN32
2 #define _POSIX_
3 #endif
4 #include "EXTERN.h"
5 #define PERLIO_NOT_STDIO 1
6 #include "perl.h"
7 #include "XSUB.h"
8 #include <ctype.h>
9 #ifdef I_DIRENT    /* XXX maybe better to just rely on perl.h? */
10 #include <dirent.h>
11 #endif
12 #include <errno.h>
13 #ifdef I_FLOAT
14 #include <float.h>
15 #endif
16 #ifdef I_LIMITS
17 #include <limits.h>
18 #endif
19 #include <locale.h>
20 #include <math.h>
21 #ifdef I_PWD
22 #include <pwd.h>
23 #endif
24 #include <setjmp.h>
25 #include <signal.h>
26 #ifdef I_STDARG
27 #include <stdarg.h>
28 #endif
29 #ifdef I_STDDEF
30 #include <stddef.h>
31 #endif
32 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to 
33    metaconfig for future extension writers.  We don't use them in POSIX.
34    (This is really sneaky :-)  --AD
35 */
36 #if defined(I_TERMIOS)
37 #include <termios.h>
38 #endif
39 #ifdef I_STDLIB
40 #include <stdlib.h>
41 #endif
42 #include <string.h>
43 #include <sys/stat.h>
44 #include <sys/types.h>
45 #include <time.h>
46 #ifdef I_UNISTD
47 #include <unistd.h>     /* see hints/sunos_4_1.sh */
48 #endif
49 #include <fcntl.h>
50
51 #if defined(__VMS) && !defined(__POSIX_SOURCE)
52 #  include <libdef.h>       /* LIB$_INVARG constant */
53 #  include <lib$routines.h> /* prototype for lib$ediv() */
54 #  include <starlet.h>      /* prototype for sys$gettim() */
55 #  if DECC_VERSION < 50000000
56 #    define pid_t int       /* old versions of DECC miss this in types.h */
57 #  endif
58
59 #  undef mkfifo  /* #defined in perl.h */
60 #  define mkfifo(a,b) (not_here("mkfifo"),-1)
61 #  define tzset() not_here("tzset")
62
63 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
64 #    define HAS_TZNAME  /* shows up in VMS 7.0 or Dec C 5.6 */
65 #    include <utsname.h>
66 #  endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
67
68    /* The POSIX notion of ttyname() is better served by getname() under VMS */
69    static char ttnambuf[64];
70 #  define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
71
72    /* The non-POSIX CRTL times() has void return type, so we just get the
73       current time directly */
74    clock_t vms_times(struct tms *bufptr) {
75         clock_t retval;
76         /* Get wall time and convert to 10 ms intervals to
77          * produce the return value that the POSIX standard expects */
78 #  if defined(__DECC) && defined (__ALPHA)
79 #    include <ints.h>
80         uint64 vmstime;
81         _ckvmssts(sys$gettim(&vmstime));
82         vmstime /= 100000;
83         retval = vmstime & 0x7fffffff;
84 #  else
85         /* (Older hw or ccs don't have an atomic 64-bit type, so we
86          * juggle 32-bit ints (and a float) to produce a time_t result
87          * with minimal loss of information.) */
88         long int vmstime[2],remainder,divisor = 100000;
89         _ckvmssts(sys$gettim((unsigned long int *)vmstime));
90         vmstime[1] &= 0x7fff;  /* prevent overflow in EDIV */
91         _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
92 #  endif
93         /* Fill in the struct tms using the CRTL routine . . .*/
94         times((tbuffer_t *)bufptr);
95         return (clock_t) retval;
96    }
97 #  define times(t) vms_times(t)
98 #else
99 #if defined (WIN32)
100 #  undef mkfifo  /* #defined in perl.h */
101 #  define mkfifo(a,b) not_here("mkfifo")
102 #  define ttyname(a) not_here("ttyname")
103 #  define sigset_t long
104 #  define pid_t long
105 #  ifdef __BORLANDC__
106 #    define tzname _tzname
107 #  endif
108 #  ifdef _MSC_VER
109 #    define mode_t short
110 #  endif
111 #  ifdef __MINGW32__
112 #    define mode_t short
113 #    define tzset()             not_here("tzset")
114 #  endif
115 #  define sigaction(a,b,c)      not_here("sigaction")
116 #  define sigpending(a)         not_here("sigpending")
117 #  define sigprocmask(a,b,c)    not_here("sigprocmask")
118 #  define sigsuspend(a)         not_here("sigsuspend")
119 #  define sigemptyset(a)        not_here("sigemptyset")
120 #  define sigaddset(a,b)        not_here("sigaddset")
121 #  define sigdelset(a,b)        not_here("sigdelset")
122 #  define sigfillset(a)         not_here("sigfillset")
123 #  define sigismember(a,b)      not_here("sigismember")
124 #else
125 #  include <grp.h>
126 #  include <sys/times.h>
127 #  ifdef HAS_UNAME
128 #    include <sys/utsname.h>
129 #  endif
130 #  include <sys/wait.h>
131 #  ifdef I_UTIME
132 #    include <utime.h>
133 #  endif
134 #endif /* WIN32 */
135 #endif /* __VMS */
136
137 typedef int SysRet;
138 typedef long SysRetLong;
139 typedef sigset_t* POSIX__SigSet;
140 typedef HV* POSIX__SigAction;
141 #ifdef I_TERMIOS
142 typedef struct termios* POSIX__Termios;
143 #else /* Define termios types to int, and call not_here for the functions.*/
144 #define POSIX__Termios int
145 #define speed_t int
146 #define tcflag_t int
147 #define cc_t int
148 #define cfgetispeed(x) not_here("cfgetispeed")
149 #define cfgetospeed(x) not_here("cfgetospeed")
150 #define tcdrain(x) not_here("tcdrain")
151 #define tcflush(x,y) not_here("tcflush")
152 #define tcsendbreak(x,y) not_here("tcsendbreak")
153 #define cfsetispeed(x,y) not_here("cfsetispeed")
154 #define cfsetospeed(x,y) not_here("cfsetospeed")
155 #define ctermid(x) (char *) not_here("ctermid")
156 #define tcflow(x,y) not_here("tcflow")
157 #define tcgetattr(x,y) not_here("tcgetattr")
158 #define tcsetattr(x,y,z) not_here("tcsetattr")
159 #endif
160
161 /* Possibly needed prototypes */
162 char *cuserid _((char *));
163 double strtod _((const char *, char **));
164 long strtol _((const char *, char **, int));
165 unsigned long strtoul _((const char *, char **, int));
166
167 #ifndef HAS_CUSERID
168 #define cuserid(a) (char *) not_here("cuserid")
169 #endif
170 #ifndef HAS_DIFFTIME
171 #ifndef difftime
172 #define difftime(a,b) not_here("difftime")
173 #endif
174 #endif
175 #ifndef HAS_FPATHCONF
176 #define fpathconf(f,n)  (SysRetLong) not_here("fpathconf")
177 #endif
178 #ifndef HAS_MKTIME
179 #define mktime(a) not_here("mktime")
180 #endif
181 #ifndef HAS_NICE
182 #define nice(a) not_here("nice")
183 #endif
184 #ifndef HAS_PATHCONF
185 #define pathconf(f,n)   (SysRetLong) not_here("pathconf")
186 #endif
187 #ifndef HAS_SYSCONF
188 #define sysconf(n)      (SysRetLong) not_here("sysconf")
189 #endif
190 #ifndef HAS_READLINK
191 #define readlink(a,b,c) not_here("readlink")
192 #endif
193 #ifndef HAS_SETPGID
194 #define setpgid(a,b) not_here("setpgid")
195 #endif
196 #ifndef HAS_SETSID
197 #define setsid() not_here("setsid")
198 #endif
199 #ifndef HAS_STRCOLL
200 #define strcoll(s1,s2) not_here("strcoll")
201 #endif
202 #ifndef HAS_STRTOD
203 #define strtod(s1,s2) not_here("strtod")
204 #endif
205 #ifndef HAS_STRTOL
206 #define strtol(s1,s2,b) not_here("strtol")
207 #endif
208 #ifndef HAS_STRTOUL
209 #define strtoul(s1,s2,b) not_here("strtoul")
210 #endif
211 #ifndef HAS_STRXFRM
212 #define strxfrm(s1,s2,n) not_here("strxfrm")
213 #endif
214 #ifndef HAS_TCGETPGRP
215 #define tcgetpgrp(a) not_here("tcgetpgrp")
216 #endif
217 #ifndef HAS_TCSETPGRP
218 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
219 #endif
220 #ifndef HAS_TIMES
221 #define times(a) not_here("times")
222 #endif
223 #ifndef HAS_UNAME
224 #define uname(a) not_here("uname")
225 #endif
226 #ifndef HAS_WAITPID
227 #define waitpid(a,b,c) not_here("waitpid")
228 #endif
229
230 #ifndef HAS_MBLEN
231 #ifndef mblen
232 #define mblen(a,b) not_here("mblen")
233 #endif
234 #endif
235 #ifndef HAS_MBSTOWCS
236 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
237 #endif
238 #ifndef HAS_MBTOWC
239 #define mbtowc(pwc, s, n) not_here("mbtowc")
240 #endif
241 #ifndef HAS_WCSTOMBS
242 #define wcstombs(s, pwcs, n) not_here("wcstombs")
243 #endif
244 #ifndef HAS_WCTOMB
245 #define wctomb(s, wchar) not_here("wcstombs")
246 #endif
247 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
248 /* If we don't have these functions, then we wouldn't have gotten a typedef
249    for wchar_t, the wide character type.  Defining wchar_t allows the
250    functions referencing it to compile.  Its actual type is then meaningless,
251    since without the above functions, all sections using it end up calling
252    not_here() and croak.  --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
253 #ifndef wchar_t
254 #define wchar_t char
255 #endif
256 #endif
257
258 #ifndef HAS_LOCALECONV
259 #define localeconv() not_here("localeconv")
260 #endif
261
262 #ifdef HAS_TZNAME
263 #  ifndef WIN32
264 extern char *tzname[];
265 #  endif
266 #else
267 char *tzname[] = { "" , "" };
268 #endif
269
270 /* XXX struct tm on some systems (SunOS4/BSD) contains extra (non POSIX)
271  * fields for which we don't have Configure support yet:
272  *   char *tm_zone;   -- abbreviation of timezone name
273  *   long tm_gmtoff;  -- offset from GMT in seconds
274  * To workaround core dumps from the uninitialised tm_zone we get the
275  * system to give us a reasonable struct to copy.  This fix means that
276  * strftime uses the tm_zone and tm_gmtoff values returned by
277  * localtime(time()). That should give the desired result most of the
278  * time. But probably not always!
279  *
280  * This is a temporary workaround to be removed once Configure
281  * support is added and NETaa14816 is considered in full.
282  * It does not address tzname aspects of NETaa14816.
283  */
284 #ifdef HAS_GNULIBC
285 # ifndef STRUCT_TM_HASZONE
286 #    define STRUCT_TM_HAS_ZONE
287 # endif
288 #endif
289
290 #ifdef STRUCT_TM_HASZONE
291 static void
292 init_tm(ptm)            /* see mktime, strftime and asctime     */
293     struct tm *ptm;
294 {
295     Time_t now;
296     (void)time(&now);
297     Copy(localtime(&now), ptm, 1, struct tm);
298 }
299
300 #else
301 # define init_tm(ptm)
302 #endif
303
304
305 #ifdef HAS_LONG_DOUBLE
306 #  if LONG_DOUBLESIZE > DOUBLESIZE
307 #    undef HAS_LONG_DOUBLE  /* XXX until we figure out how to use them */
308 #  endif
309 #endif
310
311 #ifndef HAS_LONG_DOUBLE 
312 #ifdef LDBL_MAX
313 #undef LDBL_MAX
314 #endif
315 #ifdef LDBL_MIN
316 #undef LDBL_MIN
317 #endif
318 #ifdef LDBL_EPSILON
319 #undef LDBL_EPSILON
320 #endif
321 #endif
322
323 static int
324 not_here(char *s)
325 {
326     croak("POSIX::%s not implemented on this architecture", s);
327     return -1;
328 }
329
330 static
331 #ifdef HAS_LONG_DOUBLE
332 long double
333 #else
334 double
335 #endif
336 constant(char *name, int arg)
337 {
338     errno = 0;
339     switch (*name) {
340     case 'A':
341         if (strEQ(name, "ARG_MAX"))
342 #ifdef ARG_MAX
343             return ARG_MAX;
344 #else
345             goto not_there;
346 #endif
347         break;
348     case 'B':
349         if (strEQ(name, "BUFSIZ"))
350 #ifdef BUFSIZ
351             return BUFSIZ;
352 #else
353             goto not_there;
354 #endif
355         if (strEQ(name, "BRKINT"))
356 #ifdef BRKINT
357             return BRKINT;
358 #else
359             goto not_there;
360 #endif
361         if (strEQ(name, "B9600"))
362 #ifdef B9600
363             return B9600;
364 #else
365             goto not_there;
366 #endif
367         if (strEQ(name, "B19200"))
368 #ifdef B19200
369             return B19200;
370 #else
371             goto not_there;
372 #endif
373         if (strEQ(name, "B38400"))
374 #ifdef B38400
375             return B38400;
376 #else
377             goto not_there;
378 #endif
379         if (strEQ(name, "B0"))
380 #ifdef B0
381             return B0;
382 #else
383             goto not_there;
384 #endif
385         if (strEQ(name, "B110"))
386 #ifdef B110
387             return B110;
388 #else
389             goto not_there;
390 #endif
391         if (strEQ(name, "B1200"))
392 #ifdef B1200
393             return B1200;
394 #else
395             goto not_there;
396 #endif
397         if (strEQ(name, "B134"))
398 #ifdef B134
399             return B134;
400 #else
401             goto not_there;
402 #endif
403         if (strEQ(name, "B150"))
404 #ifdef B150
405             return B150;
406 #else
407             goto not_there;
408 #endif
409         if (strEQ(name, "B1800"))
410 #ifdef B1800
411             return B1800;
412 #else
413             goto not_there;
414 #endif
415         if (strEQ(name, "B200"))
416 #ifdef B200
417             return B200;
418 #else
419             goto not_there;
420 #endif
421         if (strEQ(name, "B2400"))
422 #ifdef B2400
423             return B2400;
424 #else
425             goto not_there;
426 #endif
427         if (strEQ(name, "B300"))
428 #ifdef B300
429             return B300;
430 #else
431             goto not_there;
432 #endif
433         if (strEQ(name, "B4800"))
434 #ifdef B4800
435             return B4800;
436 #else
437             goto not_there;
438 #endif
439         if (strEQ(name, "B50"))
440 #ifdef B50
441             return B50;
442 #else
443             goto not_there;
444 #endif
445         if (strEQ(name, "B600"))
446 #ifdef B600
447             return B600;
448 #else
449             goto not_there;
450 #endif
451         if (strEQ(name, "B75"))
452 #ifdef B75
453             return B75;
454 #else
455             goto not_there;
456 #endif
457         break;
458     case 'C':
459         if (strEQ(name, "CHAR_BIT"))
460 #ifdef CHAR_BIT
461             return CHAR_BIT;
462 #else
463             goto not_there;
464 #endif
465         if (strEQ(name, "CHAR_MAX"))
466 #ifdef CHAR_MAX
467             return CHAR_MAX;
468 #else
469             goto not_there;
470 #endif
471         if (strEQ(name, "CHAR_MIN"))
472 #ifdef CHAR_MIN
473             return CHAR_MIN;
474 #else
475             goto not_there;
476 #endif
477         if (strEQ(name, "CHILD_MAX"))
478 #ifdef CHILD_MAX
479             return CHILD_MAX;
480 #else
481             goto not_there;
482 #endif
483         if (strEQ(name, "CLK_TCK"))
484 #ifdef CLK_TCK
485             return CLK_TCK;
486 #else
487             goto not_there;
488 #endif
489         if (strEQ(name, "CLOCAL"))
490 #ifdef CLOCAL
491             return CLOCAL;
492 #else
493             goto not_there;
494 #endif
495         if (strEQ(name, "CLOCKS_PER_SEC"))
496 #ifdef CLOCKS_PER_SEC
497             return CLOCKS_PER_SEC;
498 #else
499             goto not_there;
500 #endif
501         if (strEQ(name, "CREAD"))
502 #ifdef CREAD
503             return CREAD;
504 #else
505             goto not_there;
506 #endif
507         if (strEQ(name, "CS5"))
508 #ifdef CS5
509             return CS5;
510 #else
511             goto not_there;
512 #endif
513         if (strEQ(name, "CS6"))
514 #ifdef CS6
515             return CS6;
516 #else
517             goto not_there;
518 #endif
519         if (strEQ(name, "CS7"))
520 #ifdef CS7
521             return CS7;
522 #else
523             goto not_there;
524 #endif
525         if (strEQ(name, "CS8"))
526 #ifdef CS8
527             return CS8;
528 #else
529             goto not_there;
530 #endif
531         if (strEQ(name, "CSIZE"))
532 #ifdef CSIZE
533             return CSIZE;
534 #else
535             goto not_there;
536 #endif
537         if (strEQ(name, "CSTOPB"))
538 #ifdef CSTOPB
539             return CSTOPB;
540 #else
541             goto not_there;
542 #endif
543         break;
544     case 'D':
545         if (strEQ(name, "DBL_MAX"))
546 #ifdef DBL_MAX
547             return DBL_MAX;
548 #else
549             goto not_there;
550 #endif
551         if (strEQ(name, "DBL_MIN"))
552 #ifdef DBL_MIN
553             return DBL_MIN;
554 #else
555             goto not_there;
556 #endif
557         if (strEQ(name, "DBL_DIG"))
558 #ifdef DBL_DIG
559             return DBL_DIG;
560 #else
561             goto not_there;
562 #endif
563         if (strEQ(name, "DBL_EPSILON"))
564 #ifdef DBL_EPSILON
565             return DBL_EPSILON;
566 #else
567             goto not_there;
568 #endif
569         if (strEQ(name, "DBL_MANT_DIG"))
570 #ifdef DBL_MANT_DIG
571             return DBL_MANT_DIG;
572 #else
573             goto not_there;
574 #endif
575         if (strEQ(name, "DBL_MAX_10_EXP"))
576 #ifdef DBL_MAX_10_EXP
577             return DBL_MAX_10_EXP;
578 #else
579             goto not_there;
580 #endif
581         if (strEQ(name, "DBL_MAX_EXP"))
582 #ifdef DBL_MAX_EXP
583             return DBL_MAX_EXP;
584 #else
585             goto not_there;
586 #endif
587         if (strEQ(name, "DBL_MIN_10_EXP"))
588 #ifdef DBL_MIN_10_EXP
589             return DBL_MIN_10_EXP;
590 #else
591             goto not_there;
592 #endif
593         if (strEQ(name, "DBL_MIN_EXP"))
594 #ifdef DBL_MIN_EXP
595             return DBL_MIN_EXP;
596 #else
597             goto not_there;
598 #endif
599         break;
600     case 'E':
601         switch (name[1]) {
602         case 'A':
603             if (strEQ(name, "EACCES"))
604 #ifdef EACCES
605                 return EACCES;
606 #else
607                 goto not_there;
608 #endif
609             if (strEQ(name, "EADDRINUSE"))
610 #ifdef EADDRINUSE
611                 return EADDRINUSE;
612 #else
613                 goto not_there;
614 #endif
615             if (strEQ(name, "EADDRNOTAVAIL"))
616 #ifdef EADDRNOTAVAIL
617                 return EADDRNOTAVAIL;
618 #else
619                 goto not_there;
620 #endif
621             if (strEQ(name, "EAFNOSUPPORT"))
622 #ifdef EAFNOSUPPORT
623                 return EAFNOSUPPORT;
624 #else
625                 goto not_there;
626 #endif
627             if (strEQ(name, "EAGAIN"))
628 #ifdef EAGAIN
629                 return EAGAIN;
630 #else
631                 goto not_there;
632 #endif
633             if (strEQ(name, "EALREADY"))
634 #ifdef EALREADY
635                 return EALREADY;
636 #else
637                 goto not_there;
638 #endif
639             break;
640         case 'B':
641             if (strEQ(name, "EBADF"))
642 #ifdef EBADF
643                 return EBADF;
644 #else
645                 goto not_there;
646 #endif
647             if (strEQ(name, "EBUSY"))
648 #ifdef EBUSY
649                 return EBUSY;
650 #else
651                 goto not_there;
652 #endif
653             break;
654         case 'C':
655             if (strEQ(name, "ECHILD"))
656 #ifdef ECHILD
657                 return ECHILD;
658 #else
659                 goto not_there;
660 #endif
661             if (strEQ(name, "ECHO"))
662 #ifdef ECHO
663                 return ECHO;
664 #else
665                 goto not_there;
666 #endif
667             if (strEQ(name, "ECHOE"))
668 #ifdef ECHOE
669                 return ECHOE;
670 #else
671                 goto not_there;
672 #endif
673             if (strEQ(name, "ECHOK"))
674 #ifdef ECHOK
675                 return ECHOK;
676 #else
677                 goto not_there;
678 #endif
679             if (strEQ(name, "ECHONL"))
680 #ifdef ECHONL
681                 return ECHONL;
682 #else
683                 goto not_there;
684 #endif
685             if (strEQ(name, "ECONNABORTED"))
686 #ifdef ECONNABORTED
687                 return ECONNABORTED;
688 #else
689                 goto not_there;
690 #endif
691             if (strEQ(name, "ECONNREFUSED"))
692 #ifdef ECONNREFUSED
693                 return ECONNREFUSED;
694 #else
695                 goto not_there;
696 #endif
697             if (strEQ(name, "ECONNRESET"))
698 #ifdef ECONNRESET
699                 return ECONNRESET;
700 #else
701                 goto not_there;
702 #endif
703             break;
704         case 'D':
705             if (strEQ(name, "EDEADLK"))
706 #ifdef EDEADLK
707                 return EDEADLK;
708 #else
709                 goto not_there;
710 #endif
711             if (strEQ(name, "EDESTADDRREQ"))
712 #ifdef EDESTADDRREQ
713                 return EDESTADDRREQ;
714 #else
715                 goto not_there;
716 #endif
717             if (strEQ(name, "EDOM"))
718 #ifdef EDOM
719                 return EDOM;
720 #else
721                 goto not_there;
722 #endif
723             if (strEQ(name, "EDQUOT"))
724 #ifdef EDQUOT
725                 return EDQUOT;
726 #else
727                 goto not_there;
728 #endif
729             break;
730         case 'E':
731             if (strEQ(name, "EEXIST"))
732 #ifdef EEXIST
733                 return EEXIST;
734 #else
735                 goto not_there;
736 #endif
737             break;
738         case 'F':
739             if (strEQ(name, "EFAULT"))
740 #ifdef EFAULT
741                 return EFAULT;
742 #else
743                 goto not_there;
744 #endif
745             if (strEQ(name, "EFBIG"))
746 #ifdef EFBIG
747                 return EFBIG;
748 #else
749                 goto not_there;
750 #endif
751             break;
752         case 'H':
753             if (strEQ(name, "EHOSTDOWN"))
754 #ifdef EHOSTDOWN
755                 return EHOSTDOWN;
756 #else
757                 goto not_there;
758 #endif
759             if (strEQ(name, "EHOSTUNREACH"))
760 #ifdef EHOSTUNREACH
761                 return EHOSTUNREACH;
762 #else
763                 goto not_there;
764 #endif
765             break;
766         case 'I':
767             if (strEQ(name, "EINPROGRESS"))
768 #ifdef EINPROGRESS
769                 return EINPROGRESS;
770 #else
771                 goto not_there;
772 #endif
773             if (strEQ(name, "EINTR"))
774 #ifdef EINTR
775                 return EINTR;
776 #else
777                 goto not_there;
778 #endif
779             if (strEQ(name, "EINVAL"))
780 #ifdef EINVAL
781                 return EINVAL;
782 #else
783                 goto not_there;
784 #endif
785             if (strEQ(name, "EIO"))
786 #ifdef EIO
787                 return EIO;
788 #else
789                 goto not_there;
790 #endif
791             if (strEQ(name, "EISCONN"))
792 #ifdef EISCONN
793                 return EISCONN;
794 #else
795                 goto not_there;
796 #endif
797             if (strEQ(name, "EISDIR"))
798 #ifdef EISDIR
799                 return EISDIR;
800 #else
801                 goto not_there;
802 #endif
803             if (strEQ(name, "ELOOP"))
804 #ifdef ELOOP
805                 return ELOOP;
806 #else
807                 goto not_there;
808 #endif
809             break;
810         case 'M':
811             if (strEQ(name, "EMFILE"))
812 #ifdef EMFILE
813                 return EMFILE;
814 #else
815                 goto not_there;
816 #endif
817             if (strEQ(name, "EMLINK"))
818 #ifdef EMLINK
819                 return EMLINK;
820 #else
821                 goto not_there;
822 #endif
823             if (strEQ(name, "EMSGSIZE"))
824 #ifdef EMSGSIZE
825                 return EMSGSIZE;
826 #else
827                 goto not_there;
828 #endif
829             break;
830         case 'N':
831             if (strEQ(name, "ENETDOWN"))
832 #ifdef ENETDOWN
833                 return ENETDOWN;
834 #else
835                 goto not_there;
836 #endif
837             if (strEQ(name, "ENETRESET"))
838 #ifdef ENETRESET
839                 return ENETRESET;
840 #else
841                 goto not_there;
842 #endif
843             if (strEQ(name, "ENETUNREACH"))
844 #ifdef ENETUNREACH
845                 return ENETUNREACH;
846 #else
847                 goto not_there;
848 #endif
849             if (strEQ(name, "ENOBUFS"))
850 #ifdef ENOBUFS
851                 return ENOBUFS;
852 #else
853                 goto not_there;
854 #endif
855             if (strEQ(name, "ENOEXEC"))
856 #ifdef ENOEXEC
857                 return ENOEXEC;
858 #else
859                 goto not_there;
860 #endif
861             if (strEQ(name, "ENOMEM"))
862 #ifdef ENOMEM
863                 return ENOMEM;
864 #else
865                 goto not_there;
866 #endif
867             if (strEQ(name, "ENOPROTOOPT"))
868 #ifdef ENOPROTOOPT
869                 return ENOPROTOOPT;
870 #else
871                 goto not_there;
872 #endif
873             if (strEQ(name, "ENOSPC"))
874 #ifdef ENOSPC
875                 return ENOSPC;
876 #else
877                 goto not_there;
878 #endif
879             if (strEQ(name, "ENOTBLK"))
880 #ifdef ENOTBLK
881                 return ENOTBLK;
882 #else
883                 goto not_there;
884 #endif
885             if (strEQ(name, "ENOTCONN"))
886 #ifdef ENOTCONN
887                 return ENOTCONN;
888 #else
889                 goto not_there;
890 #endif
891             if (strEQ(name, "ENOTDIR"))
892 #ifdef ENOTDIR
893                 return ENOTDIR;
894 #else
895                 goto not_there;
896 #endif
897             if (strEQ(name, "ENOTEMPTY"))
898 #ifdef ENOTEMPTY
899                 return ENOTEMPTY;
900 #else
901                 goto not_there;
902 #endif
903             if (strEQ(name, "ENOTSOCK"))
904 #ifdef ENOTSOCK
905                 return ENOTSOCK;
906 #else
907                 goto not_there;
908 #endif
909             if (strEQ(name, "ENOTTY"))
910 #ifdef ENOTTY
911                 return ENOTTY;
912 #else
913                 goto not_there;
914 #endif
915             if (strEQ(name, "ENFILE"))
916 #ifdef ENFILE
917                 return ENFILE;
918 #else
919                 goto not_there;
920 #endif
921             if (strEQ(name, "ENODEV"))
922 #ifdef ENODEV
923                 return ENODEV;
924 #else
925                 goto not_there;
926 #endif
927             if (strEQ(name, "ENOENT"))
928 #ifdef ENOENT
929                 return ENOENT;
930 #else
931                 goto not_there;
932 #endif
933             if (strEQ(name, "ENOLCK"))
934 #ifdef ENOLCK
935                 return ENOLCK;
936 #else
937                 goto not_there;
938 #endif
939             if (strEQ(name, "ENOSYS"))
940 #ifdef ENOSYS
941                 return ENOSYS;
942 #else
943                 goto not_there;
944 #endif
945             if (strEQ(name, "ENXIO"))
946 #ifdef ENXIO
947                 return ENXIO;
948 #else
949                 goto not_there;
950 #endif
951             if (strEQ(name, "ENAMETOOLONG"))
952 #ifdef ENAMETOOLONG
953                 return ENAMETOOLONG;
954 #else
955                 goto not_there;
956 #endif
957             break;
958         case 'O':
959             if (strEQ(name, "EOF"))
960 #ifdef EOF
961                 return EOF;
962 #else
963                 goto not_there;
964 #endif
965             if (strEQ(name, "EOPNOTSUPP"))
966 #ifdef EOPNOTSUPP
967                 return EOPNOTSUPP;
968 #else
969                 goto not_there;
970 #endif
971             break;
972         case 'P':
973             if (strEQ(name, "EPERM"))
974 #ifdef EPERM
975                 return EPERM;
976 #else
977                 goto not_there;
978 #endif
979             if (strEQ(name, "EPFNOSUPPORT"))
980 #ifdef EPFNOSUPPORT
981                 return EPFNOSUPPORT;
982 #else
983                 goto not_there;
984 #endif
985             if (strEQ(name, "EPIPE"))
986 #ifdef EPIPE
987                 return EPIPE;
988 #else
989                 goto not_there;
990 #endif
991             if (strEQ(name, "EPROCLIM"))
992 #ifdef EPROCLIM
993                 return EPROCLIM;
994 #else
995                 goto not_there;
996 #endif
997             if (strEQ(name, "EPROTONOSUPPORT"))
998 #ifdef EPROTONOSUPPORT
999                 return EPROTONOSUPPORT;
1000 #else
1001                 goto not_there;
1002 #endif
1003             if (strEQ(name, "EPROTOTYPE"))
1004 #ifdef EPROTOTYPE
1005                 return EPROTOTYPE;
1006 #else
1007                 goto not_there;
1008 #endif
1009             break;
1010         case 'R':
1011             if (strEQ(name, "ERANGE"))
1012 #ifdef ERANGE
1013                 return ERANGE;
1014 #else
1015                 goto not_there;
1016 #endif
1017             if (strEQ(name, "EREMOTE"))
1018 #ifdef EREMOTE
1019                 return EREMOTE;
1020 #else
1021                 goto not_there;
1022 #endif
1023             if (strEQ(name, "ERESTART"))
1024 #ifdef ERESTART
1025                 return ERESTART;
1026 #else
1027                 goto not_there;
1028 #endif
1029             if (strEQ(name, "EROFS"))
1030 #ifdef EROFS
1031                 return EROFS;
1032 #else
1033                 goto not_there;
1034 #endif
1035             break;
1036         case 'S':
1037             if (strEQ(name, "ESHUTDOWN"))
1038 #ifdef ESHUTDOWN
1039                 return ESHUTDOWN;
1040 #else
1041                 goto not_there;
1042 #endif
1043             if (strEQ(name, "ESOCKTNOSUPPORT"))
1044 #ifdef ESOCKTNOSUPPORT
1045                 return ESOCKTNOSUPPORT;
1046 #else
1047                 goto not_there;
1048 #endif
1049             if (strEQ(name, "ESPIPE"))
1050 #ifdef ESPIPE
1051                 return ESPIPE;
1052 #else
1053                 goto not_there;
1054 #endif
1055             if (strEQ(name, "ESRCH"))
1056 #ifdef ESRCH
1057                 return ESRCH;
1058 #else
1059                 goto not_there;
1060 #endif
1061             if (strEQ(name, "ESTALE"))
1062 #ifdef ESTALE
1063                 return ESTALE;
1064 #else
1065                 goto not_there;
1066 #endif
1067             break;
1068         case 'T':
1069             if (strEQ(name, "ETIMEDOUT"))
1070 #ifdef ETIMEDOUT
1071                 return ETIMEDOUT;
1072 #else
1073                 goto not_there;
1074 #endif
1075             if (strEQ(name, "ETOOMANYREFS"))
1076 #ifdef ETOOMANYREFS
1077                 return ETOOMANYREFS;
1078 #else
1079                 goto not_there;
1080 #endif
1081             if (strEQ(name, "ETXTBSY"))
1082 #ifdef ETXTBSY
1083                 return ETXTBSY;
1084 #else
1085                 goto not_there;
1086 #endif
1087             break;
1088         case 'U':
1089             if (strEQ(name, "EUSERS"))
1090 #ifdef EUSERS
1091                 return EUSERS;
1092 #else
1093                 goto not_there;
1094 #endif
1095             break;
1096         case 'W':
1097             if (strEQ(name, "EWOULDBLOCK"))
1098 #ifdef EWOULDBLOCK
1099                 return EWOULDBLOCK;
1100 #else
1101                 goto not_there;
1102 #endif
1103             break;
1104         case 'X':
1105             if (strEQ(name, "EXIT_FAILURE"))
1106 #ifdef EXIT_FAILURE
1107                 return EXIT_FAILURE;
1108 #else
1109                 return 1;
1110 #endif
1111             if (strEQ(name, "EXIT_SUCCESS"))
1112 #ifdef EXIT_SUCCESS
1113                 return EXIT_SUCCESS;
1114 #else
1115                 return 0;
1116 #endif
1117             if (strEQ(name, "EXDEV"))
1118 #ifdef EXDEV
1119                 return EXDEV;
1120 #else
1121                 goto not_there;
1122 #endif
1123             break;
1124         }
1125         if (strEQ(name, "E2BIG"))
1126 #ifdef E2BIG
1127             return E2BIG;
1128 #else
1129             goto not_there;
1130 #endif
1131         break;
1132     case 'F':
1133         if (strnEQ(name, "FLT_", 4)) {
1134             if (strEQ(name, "FLT_MAX"))
1135 #ifdef FLT_MAX
1136                 return FLT_MAX;
1137 #else
1138                 goto not_there;
1139 #endif
1140             if (strEQ(name, "FLT_MIN"))
1141 #ifdef FLT_MIN
1142                 return FLT_MIN;
1143 #else
1144                 goto not_there;
1145 #endif
1146             if (strEQ(name, "FLT_ROUNDS"))
1147 #ifdef FLT_ROUNDS
1148                 return FLT_ROUNDS;
1149 #else
1150                 goto not_there;
1151 #endif
1152             if (strEQ(name, "FLT_DIG"))
1153 #ifdef FLT_DIG
1154                 return FLT_DIG;
1155 #else
1156                 goto not_there;
1157 #endif
1158             if (strEQ(name, "FLT_EPSILON"))
1159 #ifdef FLT_EPSILON
1160                 return FLT_EPSILON;
1161 #else
1162                 goto not_there;
1163 #endif
1164             if (strEQ(name, "FLT_MANT_DIG"))
1165 #ifdef FLT_MANT_DIG
1166                 return FLT_MANT_DIG;
1167 #else
1168                 goto not_there;
1169 #endif
1170             if (strEQ(name, "FLT_MAX_10_EXP"))
1171 #ifdef FLT_MAX_10_EXP
1172                 return FLT_MAX_10_EXP;
1173 #else
1174                 goto not_there;
1175 #endif
1176             if (strEQ(name, "FLT_MAX_EXP"))
1177 #ifdef FLT_MAX_EXP
1178                 return FLT_MAX_EXP;
1179 #else
1180                 goto not_there;
1181 #endif
1182             if (strEQ(name, "FLT_MIN_10_EXP"))
1183 #ifdef FLT_MIN_10_EXP
1184                 return FLT_MIN_10_EXP;
1185 #else
1186                 goto not_there;
1187 #endif
1188             if (strEQ(name, "FLT_MIN_EXP"))
1189 #ifdef FLT_MIN_EXP
1190                 return FLT_MIN_EXP;
1191 #else
1192                 goto not_there;
1193 #endif
1194             if (strEQ(name, "FLT_RADIX"))
1195 #ifdef FLT_RADIX
1196                 return FLT_RADIX;
1197 #else
1198                 goto not_there;
1199 #endif
1200             break;
1201         }
1202         if (strnEQ(name, "F_", 2)) {
1203             if (strEQ(name, "F_DUPFD"))
1204 #ifdef F_DUPFD
1205                 return F_DUPFD;
1206 #else
1207                 goto not_there;
1208 #endif
1209             if (strEQ(name, "F_GETFD"))
1210 #ifdef F_GETFD
1211                 return F_GETFD;
1212 #else
1213                 goto not_there;
1214 #endif
1215             if (strEQ(name, "F_GETFL"))
1216 #ifdef F_GETFL
1217                 return F_GETFL;
1218 #else
1219                 goto not_there;
1220 #endif
1221             if (strEQ(name, "F_GETLK"))
1222 #ifdef F_GETLK
1223                 return F_GETLK;
1224 #else
1225                 goto not_there;
1226 #endif
1227             if (strEQ(name, "F_OK"))
1228 #ifdef F_OK
1229                 return F_OK;
1230 #else
1231                 goto not_there;
1232 #endif
1233             if (strEQ(name, "F_RDLCK"))
1234 #ifdef F_RDLCK
1235                 return F_RDLCK;
1236 #else
1237                 goto not_there;
1238 #endif
1239             if (strEQ(name, "F_SETFD"))
1240 #ifdef F_SETFD
1241                 return F_SETFD;
1242 #else
1243                 goto not_there;
1244 #endif
1245             if (strEQ(name, "F_SETFL"))
1246 #ifdef F_SETFL
1247                 return F_SETFL;
1248 #else
1249                 goto not_there;
1250 #endif
1251             if (strEQ(name, "F_SETLK"))
1252 #ifdef F_SETLK
1253                 return F_SETLK;
1254 #else
1255                 goto not_there;
1256 #endif
1257             if (strEQ(name, "F_SETLKW"))
1258 #ifdef F_SETLKW
1259                 return F_SETLKW;
1260 #else
1261                 goto not_there;
1262 #endif
1263             if (strEQ(name, "F_UNLCK"))
1264 #ifdef F_UNLCK
1265                 return F_UNLCK;
1266 #else
1267                 goto not_there;
1268 #endif
1269             if (strEQ(name, "F_WRLCK"))
1270 #ifdef F_WRLCK
1271                 return F_WRLCK;
1272 #else
1273                 goto not_there;
1274 #endif
1275             break;
1276         }
1277         if (strEQ(name, "FD_CLOEXEC"))
1278 #ifdef FD_CLOEXEC
1279             return FD_CLOEXEC;
1280 #else
1281             goto not_there;
1282 #endif
1283         if (strEQ(name, "FILENAME_MAX"))
1284 #ifdef FILENAME_MAX
1285             return FILENAME_MAX;
1286 #else
1287             goto not_there;
1288 #endif
1289         break;
1290     case 'H':
1291         if (strEQ(name, "HUGE_VAL"))
1292 #ifdef HUGE_VAL
1293             return HUGE_VAL;
1294 #else
1295             goto not_there;
1296 #endif
1297         if (strEQ(name, "HUPCL"))
1298 #ifdef HUPCL
1299             return HUPCL;
1300 #else
1301             goto not_there;
1302 #endif
1303         break;
1304     case 'I':
1305         if (strEQ(name, "INT_MAX"))
1306 #ifdef INT_MAX
1307             return INT_MAX;
1308 #else
1309             goto not_there;
1310 #endif
1311         if (strEQ(name, "INT_MIN"))
1312 #ifdef INT_MIN
1313             return INT_MIN;
1314 #else
1315             goto not_there;
1316 #endif
1317         if (strEQ(name, "ICANON"))
1318 #ifdef ICANON
1319             return ICANON;
1320 #else
1321             goto not_there;
1322 #endif
1323         if (strEQ(name, "ICRNL"))
1324 #ifdef ICRNL
1325             return ICRNL;
1326 #else
1327             goto not_there;
1328 #endif
1329         if (strEQ(name, "IEXTEN"))
1330 #ifdef IEXTEN
1331             return IEXTEN;
1332 #else
1333             goto not_there;
1334 #endif
1335         if (strEQ(name, "IGNBRK"))
1336 #ifdef IGNBRK
1337             return IGNBRK;
1338 #else
1339             goto not_there;
1340 #endif
1341         if (strEQ(name, "IGNCR"))
1342 #ifdef IGNCR
1343             return IGNCR;
1344 #else
1345             goto not_there;
1346 #endif
1347         if (strEQ(name, "IGNPAR"))
1348 #ifdef IGNPAR
1349             return IGNPAR;
1350 #else
1351             goto not_there;
1352 #endif
1353         if (strEQ(name, "INLCR"))
1354 #ifdef INLCR
1355             return INLCR;
1356 #else
1357             goto not_there;
1358 #endif
1359         if (strEQ(name, "INPCK"))
1360 #ifdef INPCK
1361             return INPCK;
1362 #else
1363             goto not_there;
1364 #endif
1365         if (strEQ(name, "ISIG"))
1366 #ifdef ISIG
1367             return ISIG;
1368 #else
1369             goto not_there;
1370 #endif
1371         if (strEQ(name, "ISTRIP"))
1372 #ifdef ISTRIP
1373             return ISTRIP;
1374 #else
1375             goto not_there;
1376 #endif
1377         if (strEQ(name, "IXOFF"))
1378 #ifdef IXOFF
1379             return IXOFF;
1380 #else
1381             goto not_there;
1382 #endif
1383         if (strEQ(name, "IXON"))
1384 #ifdef IXON
1385             return IXON;
1386 #else
1387             goto not_there;
1388 #endif
1389         break;
1390     case 'L':
1391         if (strnEQ(name, "LC_", 3)) {
1392             if (strEQ(name, "LC_ALL"))
1393 #ifdef LC_ALL
1394                 return LC_ALL;
1395 #else
1396                 goto not_there;
1397 #endif
1398             if (strEQ(name, "LC_COLLATE"))
1399 #ifdef LC_COLLATE
1400                 return LC_COLLATE;
1401 #else
1402                 goto not_there;
1403 #endif
1404             if (strEQ(name, "LC_CTYPE"))
1405 #ifdef LC_CTYPE
1406                 return LC_CTYPE;
1407 #else
1408                 goto not_there;
1409 #endif
1410             if (strEQ(name, "LC_MONETARY"))
1411 #ifdef LC_MONETARY
1412                 return LC_MONETARY;
1413 #else
1414                 goto not_there;
1415 #endif
1416             if (strEQ(name, "LC_NUMERIC"))
1417 #ifdef LC_NUMERIC
1418                 return LC_NUMERIC;
1419 #else
1420                 goto not_there;
1421 #endif
1422             if (strEQ(name, "LC_TIME"))
1423 #ifdef LC_TIME
1424                 return LC_TIME;
1425 #else
1426                 goto not_there;
1427 #endif
1428             break;
1429         }
1430         if (strnEQ(name, "LDBL_", 5)) {
1431             if (strEQ(name, "LDBL_MAX"))
1432 #ifdef LDBL_MAX
1433                 return LDBL_MAX;
1434 #else
1435                 goto not_there;
1436 #endif
1437             if (strEQ(name, "LDBL_MIN"))
1438 #ifdef LDBL_MIN
1439                 return LDBL_MIN;
1440 #else
1441                 goto not_there;
1442 #endif
1443             if (strEQ(name, "LDBL_DIG"))
1444 #ifdef LDBL_DIG
1445                 return LDBL_DIG;
1446 #else
1447                 goto not_there;
1448 #endif
1449             if (strEQ(name, "LDBL_EPSILON"))
1450 #ifdef LDBL_EPSILON
1451                 return LDBL_EPSILON;
1452 #else
1453                 goto not_there;
1454 #endif
1455             if (strEQ(name, "LDBL_MANT_DIG"))
1456 #ifdef LDBL_MANT_DIG
1457                 return LDBL_MANT_DIG;
1458 #else
1459                 goto not_there;
1460 #endif
1461             if (strEQ(name, "LDBL_MAX_10_EXP"))
1462 #ifdef LDBL_MAX_10_EXP
1463                 return LDBL_MAX_10_EXP;
1464 #else
1465                 goto not_there;
1466 #endif
1467             if (strEQ(name, "LDBL_MAX_EXP"))
1468 #ifdef LDBL_MAX_EXP
1469                 return LDBL_MAX_EXP;
1470 #else
1471                 goto not_there;
1472 #endif
1473             if (strEQ(name, "LDBL_MIN_10_EXP"))
1474 #ifdef LDBL_MIN_10_EXP
1475                 return LDBL_MIN_10_EXP;
1476 #else
1477                 goto not_there;
1478 #endif
1479             if (strEQ(name, "LDBL_MIN_EXP"))
1480 #ifdef LDBL_MIN_EXP
1481                 return LDBL_MIN_EXP;
1482 #else
1483                 goto not_there;
1484 #endif
1485             break;
1486         }
1487         if (strnEQ(name, "L_", 2)) {
1488             if (strEQ(name, "L_ctermid"))
1489 #ifdef L_ctermid
1490                 return L_ctermid;
1491 #else
1492                 goto not_there;
1493 #endif
1494             if (strEQ(name, "L_cuserid"))
1495 #ifdef L_cuserid
1496                 return L_cuserid;
1497 #else
1498                 goto not_there;
1499 #endif
1500             if (strEQ(name, "L_tmpname"))
1501 #ifdef L_tmpname
1502                 return L_tmpname;
1503 #else
1504                 goto not_there;
1505 #endif
1506             break;
1507         }
1508         if (strEQ(name, "LONG_MAX"))
1509 #ifdef LONG_MAX
1510             return LONG_MAX;
1511 #else
1512             goto not_there;
1513 #endif
1514         if (strEQ(name, "LONG_MIN"))
1515 #ifdef LONG_MIN
1516             return LONG_MIN;
1517 #else
1518             goto not_there;
1519 #endif
1520         if (strEQ(name, "LINK_MAX"))
1521 #ifdef LINK_MAX
1522             return LINK_MAX;
1523 #else
1524             goto not_there;
1525 #endif
1526         break;
1527     case 'M':
1528         if (strEQ(name, "MAX_CANON"))
1529 #ifdef MAX_CANON
1530             return MAX_CANON;
1531 #else
1532             goto not_there;
1533 #endif
1534         if (strEQ(name, "MAX_INPUT"))
1535 #ifdef MAX_INPUT
1536             return MAX_INPUT;
1537 #else
1538             goto not_there;
1539 #endif
1540         if (strEQ(name, "MB_CUR_MAX"))
1541 #ifdef MB_CUR_MAX
1542             return MB_CUR_MAX;
1543 #else
1544             goto not_there;
1545 #endif
1546         if (strEQ(name, "MB_LEN_MAX"))
1547 #ifdef MB_LEN_MAX
1548             return MB_LEN_MAX;
1549 #else
1550             goto not_there;
1551 #endif
1552         break;
1553     case 'N':
1554         if (strEQ(name, "NULL")) return 0;
1555         if (strEQ(name, "NAME_MAX"))
1556 #ifdef NAME_MAX
1557             return NAME_MAX;
1558 #else
1559             goto not_there;
1560 #endif
1561         if (strEQ(name, "NCCS"))
1562 #ifdef NCCS
1563             return NCCS;
1564 #else
1565             goto not_there;
1566 #endif
1567         if (strEQ(name, "NGROUPS_MAX"))
1568 #ifdef NGROUPS_MAX
1569             return NGROUPS_MAX;
1570 #else
1571             goto not_there;
1572 #endif
1573         if (strEQ(name, "NOFLSH"))
1574 #ifdef NOFLSH
1575             return NOFLSH;
1576 #else
1577             goto not_there;
1578 #endif
1579         break;
1580     case 'O':
1581         if (strnEQ(name, "O_", 2)) {
1582             if (strEQ(name, "O_APPEND"))
1583 #ifdef O_APPEND
1584                 return O_APPEND;
1585 #else
1586                 goto not_there;
1587 #endif
1588             if (strEQ(name, "O_CREAT"))
1589 #ifdef O_CREAT
1590                 return O_CREAT;
1591 #else
1592                 goto not_there;
1593 #endif
1594             if (strEQ(name, "O_TRUNC"))
1595 #ifdef O_TRUNC
1596                 return O_TRUNC;
1597 #else
1598                 goto not_there;
1599 #endif
1600             if (strEQ(name, "O_RDONLY"))
1601 #ifdef O_RDONLY
1602                 return O_RDONLY;
1603 #else
1604                 goto not_there;
1605 #endif
1606             if (strEQ(name, "O_RDWR"))
1607 #ifdef O_RDWR
1608                 return O_RDWR;
1609 #else
1610                 goto not_there;
1611 #endif
1612             if (strEQ(name, "O_WRONLY"))
1613 #ifdef O_WRONLY
1614                 return O_WRONLY;
1615 #else
1616                 goto not_there;
1617 #endif
1618             if (strEQ(name, "O_EXCL"))
1619 #ifdef O_EXCL
1620                 return O_EXCL;
1621 #else
1622                 goto not_there;
1623 #endif
1624             if (strEQ(name, "O_NOCTTY"))
1625 #ifdef O_NOCTTY
1626                 return O_NOCTTY;
1627 #else
1628                 goto not_there;
1629 #endif
1630             if (strEQ(name, "O_NONBLOCK"))
1631 #ifdef O_NONBLOCK
1632                 return O_NONBLOCK;
1633 #else
1634                 goto not_there;
1635 #endif
1636             if (strEQ(name, "O_ACCMODE"))
1637 #ifdef O_ACCMODE
1638                 return O_ACCMODE;
1639 #else
1640                 goto not_there;
1641 #endif
1642             break;
1643         }
1644         if (strEQ(name, "OPEN_MAX"))
1645 #ifdef OPEN_MAX
1646             return OPEN_MAX;
1647 #else
1648             goto not_there;
1649 #endif
1650         if (strEQ(name, "OPOST"))
1651 #ifdef OPOST
1652             return OPOST;
1653 #else
1654             goto not_there;
1655 #endif
1656         break;
1657     case 'P':
1658         if (strEQ(name, "PATH_MAX"))
1659 #ifdef PATH_MAX
1660             return PATH_MAX;
1661 #else
1662             goto not_there;
1663 #endif
1664         if (strEQ(name, "PARENB"))
1665 #ifdef PARENB
1666             return PARENB;
1667 #else
1668             goto not_there;
1669 #endif
1670         if (strEQ(name, "PARMRK"))
1671 #ifdef PARMRK
1672             return PARMRK;
1673 #else
1674             goto not_there;
1675 #endif
1676         if (strEQ(name, "PARODD"))
1677 #ifdef PARODD
1678             return PARODD;
1679 #else
1680             goto not_there;
1681 #endif
1682         if (strEQ(name, "PIPE_BUF"))
1683 #ifdef PIPE_BUF
1684             return PIPE_BUF;
1685 #else
1686             goto not_there;
1687 #endif
1688         break;
1689     case 'R':
1690         if (strEQ(name, "RAND_MAX"))
1691 #ifdef RAND_MAX
1692             return RAND_MAX;
1693 #else
1694             goto not_there;
1695 #endif
1696         if (strEQ(name, "R_OK"))
1697 #ifdef R_OK
1698             return R_OK;
1699 #else
1700             goto not_there;
1701 #endif
1702         break;
1703     case 'S':
1704         if (strnEQ(name, "SIG", 3)) {
1705             if (name[3] == '_') {
1706                 if (strEQ(name, "SIG_BLOCK"))
1707 #ifdef SIG_BLOCK
1708                     return SIG_BLOCK;
1709 #else
1710                     goto not_there;
1711 #endif
1712 #ifdef SIG_DFL
1713                 if (strEQ(name, "SIG_DFL")) return (IV)SIG_DFL;
1714 #endif
1715 #ifdef SIG_ERR
1716                 if (strEQ(name, "SIG_ERR")) return (IV)SIG_ERR;
1717 #endif
1718 #ifdef SIG_IGN
1719                 if (strEQ(name, "SIG_IGN")) return (IV)SIG_IGN;
1720 #endif
1721                 if (strEQ(name, "SIG_SETMASK"))
1722 #ifdef SIG_SETMASK
1723                     return SIG_SETMASK;
1724 #else
1725                     goto not_there;
1726 #endif
1727                 if (strEQ(name, "SIG_UNBLOCK"))
1728 #ifdef SIG_UNBLOCK
1729                     return SIG_UNBLOCK;
1730 #else
1731                     goto not_there;
1732 #endif
1733                 break;
1734             }
1735             if (strEQ(name, "SIGABRT"))
1736 #ifdef SIGABRT
1737                 return SIGABRT;
1738 #else
1739                 goto not_there;
1740 #endif
1741             if (strEQ(name, "SIGALRM"))
1742 #ifdef SIGALRM
1743                 return SIGALRM;
1744 #else
1745                 goto not_there;
1746 #endif
1747             if (strEQ(name, "SIGCHLD"))
1748 #ifdef SIGCHLD
1749                 return SIGCHLD;
1750 #else
1751                 goto not_there;
1752 #endif
1753             if (strEQ(name, "SIGCONT"))
1754 #ifdef SIGCONT
1755                 return SIGCONT;
1756 #else
1757                 goto not_there;
1758 #endif
1759             if (strEQ(name, "SIGFPE"))
1760 #ifdef SIGFPE
1761                 return SIGFPE;
1762 #else
1763                 goto not_there;
1764 #endif
1765             if (strEQ(name, "SIGHUP"))
1766 #ifdef SIGHUP
1767                 return SIGHUP;
1768 #else
1769                 goto not_there;
1770 #endif
1771             if (strEQ(name, "SIGILL"))
1772 #ifdef SIGILL
1773                 return SIGILL;
1774 #else
1775                 goto not_there;
1776 #endif
1777             if (strEQ(name, "SIGINT"))
1778 #ifdef SIGINT
1779                 return SIGINT;
1780 #else
1781                 goto not_there;
1782 #endif
1783             if (strEQ(name, "SIGKILL"))
1784 #ifdef SIGKILL
1785                 return SIGKILL;
1786 #else
1787                 goto not_there;
1788 #endif
1789             if (strEQ(name, "SIGPIPE"))
1790 #ifdef SIGPIPE
1791                 return SIGPIPE;
1792 #else
1793                 goto not_there;
1794 #endif
1795             if (strEQ(name, "SIGQUIT"))
1796 #ifdef SIGQUIT
1797                 return SIGQUIT;
1798 #else
1799                 goto not_there;
1800 #endif
1801             if (strEQ(name, "SIGSEGV"))
1802 #ifdef SIGSEGV
1803                 return SIGSEGV;
1804 #else
1805                 goto not_there;
1806 #endif
1807             if (strEQ(name, "SIGSTOP"))
1808 #ifdef SIGSTOP
1809                 return SIGSTOP;
1810 #else
1811                 goto not_there;
1812 #endif
1813             if (strEQ(name, "SIGTERM"))
1814 #ifdef SIGTERM
1815                 return SIGTERM;
1816 #else
1817                 goto not_there;
1818 #endif
1819             if (strEQ(name, "SIGTSTP"))
1820 #ifdef SIGTSTP
1821                 return SIGTSTP;
1822 #else
1823                 goto not_there;
1824 #endif
1825             if (strEQ(name, "SIGTTIN"))
1826 #ifdef SIGTTIN
1827                 return SIGTTIN;
1828 #else
1829                 goto not_there;
1830 #endif
1831             if (strEQ(name, "SIGTTOU"))
1832 #ifdef SIGTTOU
1833                 return SIGTTOU;
1834 #else
1835                 goto not_there;
1836 #endif
1837             if (strEQ(name, "SIGUSR1"))
1838 #ifdef SIGUSR1
1839                 return SIGUSR1;
1840 #else
1841                 goto not_there;
1842 #endif
1843             if (strEQ(name, "SIGUSR2"))
1844 #ifdef SIGUSR2
1845                 return SIGUSR2;
1846 #else
1847                 goto not_there;
1848 #endif
1849             break;
1850         }
1851         if (name[1] == '_') {
1852             if (strEQ(name, "S_ISGID"))
1853 #ifdef S_ISGID
1854                 return S_ISGID;
1855 #else
1856                 goto not_there;
1857 #endif
1858             if (strEQ(name, "S_ISUID"))
1859 #ifdef S_ISUID
1860                 return S_ISUID;
1861 #else
1862                 goto not_there;
1863 #endif
1864             if (strEQ(name, "S_IRGRP"))
1865 #ifdef S_IRGRP
1866                 return S_IRGRP;
1867 #else
1868                 goto not_there;
1869 #endif
1870             if (strEQ(name, "S_IROTH"))
1871 #ifdef S_IROTH
1872                 return S_IROTH;
1873 #else
1874                 goto not_there;
1875 #endif
1876             if (strEQ(name, "S_IRUSR"))
1877 #ifdef S_IRUSR
1878                 return S_IRUSR;
1879 #else
1880                 goto not_there;
1881 #endif
1882             if (strEQ(name, "S_IRWXG"))
1883 #ifdef S_IRWXG
1884                 return S_IRWXG;
1885 #else
1886                 goto not_there;
1887 #endif
1888             if (strEQ(name, "S_IRWXO"))
1889 #ifdef S_IRWXO
1890                 return S_IRWXO;
1891 #else
1892                 goto not_there;
1893 #endif
1894             if (strEQ(name, "S_IRWXU"))
1895 #ifdef S_IRWXU
1896                 return S_IRWXU;
1897 #else
1898                 goto not_there;
1899 #endif
1900             if (strEQ(name, "S_IWGRP"))
1901 #ifdef S_IWGRP
1902                 return S_IWGRP;
1903 #else
1904                 goto not_there;
1905 #endif
1906             if (strEQ(name, "S_IWOTH"))
1907 #ifdef S_IWOTH
1908                 return S_IWOTH;
1909 #else
1910                 goto not_there;
1911 #endif
1912             if (strEQ(name, "S_IWUSR"))
1913 #ifdef S_IWUSR
1914                 return S_IWUSR;
1915 #else
1916                 goto not_there;
1917 #endif
1918             if (strEQ(name, "S_IXGRP"))
1919 #ifdef S_IXGRP
1920                 return S_IXGRP;
1921 #else
1922                 goto not_there;
1923 #endif
1924             if (strEQ(name, "S_IXOTH"))
1925 #ifdef S_IXOTH
1926                 return S_IXOTH;
1927 #else
1928                 goto not_there;
1929 #endif
1930             if (strEQ(name, "S_IXUSR"))
1931 #ifdef S_IXUSR
1932                 return S_IXUSR;
1933 #else
1934                 goto not_there;
1935 #endif
1936             errno = EAGAIN;             /* the following aren't constants */
1937 #ifdef S_ISBLK
1938             if (strEQ(name, "S_ISBLK")) return S_ISBLK(arg);
1939 #endif
1940 #ifdef S_ISCHR
1941             if (strEQ(name, "S_ISCHR")) return S_ISCHR(arg);
1942 #endif
1943 #ifdef S_ISDIR
1944             if (strEQ(name, "S_ISDIR")) return S_ISDIR(arg);
1945 #endif
1946 #ifdef S_ISFIFO
1947             if (strEQ(name, "S_ISFIFO")) return S_ISFIFO(arg);
1948 #endif
1949 #ifdef S_ISREG
1950             if (strEQ(name, "S_ISREG")) return S_ISREG(arg);
1951 #endif
1952             break;
1953         }
1954         if (strEQ(name, "SEEK_CUR"))
1955 #ifdef SEEK_CUR
1956             return SEEK_CUR;
1957 #else
1958             goto not_there;
1959 #endif
1960         if (strEQ(name, "SEEK_END"))
1961 #ifdef SEEK_END
1962             return SEEK_END;
1963 #else
1964             goto not_there;
1965 #endif
1966         if (strEQ(name, "SEEK_SET"))
1967 #ifdef SEEK_SET
1968             return SEEK_SET;
1969 #else
1970             goto not_there;
1971 #endif
1972         if (strEQ(name, "STREAM_MAX"))
1973 #ifdef STREAM_MAX
1974             return STREAM_MAX;
1975 #else
1976             goto not_there;
1977 #endif
1978         if (strEQ(name, "SHRT_MAX"))
1979 #ifdef SHRT_MAX
1980             return SHRT_MAX;
1981 #else
1982             goto not_there;
1983 #endif
1984         if (strEQ(name, "SHRT_MIN"))
1985 #ifdef SHRT_MIN
1986             return SHRT_MIN;
1987 #else
1988             goto not_there;
1989 #endif
1990         if (strnEQ(name, "SA_", 3)) {
1991             if (strEQ(name, "SA_NOCLDSTOP"))
1992 #ifdef SA_NOCLDSTOP
1993                 return SA_NOCLDSTOP;
1994 #else
1995                 goto not_there;
1996 #endif
1997             if (strEQ(name, "SA_NOCLDWAIT"))
1998 #ifdef SA_NOCLDWAIT
1999                 return SA_NOCLDWAIT;
2000 #else
2001                 goto not_there;
2002 #endif
2003             if (strEQ(name, "SA_NODEFER"))
2004 #ifdef SA_NODEFER
2005                 return SA_NODEFER;
2006 #else
2007                 goto not_there;
2008 #endif
2009             if (strEQ(name, "SA_ONSTACK"))
2010 #ifdef SA_ONSTACK
2011                 return SA_ONSTACK;
2012 #else
2013                 goto not_there;
2014 #endif
2015             if (strEQ(name, "SA_RESETHAND"))
2016 #ifdef SA_RESETHAND
2017                 return SA_RESETHAND;
2018 #else
2019                 goto not_there;
2020 #endif
2021             if (strEQ(name, "SA_RESTART"))
2022 #ifdef SA_RESTART
2023                 return SA_RESTART;
2024 #else
2025                 goto not_there;
2026 #endif
2027             if (strEQ(name, "SA_SIGINFO"))
2028 #ifdef SA_SIGINFO
2029                 return SA_SIGINFO;
2030 #else
2031                 goto not_there;
2032 #endif
2033             break;
2034         }
2035         if (strEQ(name, "SCHAR_MAX"))
2036 #ifdef SCHAR_MAX
2037             return SCHAR_MAX;
2038 #else
2039             goto not_there;
2040 #endif
2041         if (strEQ(name, "SCHAR_MIN"))
2042 #ifdef SCHAR_MIN
2043             return SCHAR_MIN;
2044 #else
2045             goto not_there;
2046 #endif
2047         if (strEQ(name, "SSIZE_MAX"))
2048 #ifdef SSIZE_MAX
2049             return SSIZE_MAX;
2050 #else
2051             goto not_there;
2052 #endif
2053         if (strEQ(name, "STDIN_FILENO"))
2054 #ifdef STDIN_FILENO
2055             return STDIN_FILENO;
2056 #else
2057             goto not_there;
2058 #endif
2059         if (strEQ(name, "STDOUT_FILENO"))
2060 #ifdef STDOUT_FILENO
2061             return STDOUT_FILENO;
2062 #else
2063             goto not_there;
2064 #endif
2065         if (strEQ(name, "STRERR_FILENO"))
2066 #ifdef STRERR_FILENO
2067             return STRERR_FILENO;
2068 #else
2069             goto not_there;
2070 #endif
2071         break;
2072     case 'T':
2073         if (strEQ(name, "TCIFLUSH"))
2074 #ifdef TCIFLUSH
2075             return TCIFLUSH;
2076 #else
2077             goto not_there;
2078 #endif
2079         if (strEQ(name, "TCIOFF"))
2080 #ifdef TCIOFF
2081             return TCIOFF;
2082 #else
2083             goto not_there;
2084 #endif
2085         if (strEQ(name, "TCIOFLUSH"))
2086 #ifdef TCIOFLUSH
2087             return TCIOFLUSH;
2088 #else
2089             goto not_there;
2090 #endif
2091         if (strEQ(name, "TCION"))
2092 #ifdef TCION
2093             return TCION;
2094 #else
2095             goto not_there;
2096 #endif
2097         if (strEQ(name, "TCOFLUSH"))
2098 #ifdef TCOFLUSH
2099             return TCOFLUSH;
2100 #else
2101             goto not_there;
2102 #endif
2103         if (strEQ(name, "TCOOFF"))
2104 #ifdef TCOOFF
2105             return TCOOFF;
2106 #else
2107             goto not_there;
2108 #endif
2109         if (strEQ(name, "TCOON"))
2110 #ifdef TCOON
2111             return TCOON;
2112 #else
2113             goto not_there;
2114 #endif
2115         if (strEQ(name, "TCSADRAIN"))
2116 #ifdef TCSADRAIN
2117             return TCSADRAIN;
2118 #else
2119             goto not_there;
2120 #endif
2121         if (strEQ(name, "TCSAFLUSH"))
2122 #ifdef TCSAFLUSH
2123             return TCSAFLUSH;
2124 #else
2125             goto not_there;
2126 #endif
2127         if (strEQ(name, "TCSANOW"))
2128 #ifdef TCSANOW
2129             return TCSANOW;
2130 #else
2131             goto not_there;
2132 #endif
2133         if (strEQ(name, "TMP_MAX"))
2134 #ifdef TMP_MAX
2135             return TMP_MAX;
2136 #else
2137             goto not_there;
2138 #endif
2139         if (strEQ(name, "TOSTOP"))
2140 #ifdef TOSTOP
2141             return TOSTOP;
2142 #else
2143             goto not_there;
2144 #endif
2145         if (strEQ(name, "TZNAME_MAX"))
2146 #ifdef TZNAME_MAX
2147             return TZNAME_MAX;
2148 #else
2149             goto not_there;
2150 #endif
2151         break;
2152     case 'U':
2153         if (strEQ(name, "UCHAR_MAX"))
2154 #ifdef UCHAR_MAX
2155             return UCHAR_MAX;
2156 #else
2157             goto not_there;
2158 #endif
2159         if (strEQ(name, "UINT_MAX"))
2160 #ifdef UINT_MAX
2161             return UINT_MAX;
2162 #else
2163             goto not_there;
2164 #endif
2165         if (strEQ(name, "ULONG_MAX"))
2166 #ifdef ULONG_MAX
2167             return ULONG_MAX;
2168 #else
2169             goto not_there;
2170 #endif
2171         if (strEQ(name, "USHRT_MAX"))
2172 #ifdef USHRT_MAX
2173             return USHRT_MAX;
2174 #else
2175             goto not_there;
2176 #endif
2177         break;
2178     case 'V':
2179         if (strEQ(name, "VEOF"))
2180 #ifdef VEOF
2181             return VEOF;
2182 #else
2183             goto not_there;
2184 #endif
2185         if (strEQ(name, "VEOL"))
2186 #ifdef VEOL
2187             return VEOL;
2188 #else
2189             goto not_there;
2190 #endif
2191         if (strEQ(name, "VERASE"))
2192 #ifdef VERASE
2193             return VERASE;
2194 #else
2195             goto not_there;
2196 #endif
2197         if (strEQ(name, "VINTR"))
2198 #ifdef VINTR
2199             return VINTR;
2200 #else
2201             goto not_there;
2202 #endif
2203         if (strEQ(name, "VKILL"))
2204 #ifdef VKILL
2205             return VKILL;
2206 #else
2207             goto not_there;
2208 #endif
2209         if (strEQ(name, "VMIN"))
2210 #ifdef VMIN
2211             return VMIN;
2212 #else
2213             goto not_there;
2214 #endif
2215         if (strEQ(name, "VQUIT"))
2216 #ifdef VQUIT
2217             return VQUIT;
2218 #else
2219             goto not_there;
2220 #endif
2221         if (strEQ(name, "VSTART"))
2222 #ifdef VSTART
2223             return VSTART;
2224 #else
2225             goto not_there;
2226 #endif
2227         if (strEQ(name, "VSTOP"))
2228 #ifdef VSTOP
2229             return VSTOP;
2230 #else
2231             goto not_there;
2232 #endif
2233         if (strEQ(name, "VSUSP"))
2234 #ifdef VSUSP
2235             return VSUSP;
2236 #else
2237             goto not_there;
2238 #endif
2239         if (strEQ(name, "VTIME"))
2240 #ifdef VTIME
2241             return VTIME;
2242 #else
2243             goto not_there;
2244 #endif
2245         break;
2246     case 'W':
2247         if (strEQ(name, "W_OK"))
2248 #ifdef W_OK
2249             return W_OK;
2250 #else
2251             goto not_there;
2252 #endif
2253         if (strEQ(name, "WNOHANG"))
2254 #ifdef WNOHANG
2255             return WNOHANG;
2256 #else
2257             goto not_there;
2258 #endif
2259         if (strEQ(name, "WUNTRACED"))
2260 #ifdef WUNTRACED
2261             return WUNTRACED;
2262 #else
2263             goto not_there;
2264 #endif
2265         errno = EAGAIN;         /* the following aren't constants */
2266 #ifdef WEXITSTATUS
2267         if (strEQ(name, "WEXITSTATUS")) return WEXITSTATUS(arg);
2268 #endif
2269 #ifdef WIFEXITED
2270         if (strEQ(name, "WIFEXITED")) return WIFEXITED(arg);
2271 #endif
2272 #ifdef WIFSIGNALED
2273         if (strEQ(name, "WIFSIGNALED")) return WIFSIGNALED(arg);
2274 #endif
2275 #ifdef WIFSTOPPED
2276         if (strEQ(name, "WIFSTOPPED")) return WIFSTOPPED(arg);
2277 #endif
2278 #ifdef WSTOPSIG
2279         if (strEQ(name, "WSTOPSIG")) return WSTOPSIG(arg);
2280 #endif
2281 #ifdef WTERMSIG
2282         if (strEQ(name, "WTERMSIG")) return WTERMSIG(arg);
2283 #endif
2284         break;
2285     case 'X':
2286         if (strEQ(name, "X_OK"))
2287 #ifdef X_OK
2288             return X_OK;
2289 #else
2290             goto not_there;
2291 #endif
2292         break;
2293     case '_':
2294         if (strnEQ(name, "_PC_", 4)) {
2295             if (strEQ(name, "_PC_CHOWN_RESTRICTED"))
2296 #if defined(_PC_CHOWN_RESTRICTED) || HINT_SC_EXIST
2297                 return _PC_CHOWN_RESTRICTED;
2298 #else
2299                 goto not_there;
2300 #endif
2301             if (strEQ(name, "_PC_LINK_MAX"))
2302 #if defined(_PC_LINK_MAX) || HINT_SC_EXIST
2303                 return _PC_LINK_MAX;
2304 #else
2305                 goto not_there;
2306 #endif
2307             if (strEQ(name, "_PC_MAX_CANON"))
2308 #if defined(_PC_MAX_CANON) || HINT_SC_EXIST
2309                 return _PC_MAX_CANON;
2310 #else
2311                 goto not_there;
2312 #endif
2313             if (strEQ(name, "_PC_MAX_INPUT"))
2314 #if defined(_PC_MAX_INPUT) || HINT_SC_EXIST
2315                 return _PC_MAX_INPUT;
2316 #else
2317                 goto not_there;
2318 #endif
2319             if (strEQ(name, "_PC_NAME_MAX"))
2320 #if defined(_PC_NAME_MAX) || HINT_SC_EXIST
2321                 return _PC_NAME_MAX;
2322 #else
2323                 goto not_there;
2324 #endif
2325             if (strEQ(name, "_PC_NO_TRUNC"))
2326 #if defined(_PC_NO_TRUNC) || HINT_SC_EXIST
2327                 return _PC_NO_TRUNC;
2328 #else
2329                 goto not_there;
2330 #endif
2331             if (strEQ(name, "_PC_PATH_MAX"))
2332 #if defined(_PC_PATH_MAX) || HINT_SC_EXIST
2333                 return _PC_PATH_MAX;
2334 #else
2335                 goto not_there;
2336 #endif
2337             if (strEQ(name, "_PC_PIPE_BUF"))
2338 #if defined(_PC_PIPE_BUF) || HINT_SC_EXIST
2339                 return _PC_PIPE_BUF;
2340 #else
2341                 goto not_there;
2342 #endif
2343             if (strEQ(name, "_PC_VDISABLE"))
2344 #if defined(_PC_VDISABLE) || HINT_SC_EXIST
2345                 return _PC_VDISABLE;
2346 #else
2347                 goto not_there;
2348 #endif
2349             break;
2350         }
2351         if (strnEQ(name, "_POSIX_", 7)) {
2352             if (strEQ(name, "_POSIX_ARG_MAX"))
2353 #ifdef _POSIX_ARG_MAX
2354                 return _POSIX_ARG_MAX;
2355 #else
2356                 return 0;
2357 #endif
2358             if (strEQ(name, "_POSIX_CHILD_MAX"))
2359 #ifdef _POSIX_CHILD_MAX
2360                 return _POSIX_CHILD_MAX;
2361 #else
2362                 return 0;
2363 #endif
2364             if (strEQ(name, "_POSIX_CHOWN_RESTRICTED"))
2365 #ifdef _POSIX_CHOWN_RESTRICTED
2366                 return _POSIX_CHOWN_RESTRICTED;
2367 #else
2368                 return 0;
2369 #endif
2370             if (strEQ(name, "_POSIX_JOB_CONTROL"))
2371 #ifdef _POSIX_JOB_CONTROL
2372                 return _POSIX_JOB_CONTROL;
2373 #else
2374                 return 0;
2375 #endif
2376             if (strEQ(name, "_POSIX_LINK_MAX"))
2377 #ifdef _POSIX_LINK_MAX
2378                 return _POSIX_LINK_MAX;
2379 #else
2380                 return 0;
2381 #endif
2382             if (strEQ(name, "_POSIX_MAX_CANON"))
2383 #ifdef _POSIX_MAX_CANON
2384                 return _POSIX_MAX_CANON;
2385 #else
2386                 return 0;
2387 #endif
2388             if (strEQ(name, "_POSIX_MAX_INPUT"))
2389 #ifdef _POSIX_MAX_INPUT
2390                 return _POSIX_MAX_INPUT;
2391 #else
2392                 return 0;
2393 #endif
2394             if (strEQ(name, "_POSIX_NAME_MAX"))
2395 #ifdef _POSIX_NAME_MAX
2396                 return _POSIX_NAME_MAX;
2397 #else
2398                 return 0;
2399 #endif
2400             if (strEQ(name, "_POSIX_NGROUPS_MAX"))
2401 #ifdef _POSIX_NGROUPS_MAX
2402                 return _POSIX_NGROUPS_MAX;
2403 #else
2404                 return 0;
2405 #endif
2406             if (strEQ(name, "_POSIX_NO_TRUNC"))
2407 #ifdef _POSIX_NO_TRUNC
2408                 return _POSIX_NO_TRUNC;
2409 #else
2410                 return 0;
2411 #endif
2412             if (strEQ(name, "_POSIX_OPEN_MAX"))
2413 #ifdef _POSIX_OPEN_MAX
2414                 return _POSIX_OPEN_MAX;
2415 #else
2416                 return 0;
2417 #endif
2418             if (strEQ(name, "_POSIX_PATH_MAX"))
2419 #ifdef _POSIX_PATH_MAX
2420                 return _POSIX_PATH_MAX;
2421 #else
2422                 return 0;
2423 #endif
2424             if (strEQ(name, "_POSIX_PIPE_BUF"))
2425 #ifdef _POSIX_PIPE_BUF
2426                 return _POSIX_PIPE_BUF;
2427 #else
2428                 return 0;
2429 #endif
2430             if (strEQ(name, "_POSIX_SAVED_IDS"))
2431 #ifdef _POSIX_SAVED_IDS
2432                 return _POSIX_SAVED_IDS;
2433 #else
2434                 return 0;
2435 #endif
2436             if (strEQ(name, "_POSIX_SSIZE_MAX"))
2437 #ifdef _POSIX_SSIZE_MAX
2438                 return _POSIX_SSIZE_MAX;
2439 #else
2440                 return 0;
2441 #endif
2442             if (strEQ(name, "_POSIX_STREAM_MAX"))
2443 #ifdef _POSIX_STREAM_MAX
2444                 return _POSIX_STREAM_MAX;
2445 #else
2446                 return 0;
2447 #endif
2448             if (strEQ(name, "_POSIX_TZNAME_MAX"))
2449 #ifdef _POSIX_TZNAME_MAX
2450                 return _POSIX_TZNAME_MAX;
2451 #else
2452                 return 0;
2453 #endif
2454             if (strEQ(name, "_POSIX_VDISABLE"))
2455 #ifdef _POSIX_VDISABLE
2456                 return _POSIX_VDISABLE;
2457 #else
2458                 return 0;
2459 #endif
2460             if (strEQ(name, "_POSIX_VERSION"))
2461 #ifdef _POSIX_VERSION
2462                 return _POSIX_VERSION;
2463 #else
2464                 return 0;
2465 #endif
2466             break;
2467         }
2468         if (strnEQ(name, "_SC_", 4)) {
2469             if (strEQ(name, "_SC_ARG_MAX"))
2470 #if defined(_SC_ARG_MAX) || HINT_SC_EXIST
2471                 return _SC_ARG_MAX;
2472 #else
2473                 goto not_there;
2474 #endif
2475             if (strEQ(name, "_SC_CHILD_MAX"))
2476 #if defined(_SC_CHILD_MAX) || HINT_SC_EXIST
2477                 return _SC_CHILD_MAX;
2478 #else
2479                 goto not_there;
2480 #endif
2481             if (strEQ(name, "_SC_CLK_TCK"))
2482 #if defined(_SC_CLK_TCK) || HINT_SC_EXIST
2483                 return _SC_CLK_TCK;
2484 #else
2485                 goto not_there;
2486 #endif
2487             if (strEQ(name, "_SC_JOB_CONTROL"))
2488 #if defined(_SC_JOB_CONTROL) || HINT_SC_EXIST
2489                 return _SC_JOB_CONTROL;
2490 #else
2491                 goto not_there;
2492 #endif
2493             if (strEQ(name, "_SC_NGROUPS_MAX"))
2494 #if defined(_SC_NGROUPS_MAX) || HINT_SC_EXIST
2495                 return _SC_NGROUPS_MAX;
2496 #else
2497                 goto not_there;
2498 #endif
2499             if (strEQ(name, "_SC_OPEN_MAX"))
2500 #if defined(_SC_OPEN_MAX) || HINT_SC_EXIST
2501                 return _SC_OPEN_MAX;
2502 #else
2503                 goto not_there;
2504 #endif
2505             if (strEQ(name, "_SC_SAVED_IDS"))
2506 #if defined(_SC_SAVED_IDS) || HINT_SC_EXIST
2507                 return _SC_SAVED_IDS;
2508 #else
2509                 goto not_there;
2510 #endif
2511             if (strEQ(name, "_SC_STREAM_MAX"))
2512 #if defined(_SC_STREAM_MAX) || HINT_SC_EXIST
2513                 return _SC_STREAM_MAX;
2514 #else
2515                 goto not_there;
2516 #endif
2517             if (strEQ(name, "_SC_TZNAME_MAX"))
2518 #if defined(_SC_TZNAME_MAX) || HINT_SC_EXIST
2519                 return _SC_TZNAME_MAX;
2520 #else
2521                 goto not_there;
2522 #endif
2523             if (strEQ(name, "_SC_VERSION"))
2524 #if defined(_SC_VERSION) || HINT_SC_EXIST
2525                 return _SC_VERSION;
2526 #else
2527                 goto not_there;
2528 #endif
2529             break;
2530         }
2531     }
2532     errno = EINVAL;
2533     return 0;
2534
2535 not_there:
2536     errno = ENOENT;
2537     return 0;
2538 }
2539
2540 MODULE = SigSet         PACKAGE = POSIX::SigSet         PREFIX = sig
2541
2542 POSIX::SigSet
2543 new(packname = "POSIX::SigSet", ...)
2544     char *              packname
2545     CODE:
2546         {
2547             int i;
2548             RETVAL = (sigset_t*)safemalloc(sizeof(sigset_t));
2549             sigemptyset(RETVAL);
2550             for (i = 1; i < items; i++)
2551                 sigaddset(RETVAL, SvIV(ST(i)));
2552         }
2553     OUTPUT:
2554         RETVAL
2555
2556 void
2557 DESTROY(sigset)
2558         POSIX::SigSet   sigset
2559     CODE:
2560         safefree((char *)sigset);
2561
2562 SysRet
2563 sigaddset(sigset, sig)
2564         POSIX::SigSet   sigset
2565         int             sig
2566
2567 SysRet
2568 sigdelset(sigset, sig)
2569         POSIX::SigSet   sigset
2570         int             sig
2571
2572 SysRet
2573 sigemptyset(sigset)
2574         POSIX::SigSet   sigset
2575
2576 SysRet
2577 sigfillset(sigset)
2578         POSIX::SigSet   sigset
2579
2580 int
2581 sigismember(sigset, sig)
2582         POSIX::SigSet   sigset
2583         int             sig
2584
2585
2586 MODULE = Termios        PACKAGE = POSIX::Termios        PREFIX = cf
2587
2588 POSIX::Termios
2589 new(packname = "POSIX::Termios", ...)
2590     char *              packname
2591     CODE:
2592         {
2593 #ifdef I_TERMIOS
2594             RETVAL = (struct termios*)safemalloc(sizeof(struct termios));
2595 #else
2596             not_here("termios");
2597         RETVAL = 0;
2598 #endif
2599         }
2600     OUTPUT:
2601         RETVAL
2602
2603 void
2604 DESTROY(termios_ref)
2605         POSIX::Termios  termios_ref
2606     CODE:
2607 #ifdef I_TERMIOS
2608         safefree((char *)termios_ref);
2609 #else
2610             not_here("termios");
2611 #endif
2612
2613 SysRet
2614 getattr(termios_ref, fd = 0)
2615         POSIX::Termios  termios_ref
2616         int             fd
2617     CODE:
2618         RETVAL = tcgetattr(fd, termios_ref);
2619     OUTPUT:
2620         RETVAL
2621
2622 SysRet
2623 setattr(termios_ref, fd = 0, optional_actions = 0)
2624         POSIX::Termios  termios_ref
2625         int             fd
2626         int             optional_actions
2627     CODE:
2628         RETVAL = tcsetattr(fd, optional_actions, termios_ref);
2629     OUTPUT:
2630         RETVAL
2631
2632 speed_t
2633 cfgetispeed(termios_ref)
2634         POSIX::Termios  termios_ref
2635
2636 speed_t
2637 cfgetospeed(termios_ref)
2638         POSIX::Termios  termios_ref
2639
2640 tcflag_t
2641 getiflag(termios_ref)
2642         POSIX::Termios  termios_ref
2643     CODE:
2644 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2645         RETVAL = termios_ref->c_iflag;
2646 #else
2647      not_here("getiflag");
2648      RETVAL = 0;
2649 #endif
2650     OUTPUT:
2651         RETVAL
2652
2653 tcflag_t
2654 getoflag(termios_ref)
2655         POSIX::Termios  termios_ref
2656     CODE:
2657 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2658         RETVAL = termios_ref->c_oflag;
2659 #else
2660      not_here("getoflag");
2661      RETVAL = 0;
2662 #endif
2663     OUTPUT:
2664         RETVAL
2665
2666 tcflag_t
2667 getcflag(termios_ref)
2668         POSIX::Termios  termios_ref
2669     CODE:
2670 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2671         RETVAL = termios_ref->c_cflag;
2672 #else
2673      not_here("getcflag");
2674      RETVAL = 0;
2675 #endif
2676     OUTPUT:
2677         RETVAL
2678
2679 tcflag_t
2680 getlflag(termios_ref)
2681         POSIX::Termios  termios_ref
2682     CODE:
2683 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2684         RETVAL = termios_ref->c_lflag;
2685 #else
2686      not_here("getlflag");
2687      RETVAL = 0;
2688 #endif
2689     OUTPUT:
2690         RETVAL
2691
2692 cc_t
2693 getcc(termios_ref, ccix)
2694         POSIX::Termios  termios_ref
2695         int             ccix
2696     CODE:
2697 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2698         if (ccix >= NCCS)
2699             croak("Bad getcc subscript");
2700         RETVAL = termios_ref->c_cc[ccix];
2701 #else
2702      not_here("getcc");
2703      RETVAL = 0;
2704 #endif
2705     OUTPUT:
2706         RETVAL
2707
2708 SysRet
2709 cfsetispeed(termios_ref, speed)
2710         POSIX::Termios  termios_ref
2711         speed_t         speed
2712
2713 SysRet
2714 cfsetospeed(termios_ref, speed)
2715         POSIX::Termios  termios_ref
2716         speed_t         speed
2717
2718 void
2719 setiflag(termios_ref, iflag)
2720         POSIX::Termios  termios_ref
2721         tcflag_t        iflag
2722     CODE:
2723 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2724         termios_ref->c_iflag = iflag;
2725 #else
2726             not_here("setiflag");
2727 #endif
2728
2729 void
2730 setoflag(termios_ref, oflag)
2731         POSIX::Termios  termios_ref
2732         tcflag_t        oflag
2733     CODE:
2734 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2735         termios_ref->c_oflag = oflag;
2736 #else
2737             not_here("setoflag");
2738 #endif
2739
2740 void
2741 setcflag(termios_ref, cflag)
2742         POSIX::Termios  termios_ref
2743         tcflag_t        cflag
2744     CODE:
2745 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2746         termios_ref->c_cflag = cflag;
2747 #else
2748             not_here("setcflag");
2749 #endif
2750
2751 void
2752 setlflag(termios_ref, lflag)
2753         POSIX::Termios  termios_ref
2754         tcflag_t        lflag
2755     CODE:
2756 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2757         termios_ref->c_lflag = lflag;
2758 #else
2759             not_here("setlflag");
2760 #endif
2761
2762 void
2763 setcc(termios_ref, ccix, cc)
2764         POSIX::Termios  termios_ref
2765         int             ccix
2766         cc_t            cc
2767     CODE:
2768 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2769         if (ccix >= NCCS)
2770             croak("Bad setcc subscript");
2771         termios_ref->c_cc[ccix] = cc;
2772 #else
2773             not_here("setcc");
2774 #endif
2775
2776
2777 MODULE = POSIX          PACKAGE = POSIX
2778
2779 double
2780 constant(name,arg)
2781         char *          name
2782         int             arg
2783
2784 int
2785 isalnum(charstring)
2786         unsigned char * charstring
2787     CODE:
2788         unsigned char *s = charstring;
2789         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2790         for (RETVAL = 1; RETVAL && s < e; s++)
2791             if (!isalnum(*s))
2792                 RETVAL = 0;
2793     OUTPUT:
2794         RETVAL
2795
2796 int
2797 isalpha(charstring)
2798         unsigned char * charstring
2799     CODE:
2800         unsigned char *s = charstring;
2801         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2802         for (RETVAL = 1; RETVAL && s < e; s++)
2803             if (!isalpha(*s))
2804                 RETVAL = 0;
2805     OUTPUT:
2806         RETVAL
2807
2808 int
2809 iscntrl(charstring)
2810         unsigned char * charstring
2811     CODE:
2812         unsigned char *s = charstring;
2813         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2814         for (RETVAL = 1; RETVAL && s < e; s++)
2815             if (!iscntrl(*s))
2816                 RETVAL = 0;
2817     OUTPUT:
2818         RETVAL
2819
2820 int
2821 isdigit(charstring)
2822         unsigned char * charstring
2823     CODE:
2824         unsigned char *s = charstring;
2825         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2826         for (RETVAL = 1; RETVAL && s < e; s++)
2827             if (!isdigit(*s))
2828                 RETVAL = 0;
2829     OUTPUT:
2830         RETVAL
2831
2832 int
2833 isgraph(charstring)
2834         unsigned char * charstring
2835     CODE:
2836         unsigned char *s = charstring;
2837         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2838         for (RETVAL = 1; RETVAL && s < e; s++)
2839             if (!isgraph(*s))
2840                 RETVAL = 0;
2841     OUTPUT:
2842         RETVAL
2843
2844 int
2845 islower(charstring)
2846         unsigned char * charstring
2847     CODE:
2848         unsigned char *s = charstring;
2849         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2850         for (RETVAL = 1; RETVAL && s < e; s++)
2851             if (!islower(*s))
2852                 RETVAL = 0;
2853     OUTPUT:
2854         RETVAL
2855
2856 int
2857 isprint(charstring)
2858         unsigned char * charstring
2859     CODE:
2860         unsigned char *s = charstring;
2861         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2862         for (RETVAL = 1; RETVAL && s < e; s++)
2863             if (!isprint(*s))
2864                 RETVAL = 0;
2865     OUTPUT:
2866         RETVAL
2867
2868 int
2869 ispunct(charstring)
2870         unsigned char * charstring
2871     CODE:
2872         unsigned char *s = charstring;
2873         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2874         for (RETVAL = 1; RETVAL && s < e; s++)
2875             if (!ispunct(*s))
2876                 RETVAL = 0;
2877     OUTPUT:
2878         RETVAL
2879
2880 int
2881 isspace(charstring)
2882         unsigned char * charstring
2883     CODE:
2884         unsigned char *s = charstring;
2885         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2886         for (RETVAL = 1; RETVAL && s < e; s++)
2887             if (!isspace(*s))
2888                 RETVAL = 0;
2889     OUTPUT:
2890         RETVAL
2891
2892 int
2893 isupper(charstring)
2894         unsigned char * charstring
2895     CODE:
2896         unsigned char *s = charstring;
2897         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2898         for (RETVAL = 1; RETVAL && s < e; s++)
2899             if (!isupper(*s))
2900                 RETVAL = 0;
2901     OUTPUT:
2902         RETVAL
2903
2904 int
2905 isxdigit(charstring)
2906         unsigned char * charstring
2907     CODE:
2908         unsigned char *s = charstring;
2909         unsigned char *e = s + na;      /* "na" set by typemap side effect */
2910         for (RETVAL = 1; RETVAL && s < e; s++)
2911             if (!isxdigit(*s))
2912                 RETVAL = 0;
2913     OUTPUT:
2914         RETVAL
2915
2916 SysRet
2917 open(filename, flags = O_RDONLY, mode = 0666)
2918         char *          filename
2919         int             flags
2920         Mode_t          mode
2921     CODE:
2922         if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
2923             TAINT_PROPER("open");
2924         RETVAL = open(filename, flags, mode);
2925     OUTPUT:
2926         RETVAL
2927
2928
2929 HV *
2930 localeconv()
2931     CODE:
2932 #ifdef HAS_LOCALECONV
2933         struct lconv *lcbuf;
2934         RETVAL = newHV();
2935         SET_NUMERIC_LOCAL();
2936         if (lcbuf = localeconv()) {
2937             /* the strings */
2938             if (lcbuf->decimal_point && *lcbuf->decimal_point)
2939                 hv_store(RETVAL, "decimal_point", 13,
2940                     newSVpv(lcbuf->decimal_point, 0), 0);
2941             if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
2942                 hv_store(RETVAL, "thousands_sep", 13,
2943                     newSVpv(lcbuf->thousands_sep, 0), 0);
2944             if (lcbuf->grouping && *lcbuf->grouping)
2945                 hv_store(RETVAL, "grouping", 8,
2946                     newSVpv(lcbuf->grouping, 0), 0);
2947             if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
2948                 hv_store(RETVAL, "int_curr_symbol", 15,
2949                     newSVpv(lcbuf->int_curr_symbol, 0), 0);
2950             if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
2951                 hv_store(RETVAL, "currency_symbol", 15,
2952                     newSVpv(lcbuf->currency_symbol, 0), 0);
2953             if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
2954                 hv_store(RETVAL, "mon_decimal_point", 17,
2955                     newSVpv(lcbuf->mon_decimal_point, 0), 0);
2956 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
2957             if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
2958                 hv_store(RETVAL, "mon_thousands_sep", 17,
2959                     newSVpv(lcbuf->mon_thousands_sep, 0), 0);
2960 #endif                    
2961             if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
2962                 hv_store(RETVAL, "mon_grouping", 12,
2963                     newSVpv(lcbuf->mon_grouping, 0), 0);
2964             if (lcbuf->positive_sign && *lcbuf->positive_sign)
2965                 hv_store(RETVAL, "positive_sign", 13,
2966                     newSVpv(lcbuf->positive_sign, 0), 0);
2967             if (lcbuf->negative_sign && *lcbuf->negative_sign)
2968                 hv_store(RETVAL, "negative_sign", 13,
2969                     newSVpv(lcbuf->negative_sign, 0), 0);
2970             /* the integers */
2971             if (lcbuf->int_frac_digits != CHAR_MAX)
2972                 hv_store(RETVAL, "int_frac_digits", 15,
2973                     newSViv(lcbuf->int_frac_digits), 0);
2974             if (lcbuf->frac_digits != CHAR_MAX)
2975                 hv_store(RETVAL, "frac_digits", 11,
2976                     newSViv(lcbuf->frac_digits), 0);
2977             if (lcbuf->p_cs_precedes != CHAR_MAX)
2978                 hv_store(RETVAL, "p_cs_precedes", 13,
2979                     newSViv(lcbuf->p_cs_precedes), 0);
2980             if (lcbuf->p_sep_by_space != CHAR_MAX)
2981                 hv_store(RETVAL, "p_sep_by_space", 14,
2982                     newSViv(lcbuf->p_sep_by_space), 0);
2983             if (lcbuf->n_cs_precedes != CHAR_MAX)
2984                 hv_store(RETVAL, "n_cs_precedes", 13,
2985                     newSViv(lcbuf->n_cs_precedes), 0);
2986             if (lcbuf->n_sep_by_space != CHAR_MAX)
2987                 hv_store(RETVAL, "n_sep_by_space", 14,
2988                     newSViv(lcbuf->n_sep_by_space), 0);
2989             if (lcbuf->p_sign_posn != CHAR_MAX)
2990                 hv_store(RETVAL, "p_sign_posn", 11,
2991                     newSViv(lcbuf->p_sign_posn), 0);
2992             if (lcbuf->n_sign_posn != CHAR_MAX)
2993                 hv_store(RETVAL, "n_sign_posn", 11,
2994                     newSViv(lcbuf->n_sign_posn), 0);
2995         }
2996 #else
2997         localeconv(); /* A stub to call not_here(). */
2998 #endif
2999     OUTPUT:
3000         RETVAL
3001
3002 char *
3003 setlocale(category, locale = 0)
3004         int             category
3005         char *          locale
3006     CODE:
3007         RETVAL = setlocale(category, locale);
3008         if (RETVAL) {
3009 #ifdef USE_LOCALE_CTYPE
3010             if (category == LC_CTYPE
3011 #ifdef LC_ALL
3012                 || category == LC_ALL
3013 #endif
3014                 )
3015             {
3016                 char *newctype;
3017 #ifdef LC_ALL
3018                 if (category == LC_ALL)
3019                     newctype = setlocale(LC_CTYPE, NULL);
3020                 else
3021 #endif
3022                     newctype = RETVAL;
3023                 perl_new_ctype(newctype);
3024             }
3025 #endif /* USE_LOCALE_CTYPE */
3026 #ifdef USE_LOCALE_COLLATE
3027             if (category == LC_COLLATE
3028 #ifdef LC_ALL
3029                 || category == LC_ALL
3030 #endif
3031                 )
3032             {
3033                 char *newcoll;
3034 #ifdef LC_ALL
3035                 if (category == LC_ALL)
3036                     newcoll = setlocale(LC_COLLATE, NULL);
3037                 else
3038 #endif
3039                     newcoll = RETVAL;
3040                 perl_new_collate(newcoll);
3041             }
3042 #endif /* USE_LOCALE_COLLATE */
3043 #ifdef USE_LOCALE_NUMERIC
3044             if (category == LC_NUMERIC
3045 #ifdef LC_ALL
3046                 || category == LC_ALL
3047 #endif
3048                 )
3049             {
3050                 char *newnum;
3051 #ifdef LC_ALL
3052                 if (category == LC_ALL)
3053                     newnum = setlocale(LC_NUMERIC, NULL);
3054                 else
3055 #endif
3056                     newnum = RETVAL;
3057                 perl_new_numeric(newnum);
3058             }
3059 #endif /* USE_LOCALE_NUMERIC */
3060         }
3061     OUTPUT:
3062         RETVAL
3063
3064
3065 double
3066 acos(x)
3067         double          x
3068
3069 double
3070 asin(x)
3071         double          x
3072
3073 double
3074 atan(x)
3075         double          x
3076
3077 double
3078 ceil(x)
3079         double          x
3080
3081 double
3082 cosh(x)
3083         double          x
3084
3085 double
3086 floor(x)
3087         double          x
3088
3089 double
3090 fmod(x,y)
3091         double          x
3092         double          y
3093
3094 void
3095 frexp(x)
3096         double          x
3097     PPCODE:
3098         int expvar;
3099         /* (We already know stack is long enough.) */
3100         PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
3101         PUSHs(sv_2mortal(newSViv(expvar)));
3102
3103 double
3104 ldexp(x,exp)
3105         double          x
3106         int             exp
3107
3108 double
3109 log10(x)
3110         double          x
3111
3112 void
3113 modf(x)
3114         double          x
3115     PPCODE:
3116         double intvar;
3117         /* (We already know stack is long enough.) */
3118         PUSHs(sv_2mortal(newSVnv(modf(x,&intvar))));
3119         PUSHs(sv_2mortal(newSVnv(intvar)));
3120
3121 double
3122 sinh(x)
3123         double          x
3124
3125 double
3126 tan(x)
3127         double          x
3128
3129 double
3130 tanh(x)
3131         double          x
3132
3133 SysRet
3134 sigaction(sig, action, oldaction = 0)
3135         int                     sig
3136         POSIX::SigAction        action
3137         POSIX::SigAction        oldaction
3138     CODE:
3139 #ifdef WIN32
3140         RETVAL = not_here("sigaction");
3141 #else
3142 # This code is really grody because we're trying to make the signal
3143 # interface look beautiful, which is hard.
3144
3145         if (!siggv)
3146             gv_fetchpv("SIG", TRUE, SVt_PVHV);
3147
3148         {
3149             struct sigaction act;
3150             struct sigaction oact;
3151             POSIX__SigSet sigset;
3152             SV** svp;
3153             SV** sigsvp = hv_fetch(GvHVn(siggv),
3154                                  sig_name[sig],
3155                                  strlen(sig_name[sig]),
3156                                  TRUE);
3157
3158             /* Remember old handler name if desired. */
3159             if (oldaction) {
3160                 char *hand = SvPVx(*sigsvp, na);
3161                 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
3162                 sv_setpv(*svp, *hand ? hand : "DEFAULT");
3163             }
3164
3165             if (action) {
3166                 /* Vector new handler through %SIG.  (We always use sighandler
3167                    for the C signal handler, which reads %SIG to dispatch.) */
3168                 svp = hv_fetch(action, "HANDLER", 7, FALSE);
3169                 if (!svp)
3170                     croak("Can't supply an action without a HANDLER");
3171                 sv_setpv(*sigsvp, SvPV(*svp, na));
3172                 mg_set(*sigsvp);        /* handles DEFAULT and IGNORE */
3173                 act.sa_handler = sighandler;
3174
3175                 /* Set up any desired mask. */
3176                 svp = hv_fetch(action, "MASK", 4, FALSE);
3177                 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
3178                     unsigned long tmp;
3179                     tmp = (unsigned long)SvNV((SV*)SvRV(*svp));
3180                     sigset = (sigset_t*) tmp;
3181                     act.sa_mask = *sigset;
3182                 }
3183                 else
3184                     sigemptyset(& act.sa_mask);
3185
3186                 /* Set up any desired flags. */
3187                 svp = hv_fetch(action, "FLAGS", 5, FALSE);
3188                 act.sa_flags = svp ? SvIV(*svp) : 0;
3189             }
3190
3191             /* Now work around sigaction oddities */
3192             if (action && oldaction)
3193                 RETVAL = sigaction(sig, & act, & oact);
3194             else if (action)
3195                 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
3196             else if (oldaction)
3197                 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
3198             else
3199                 RETVAL = -1;
3200
3201             if (oldaction) {
3202                 /* Get back the mask. */
3203                 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
3204                 if (sv_isa(*svp, "POSIX::SigSet")) {
3205                     unsigned long tmp;
3206                     tmp = (unsigned long)SvNV((SV*)SvRV(*svp));
3207                     sigset = (sigset_t*) tmp;
3208                 }
3209                 else {
3210                     sigset = (sigset_t*)safemalloc(sizeof(sigset_t));
3211                     sv_setptrobj(*svp, sigset, "POSIX::SigSet");
3212                 }
3213                 *sigset = oact.sa_mask;
3214
3215                 /* Get back the flags. */
3216                 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
3217                 sv_setiv(*svp, oact.sa_flags);
3218             }
3219         }
3220 #endif
3221     OUTPUT:
3222         RETVAL
3223
3224 SysRet
3225 sigpending(sigset)
3226         POSIX::SigSet           sigset
3227
3228 SysRet
3229 sigprocmask(how, sigset, oldsigset = 0)
3230         int                     how
3231         POSIX::SigSet           sigset
3232         POSIX::SigSet           oldsigset
3233
3234 SysRet
3235 sigsuspend(signal_mask)
3236         POSIX::SigSet           signal_mask
3237
3238 void
3239 _exit(status)
3240         int             status
3241
3242 SysRet
3243 close(fd)
3244         int             fd
3245
3246 SysRet
3247 dup(fd)
3248         int             fd
3249
3250 SysRet
3251 dup2(fd1, fd2)
3252         int             fd1
3253         int             fd2
3254
3255 SysRetLong
3256 lseek(fd, offset, whence)
3257         int             fd
3258         Off_t           offset
3259         int             whence
3260
3261 SysRet
3262 nice(incr)
3263         int             incr
3264
3265 int
3266 pipe()
3267     PPCODE:
3268         int fds[2];
3269         if (pipe(fds) != -1) {
3270             EXTEND(SP,2);
3271             PUSHs(sv_2mortal(newSViv(fds[0])));
3272             PUSHs(sv_2mortal(newSViv(fds[1])));
3273         }
3274
3275 SysRet
3276 read(fd, buffer, nbytes)
3277     PREINIT:
3278         SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
3279     INPUT:
3280         int             fd
3281         size_t          nbytes
3282         char *          buffer = sv_grow( sv_buffer, nbytes+1 );
3283     CLEANUP:
3284         if (RETVAL >= 0) {
3285             SvCUR(sv_buffer) = RETVAL;
3286             SvPOK_only(sv_buffer);
3287             *SvEND(sv_buffer) = '\0';
3288             SvTAINTED_on(sv_buffer);
3289         }
3290
3291 SysRet
3292 setpgid(pid, pgid)
3293         pid_t           pid
3294         pid_t           pgid
3295
3296 pid_t
3297 setsid()
3298
3299 pid_t
3300 tcgetpgrp(fd)
3301         int             fd
3302
3303 SysRet
3304 tcsetpgrp(fd, pgrp_id)
3305         int             fd
3306         pid_t           pgrp_id
3307
3308 int
3309 uname()
3310     PPCODE:
3311 #ifdef HAS_UNAME
3312         struct utsname buf;
3313         if (uname(&buf) >= 0) {
3314             EXTEND(SP, 5);
3315             PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
3316             PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
3317             PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
3318             PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
3319             PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
3320         }
3321 #else
3322         uname((char *) 0); /* A stub to call not_here(). */
3323 #endif
3324
3325 SysRet
3326 write(fd, buffer, nbytes)
3327         int             fd
3328         char *          buffer
3329         size_t          nbytes
3330
3331 char *
3332 tmpnam(s = 0)
3333         char *          s = 0;
3334
3335 void
3336 abort()
3337
3338 int
3339 mblen(s, n)
3340         char *          s
3341         size_t          n
3342
3343 size_t
3344 mbstowcs(s, pwcs, n)
3345         wchar_t *       s
3346         char *          pwcs
3347         size_t          n
3348
3349 int
3350 mbtowc(pwc, s, n)
3351         wchar_t *       pwc
3352         char *          s
3353         size_t          n
3354
3355 int
3356 wcstombs(s, pwcs, n)
3357         char *          s
3358         wchar_t *       pwcs
3359         size_t          n
3360
3361 int
3362 wctomb(s, wchar)
3363         char *          s
3364         wchar_t         wchar
3365
3366 int
3367 strcoll(s1, s2)
3368         char *          s1
3369         char *          s2
3370
3371 void
3372 strtod(str)
3373         char *          str
3374     PREINIT:
3375         double num;
3376         char *unparsed;
3377     PPCODE:
3378         SET_NUMERIC_LOCAL();
3379         num = strtod(str, &unparsed);
3380         PUSHs(sv_2mortal(newSVnv(num)));
3381         if (GIMME == G_ARRAY) {
3382             EXTEND(SP, 1);
3383             if (unparsed)
3384                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3385             else
3386                 PUSHs(&sv_undef);
3387         }
3388
3389 void
3390 strtol(str, base = 0)
3391         char *          str
3392         int             base
3393     PREINIT:
3394         long num;
3395         char *unparsed;
3396     PPCODE:
3397         num = strtol(str, &unparsed, base);
3398         if (num >= IV_MIN && num <= IV_MAX)
3399             PUSHs(sv_2mortal(newSViv((IV)num)));
3400         else
3401             PUSHs(sv_2mortal(newSVnv((double)num)));
3402         if (GIMME == G_ARRAY) {
3403             EXTEND(SP, 1);
3404             if (unparsed)
3405                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3406             else
3407                 PUSHs(&sv_undef);
3408         }
3409
3410 void
3411 strtoul(str, base = 0)
3412         char *          str
3413         int             base
3414     PREINIT:
3415         unsigned long num;
3416         char *unparsed;
3417     PPCODE:
3418         num = strtoul(str, &unparsed, base);
3419         if (num <= IV_MAX)
3420             PUSHs(sv_2mortal(newSViv((IV)num)));
3421         else
3422             PUSHs(sv_2mortal(newSVnv((double)num)));
3423         if (GIMME == G_ARRAY) {
3424             EXTEND(SP, 1);
3425             if (unparsed)
3426                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3427             else
3428                 PUSHs(&sv_undef);
3429         }
3430
3431 SV *
3432 strxfrm(src)
3433         SV *            src
3434     CODE:
3435         {
3436           STRLEN srclen;
3437           STRLEN dstlen;
3438           char *p = SvPV(src,srclen);
3439           srclen++;
3440           ST(0) = sv_2mortal(NEWSV(800,srclen));
3441           dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
3442           if (dstlen > srclen) {
3443               dstlen++;
3444               SvGROW(ST(0), dstlen);
3445               strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
3446               dstlen--;
3447           }
3448           SvCUR(ST(0)) = dstlen;
3449             SvPOK_only(ST(0));
3450         }
3451
3452 SysRet
3453 mkfifo(filename, mode)
3454         char *          filename
3455         Mode_t          mode
3456     CODE:
3457         TAINT_PROPER("mkfifo");
3458         RETVAL = mkfifo(filename, mode);
3459     OUTPUT:
3460         RETVAL
3461
3462 SysRet
3463 tcdrain(fd)
3464         int             fd
3465
3466
3467 SysRet
3468 tcflow(fd, action)
3469         int             fd
3470         int             action
3471
3472
3473 SysRet
3474 tcflush(fd, queue_selector)
3475         int             fd
3476         int             queue_selector
3477
3478 SysRet
3479 tcsendbreak(fd, duration)
3480         int             fd
3481         int             duration
3482
3483 char *
3484 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
3485         int             sec
3486         int             min
3487         int             hour
3488         int             mday
3489         int             mon
3490         int             year
3491         int             wday
3492         int             yday
3493         int             isdst
3494     CODE:
3495         {
3496             struct tm mytm;
3497             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3498             mytm.tm_sec = sec;
3499             mytm.tm_min = min;
3500             mytm.tm_hour = hour;
3501             mytm.tm_mday = mday;
3502             mytm.tm_mon = mon;
3503             mytm.tm_year = year;
3504             mytm.tm_wday = wday;
3505             mytm.tm_yday = yday;
3506             mytm.tm_isdst = isdst;
3507             RETVAL = asctime(&mytm);
3508         }
3509     OUTPUT:
3510         RETVAL
3511
3512 long
3513 clock()
3514
3515 char *
3516 ctime(time)
3517         Time_t          &time
3518
3519 void
3520 times()
3521         PPCODE:
3522         struct tms tms;
3523         clock_t realtime;
3524         realtime = times( &tms );
3525         EXTEND(SP,5);
3526         PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
3527         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
3528         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
3529         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
3530         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
3531
3532 double
3533 difftime(time1, time2)
3534         Time_t          time1
3535         Time_t          time2
3536
3537 SysRetLong
3538 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
3539         int             sec
3540         int             min
3541         int             hour
3542         int             mday
3543         int             mon
3544         int             year
3545         int             wday
3546         int             yday
3547         int             isdst
3548     CODE:
3549         {
3550             struct tm mytm;
3551             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3552             mytm.tm_sec = sec;
3553             mytm.tm_min = min;
3554             mytm.tm_hour = hour;
3555             mytm.tm_mday = mday;
3556             mytm.tm_mon = mon;
3557             mytm.tm_year = year;
3558             mytm.tm_wday = wday;
3559             mytm.tm_yday = yday;
3560             mytm.tm_isdst = isdst;
3561             RETVAL = mktime(&mytm);
3562         }
3563     OUTPUT:
3564         RETVAL
3565
3566 char *
3567 strftime(fmt, sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
3568         char *          fmt
3569         int             sec
3570         int             min
3571         int             hour
3572         int             mday
3573         int             mon
3574         int             year
3575         int             wday
3576         int             yday
3577         int             isdst
3578     CODE:
3579         {
3580             char tmpbuf[128];
3581             struct tm mytm;
3582             int len;
3583             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3584             mytm.tm_sec = sec;
3585             mytm.tm_min = min;
3586             mytm.tm_hour = hour;
3587             mytm.tm_mday = mday;
3588             mytm.tm_mon = mon;
3589             mytm.tm_year = year;
3590             mytm.tm_wday = wday;
3591             mytm.tm_yday = yday;
3592             mytm.tm_isdst = isdst;
3593             len = strftime(tmpbuf, sizeof tmpbuf, fmt, &mytm);
3594             ST(0) = sv_2mortal(newSVpv(tmpbuf, len));
3595         }
3596
3597 void
3598 tzset()
3599
3600 void
3601 tzname()
3602     PPCODE:
3603         EXTEND(SP,2);
3604         PUSHs(sv_2mortal(newSVpv(tzname[0],strlen(tzname[0]))));
3605         PUSHs(sv_2mortal(newSVpv(tzname[1],strlen(tzname[1]))));
3606
3607 SysRet
3608 access(filename, mode)
3609         char *          filename
3610         Mode_t          mode
3611
3612 char *
3613 ctermid(s = 0)
3614         char *          s = 0;
3615
3616 char *
3617 cuserid(s = 0)
3618         char *          s = 0;
3619
3620 SysRetLong
3621 fpathconf(fd, name)
3622         int             fd
3623         int             name
3624
3625 SysRetLong
3626 pathconf(filename, name)
3627         char *          filename
3628         int             name
3629
3630 SysRet
3631 pause()
3632
3633 SysRetLong
3634 sysconf(name)
3635         int             name
3636
3637 char *
3638 ttyname(fd)
3639         int             fd