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