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