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