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