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