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