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