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