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