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