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