slightly modified version of suggested patch
[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             /* L_tmpnam[e] was a typo--retained for compatibility */
1530             if (strEQ(name, "L_tmpname") || strEQ(name, "L_tmpnam"))
1531 #ifdef L_tmpnam
1532                 return L_tmpnam;
1533 #else
1534                 goto not_there;
1535 #endif
1536             break;
1537         }
1538         if (strEQ(name, "LONG_MAX"))
1539 #ifdef LONG_MAX
1540             return LONG_MAX;
1541 #else
1542             goto not_there;
1543 #endif
1544         if (strEQ(name, "LONG_MIN"))
1545 #ifdef LONG_MIN
1546             return LONG_MIN;
1547 #else
1548             goto not_there;
1549 #endif
1550         if (strEQ(name, "LINK_MAX"))
1551 #ifdef LINK_MAX
1552             return LINK_MAX;
1553 #else
1554             goto not_there;
1555 #endif
1556         break;
1557     case 'M':
1558         if (strEQ(name, "MAX_CANON"))
1559 #ifdef MAX_CANON
1560             return MAX_CANON;
1561 #else
1562             goto not_there;
1563 #endif
1564         if (strEQ(name, "MAX_INPUT"))
1565 #ifdef MAX_INPUT
1566             return MAX_INPUT;
1567 #else
1568             goto not_there;
1569 #endif
1570         if (strEQ(name, "MB_CUR_MAX"))
1571 #ifdef MB_CUR_MAX
1572             return MB_CUR_MAX;
1573 #else
1574             goto not_there;
1575 #endif
1576         if (strEQ(name, "MB_LEN_MAX"))
1577 #ifdef MB_LEN_MAX
1578             return MB_LEN_MAX;
1579 #else
1580             goto not_there;
1581 #endif
1582         break;
1583     case 'N':
1584         if (strEQ(name, "NULL")) return 0;
1585         if (strEQ(name, "NAME_MAX"))
1586 #ifdef NAME_MAX
1587             return NAME_MAX;
1588 #else
1589             goto not_there;
1590 #endif
1591         if (strEQ(name, "NCCS"))
1592 #ifdef NCCS
1593             return NCCS;
1594 #else
1595             goto not_there;
1596 #endif
1597         if (strEQ(name, "NGROUPS_MAX"))
1598 #ifdef NGROUPS_MAX
1599             return NGROUPS_MAX;
1600 #else
1601             goto not_there;
1602 #endif
1603         if (strEQ(name, "NOFLSH"))
1604 #ifdef NOFLSH
1605             return NOFLSH;
1606 #else
1607             goto not_there;
1608 #endif
1609         break;
1610     case 'O':
1611         if (strnEQ(name, "O_", 2)) {
1612             if (strEQ(name, "O_APPEND"))
1613 #ifdef O_APPEND
1614                 return O_APPEND;
1615 #else
1616                 goto not_there;
1617 #endif
1618             if (strEQ(name, "O_CREAT"))
1619 #ifdef O_CREAT
1620                 return O_CREAT;
1621 #else
1622                 goto not_there;
1623 #endif
1624             if (strEQ(name, "O_TRUNC"))
1625 #ifdef O_TRUNC
1626                 return O_TRUNC;
1627 #else
1628                 goto not_there;
1629 #endif
1630             if (strEQ(name, "O_RDONLY"))
1631 #ifdef O_RDONLY
1632                 return O_RDONLY;
1633 #else
1634                 goto not_there;
1635 #endif
1636             if (strEQ(name, "O_RDWR"))
1637 #ifdef O_RDWR
1638                 return O_RDWR;
1639 #else
1640                 goto not_there;
1641 #endif
1642             if (strEQ(name, "O_WRONLY"))
1643 #ifdef O_WRONLY
1644                 return O_WRONLY;
1645 #else
1646                 goto not_there;
1647 #endif
1648             if (strEQ(name, "O_EXCL"))
1649 #ifdef O_EXCL
1650                 return O_EXCL;
1651 #else
1652                 goto not_there;
1653 #endif
1654             if (strEQ(name, "O_NOCTTY"))
1655 #ifdef O_NOCTTY
1656                 return O_NOCTTY;
1657 #else
1658                 goto not_there;
1659 #endif
1660             if (strEQ(name, "O_NONBLOCK"))
1661 #ifdef O_NONBLOCK
1662                 return O_NONBLOCK;
1663 #else
1664                 goto not_there;
1665 #endif
1666             if (strEQ(name, "O_ACCMODE"))
1667 #ifdef O_ACCMODE
1668                 return O_ACCMODE;
1669 #else
1670                 goto not_there;
1671 #endif
1672             break;
1673         }
1674         if (strEQ(name, "OPEN_MAX"))
1675 #ifdef OPEN_MAX
1676             return OPEN_MAX;
1677 #else
1678             goto not_there;
1679 #endif
1680         if (strEQ(name, "OPOST"))
1681 #ifdef OPOST
1682             return OPOST;
1683 #else
1684             goto not_there;
1685 #endif
1686         break;
1687     case 'P':
1688         if (strEQ(name, "PATH_MAX"))
1689 #ifdef PATH_MAX
1690             return PATH_MAX;
1691 #else
1692             goto not_there;
1693 #endif
1694         if (strEQ(name, "PARENB"))
1695 #ifdef PARENB
1696             return PARENB;
1697 #else
1698             goto not_there;
1699 #endif
1700         if (strEQ(name, "PARMRK"))
1701 #ifdef PARMRK
1702             return PARMRK;
1703 #else
1704             goto not_there;
1705 #endif
1706         if (strEQ(name, "PARODD"))
1707 #ifdef PARODD
1708             return PARODD;
1709 #else
1710             goto not_there;
1711 #endif
1712         if (strEQ(name, "PIPE_BUF"))
1713 #ifdef PIPE_BUF
1714             return PIPE_BUF;
1715 #else
1716             goto not_there;
1717 #endif
1718         break;
1719     case 'R':
1720         if (strEQ(name, "RAND_MAX"))
1721 #ifdef RAND_MAX
1722             return RAND_MAX;
1723 #else
1724             goto not_there;
1725 #endif
1726         if (strEQ(name, "R_OK"))
1727 #ifdef R_OK
1728             return R_OK;
1729 #else
1730             goto not_there;
1731 #endif
1732         break;
1733     case 'S':
1734         if (strnEQ(name, "SIG", 3)) {
1735             if (name[3] == '_') {
1736                 if (strEQ(name, "SIG_BLOCK"))
1737 #ifdef SIG_BLOCK
1738                     return SIG_BLOCK;
1739 #else
1740                     goto not_there;
1741 #endif
1742 #ifdef SIG_DFL
1743                 if (strEQ(name, "SIG_DFL")) return (IV)SIG_DFL;
1744 #endif
1745 #ifdef SIG_ERR
1746                 if (strEQ(name, "SIG_ERR")) return (IV)SIG_ERR;
1747 #endif
1748 #ifdef SIG_IGN
1749                 if (strEQ(name, "SIG_IGN")) return (IV)SIG_IGN;
1750 #endif
1751                 if (strEQ(name, "SIG_SETMASK"))
1752 #ifdef SIG_SETMASK
1753                     return SIG_SETMASK;
1754 #else
1755                     goto not_there;
1756 #endif
1757                 if (strEQ(name, "SIG_UNBLOCK"))
1758 #ifdef SIG_UNBLOCK
1759                     return SIG_UNBLOCK;
1760 #else
1761                     goto not_there;
1762 #endif
1763                 break;
1764             }
1765             if (strEQ(name, "SIGABRT"))
1766 #ifdef SIGABRT
1767                 return SIGABRT;
1768 #else
1769                 goto not_there;
1770 #endif
1771             if (strEQ(name, "SIGALRM"))
1772 #ifdef SIGALRM
1773                 return SIGALRM;
1774 #else
1775                 goto not_there;
1776 #endif
1777             if (strEQ(name, "SIGCHLD"))
1778 #ifdef SIGCHLD
1779                 return SIGCHLD;
1780 #else
1781                 goto not_there;
1782 #endif
1783             if (strEQ(name, "SIGCONT"))
1784 #ifdef SIGCONT
1785                 return SIGCONT;
1786 #else
1787                 goto not_there;
1788 #endif
1789             if (strEQ(name, "SIGFPE"))
1790 #ifdef SIGFPE
1791                 return SIGFPE;
1792 #else
1793                 goto not_there;
1794 #endif
1795             if (strEQ(name, "SIGHUP"))
1796 #ifdef SIGHUP
1797                 return SIGHUP;
1798 #else
1799                 goto not_there;
1800 #endif
1801             if (strEQ(name, "SIGILL"))
1802 #ifdef SIGILL
1803                 return SIGILL;
1804 #else
1805                 goto not_there;
1806 #endif
1807             if (strEQ(name, "SIGINT"))
1808 #ifdef SIGINT
1809                 return SIGINT;
1810 #else
1811                 goto not_there;
1812 #endif
1813             if (strEQ(name, "SIGKILL"))
1814 #ifdef SIGKILL
1815                 return SIGKILL;
1816 #else
1817                 goto not_there;
1818 #endif
1819             if (strEQ(name, "SIGPIPE"))
1820 #ifdef SIGPIPE
1821                 return SIGPIPE;
1822 #else
1823                 goto not_there;
1824 #endif
1825             if (strEQ(name, "SIGQUIT"))
1826 #ifdef SIGQUIT
1827                 return SIGQUIT;
1828 #else
1829                 goto not_there;
1830 #endif
1831             if (strEQ(name, "SIGSEGV"))
1832 #ifdef SIGSEGV
1833                 return SIGSEGV;
1834 #else
1835                 goto not_there;
1836 #endif
1837             if (strEQ(name, "SIGSTOP"))
1838 #ifdef SIGSTOP
1839                 return SIGSTOP;
1840 #else
1841                 goto not_there;
1842 #endif
1843             if (strEQ(name, "SIGTERM"))
1844 #ifdef SIGTERM
1845                 return SIGTERM;
1846 #else
1847                 goto not_there;
1848 #endif
1849             if (strEQ(name, "SIGTSTP"))
1850 #ifdef SIGTSTP
1851                 return SIGTSTP;
1852 #else
1853                 goto not_there;
1854 #endif
1855             if (strEQ(name, "SIGTTIN"))
1856 #ifdef SIGTTIN
1857                 return SIGTTIN;
1858 #else
1859                 goto not_there;
1860 #endif
1861             if (strEQ(name, "SIGTTOU"))
1862 #ifdef SIGTTOU
1863                 return SIGTTOU;
1864 #else
1865                 goto not_there;
1866 #endif
1867             if (strEQ(name, "SIGUSR1"))
1868 #ifdef SIGUSR1
1869                 return SIGUSR1;
1870 #else
1871                 goto not_there;
1872 #endif
1873             if (strEQ(name, "SIGUSR2"))
1874 #ifdef SIGUSR2
1875                 return SIGUSR2;
1876 #else
1877                 goto not_there;
1878 #endif
1879             break;
1880         }
1881         if (name[1] == '_') {
1882             if (strEQ(name, "S_ISGID"))
1883 #ifdef S_ISGID
1884                 return S_ISGID;
1885 #else
1886                 goto not_there;
1887 #endif
1888             if (strEQ(name, "S_ISUID"))
1889 #ifdef S_ISUID
1890                 return S_ISUID;
1891 #else
1892                 goto not_there;
1893 #endif
1894             if (strEQ(name, "S_IRGRP"))
1895 #ifdef S_IRGRP
1896                 return S_IRGRP;
1897 #else
1898                 goto not_there;
1899 #endif
1900             if (strEQ(name, "S_IROTH"))
1901 #ifdef S_IROTH
1902                 return S_IROTH;
1903 #else
1904                 goto not_there;
1905 #endif
1906             if (strEQ(name, "S_IRUSR"))
1907 #ifdef S_IRUSR
1908                 return S_IRUSR;
1909 #else
1910                 goto not_there;
1911 #endif
1912             if (strEQ(name, "S_IRWXG"))
1913 #ifdef S_IRWXG
1914                 return S_IRWXG;
1915 #else
1916                 goto not_there;
1917 #endif
1918             if (strEQ(name, "S_IRWXO"))
1919 #ifdef S_IRWXO
1920                 return S_IRWXO;
1921 #else
1922                 goto not_there;
1923 #endif
1924             if (strEQ(name, "S_IRWXU"))
1925 #ifdef S_IRWXU
1926                 return S_IRWXU;
1927 #else
1928                 goto not_there;
1929 #endif
1930             if (strEQ(name, "S_IWGRP"))
1931 #ifdef S_IWGRP
1932                 return S_IWGRP;
1933 #else
1934                 goto not_there;
1935 #endif
1936             if (strEQ(name, "S_IWOTH"))
1937 #ifdef S_IWOTH
1938                 return S_IWOTH;
1939 #else
1940                 goto not_there;
1941 #endif
1942             if (strEQ(name, "S_IWUSR"))
1943 #ifdef S_IWUSR
1944                 return S_IWUSR;
1945 #else
1946                 goto not_there;
1947 #endif
1948             if (strEQ(name, "S_IXGRP"))
1949 #ifdef S_IXGRP
1950                 return S_IXGRP;
1951 #else
1952                 goto not_there;
1953 #endif
1954             if (strEQ(name, "S_IXOTH"))
1955 #ifdef S_IXOTH
1956                 return S_IXOTH;
1957 #else
1958                 goto not_there;
1959 #endif
1960             if (strEQ(name, "S_IXUSR"))
1961 #ifdef S_IXUSR
1962                 return S_IXUSR;
1963 #else
1964                 goto not_there;
1965 #endif
1966             errno = EAGAIN;             /* the following aren't constants */
1967 #ifdef S_ISBLK
1968             if (strEQ(name, "S_ISBLK")) return S_ISBLK(arg);
1969 #endif
1970 #ifdef S_ISCHR
1971             if (strEQ(name, "S_ISCHR")) return S_ISCHR(arg);
1972 #endif
1973 #ifdef S_ISDIR
1974             if (strEQ(name, "S_ISDIR")) return S_ISDIR(arg);
1975 #endif
1976 #ifdef S_ISFIFO
1977             if (strEQ(name, "S_ISFIFO")) return S_ISFIFO(arg);
1978 #endif
1979 #ifdef S_ISREG
1980             if (strEQ(name, "S_ISREG")) return S_ISREG(arg);
1981 #endif
1982             break;
1983         }
1984         if (strEQ(name, "SEEK_CUR"))
1985 #ifdef SEEK_CUR
1986             return SEEK_CUR;
1987 #else
1988             goto not_there;
1989 #endif
1990         if (strEQ(name, "SEEK_END"))
1991 #ifdef SEEK_END
1992             return SEEK_END;
1993 #else
1994             goto not_there;
1995 #endif
1996         if (strEQ(name, "SEEK_SET"))
1997 #ifdef SEEK_SET
1998             return SEEK_SET;
1999 #else
2000             goto not_there;
2001 #endif
2002         if (strEQ(name, "STREAM_MAX"))
2003 #ifdef STREAM_MAX
2004             return STREAM_MAX;
2005 #else
2006             goto not_there;
2007 #endif
2008         if (strEQ(name, "SHRT_MAX"))
2009 #ifdef SHRT_MAX
2010             return SHRT_MAX;
2011 #else
2012             goto not_there;
2013 #endif
2014         if (strEQ(name, "SHRT_MIN"))
2015 #ifdef SHRT_MIN
2016             return SHRT_MIN;
2017 #else
2018             goto not_there;
2019 #endif
2020         if (strnEQ(name, "SA_", 3)) {
2021             if (strEQ(name, "SA_NOCLDSTOP"))
2022 #ifdef SA_NOCLDSTOP
2023                 return SA_NOCLDSTOP;
2024 #else
2025                 goto not_there;
2026 #endif
2027             if (strEQ(name, "SA_NOCLDWAIT"))
2028 #ifdef SA_NOCLDWAIT
2029                 return SA_NOCLDWAIT;
2030 #else
2031                 goto not_there;
2032 #endif
2033             if (strEQ(name, "SA_NODEFER"))
2034 #ifdef SA_NODEFER
2035                 return SA_NODEFER;
2036 #else
2037                 goto not_there;
2038 #endif
2039             if (strEQ(name, "SA_ONSTACK"))
2040 #ifdef SA_ONSTACK
2041                 return SA_ONSTACK;
2042 #else
2043                 goto not_there;
2044 #endif
2045             if (strEQ(name, "SA_RESETHAND"))
2046 #ifdef SA_RESETHAND
2047                 return SA_RESETHAND;
2048 #else
2049                 goto not_there;
2050 #endif
2051             if (strEQ(name, "SA_RESTART"))
2052 #ifdef SA_RESTART
2053                 return SA_RESTART;
2054 #else
2055                 goto not_there;
2056 #endif
2057             if (strEQ(name, "SA_SIGINFO"))
2058 #ifdef SA_SIGINFO
2059                 return SA_SIGINFO;
2060 #else
2061                 goto not_there;
2062 #endif
2063             break;
2064         }
2065         if (strEQ(name, "SCHAR_MAX"))
2066 #ifdef SCHAR_MAX
2067             return SCHAR_MAX;
2068 #else
2069             goto not_there;
2070 #endif
2071         if (strEQ(name, "SCHAR_MIN"))
2072 #ifdef SCHAR_MIN
2073             return SCHAR_MIN;
2074 #else
2075             goto not_there;
2076 #endif
2077         if (strEQ(name, "SSIZE_MAX"))
2078 #ifdef SSIZE_MAX
2079             return SSIZE_MAX;
2080 #else
2081             goto not_there;
2082 #endif
2083         if (strEQ(name, "STDIN_FILENO"))
2084 #ifdef STDIN_FILENO
2085             return STDIN_FILENO;
2086 #else
2087             goto not_there;
2088 #endif
2089         if (strEQ(name, "STDOUT_FILENO"))
2090 #ifdef STDOUT_FILENO
2091             return STDOUT_FILENO;
2092 #else
2093             goto not_there;
2094 #endif
2095         if (strEQ(name, "STRERR_FILENO"))
2096 #ifdef STRERR_FILENO
2097             return STRERR_FILENO;
2098 #else
2099             goto not_there;
2100 #endif
2101         break;
2102     case 'T':
2103         if (strEQ(name, "TCIFLUSH"))
2104 #ifdef TCIFLUSH
2105             return TCIFLUSH;
2106 #else
2107             goto not_there;
2108 #endif
2109         if (strEQ(name, "TCIOFF"))
2110 #ifdef TCIOFF
2111             return TCIOFF;
2112 #else
2113             goto not_there;
2114 #endif
2115         if (strEQ(name, "TCIOFLUSH"))
2116 #ifdef TCIOFLUSH
2117             return TCIOFLUSH;
2118 #else
2119             goto not_there;
2120 #endif
2121         if (strEQ(name, "TCION"))
2122 #ifdef TCION
2123             return TCION;
2124 #else
2125             goto not_there;
2126 #endif
2127         if (strEQ(name, "TCOFLUSH"))
2128 #ifdef TCOFLUSH
2129             return TCOFLUSH;
2130 #else
2131             goto not_there;
2132 #endif
2133         if (strEQ(name, "TCOOFF"))
2134 #ifdef TCOOFF
2135             return TCOOFF;
2136 #else
2137             goto not_there;
2138 #endif
2139         if (strEQ(name, "TCOON"))
2140 #ifdef TCOON
2141             return TCOON;
2142 #else
2143             goto not_there;
2144 #endif
2145         if (strEQ(name, "TCSADRAIN"))
2146 #ifdef TCSADRAIN
2147             return TCSADRAIN;
2148 #else
2149             goto not_there;
2150 #endif
2151         if (strEQ(name, "TCSAFLUSH"))
2152 #ifdef TCSAFLUSH
2153             return TCSAFLUSH;
2154 #else
2155             goto not_there;
2156 #endif
2157         if (strEQ(name, "TCSANOW"))
2158 #ifdef TCSANOW
2159             return TCSANOW;
2160 #else
2161             goto not_there;
2162 #endif
2163         if (strEQ(name, "TMP_MAX"))
2164 #ifdef TMP_MAX
2165             return TMP_MAX;
2166 #else
2167             goto not_there;
2168 #endif
2169         if (strEQ(name, "TOSTOP"))
2170 #ifdef TOSTOP
2171             return TOSTOP;
2172 #else
2173             goto not_there;
2174 #endif
2175         if (strEQ(name, "TZNAME_MAX"))
2176 #ifdef TZNAME_MAX
2177             return TZNAME_MAX;
2178 #else
2179             goto not_there;
2180 #endif
2181         break;
2182     case 'U':
2183         if (strEQ(name, "UCHAR_MAX"))
2184 #ifdef UCHAR_MAX
2185             return UCHAR_MAX;
2186 #else
2187             goto not_there;
2188 #endif
2189         if (strEQ(name, "UINT_MAX"))
2190 #ifdef UINT_MAX
2191             return UINT_MAX;
2192 #else
2193             goto not_there;
2194 #endif
2195         if (strEQ(name, "ULONG_MAX"))
2196 #ifdef ULONG_MAX
2197             return ULONG_MAX;
2198 #else
2199             goto not_there;
2200 #endif
2201         if (strEQ(name, "USHRT_MAX"))
2202 #ifdef USHRT_MAX
2203             return USHRT_MAX;
2204 #else
2205             goto not_there;
2206 #endif
2207         break;
2208     case 'V':
2209         if (strEQ(name, "VEOF"))
2210 #ifdef VEOF
2211             return VEOF;
2212 #else
2213             goto not_there;
2214 #endif
2215         if (strEQ(name, "VEOL"))
2216 #ifdef VEOL
2217             return VEOL;
2218 #else
2219             goto not_there;
2220 #endif
2221         if (strEQ(name, "VERASE"))
2222 #ifdef VERASE
2223             return VERASE;
2224 #else
2225             goto not_there;
2226 #endif
2227         if (strEQ(name, "VINTR"))
2228 #ifdef VINTR
2229             return VINTR;
2230 #else
2231             goto not_there;
2232 #endif
2233         if (strEQ(name, "VKILL"))
2234 #ifdef VKILL
2235             return VKILL;
2236 #else
2237             goto not_there;
2238 #endif
2239         if (strEQ(name, "VMIN"))
2240 #ifdef VMIN
2241             return VMIN;
2242 #else
2243             goto not_there;
2244 #endif
2245         if (strEQ(name, "VQUIT"))
2246 #ifdef VQUIT
2247             return VQUIT;
2248 #else
2249             goto not_there;
2250 #endif
2251         if (strEQ(name, "VSTART"))
2252 #ifdef VSTART
2253             return VSTART;
2254 #else
2255             goto not_there;
2256 #endif
2257         if (strEQ(name, "VSTOP"))
2258 #ifdef VSTOP
2259             return VSTOP;
2260 #else
2261             goto not_there;
2262 #endif
2263         if (strEQ(name, "VSUSP"))
2264 #ifdef VSUSP
2265             return VSUSP;
2266 #else
2267             goto not_there;
2268 #endif
2269         if (strEQ(name, "VTIME"))
2270 #ifdef VTIME
2271             return VTIME;
2272 #else
2273             goto not_there;
2274 #endif
2275         break;
2276     case 'W':
2277         if (strEQ(name, "W_OK"))
2278 #ifdef W_OK
2279             return W_OK;
2280 #else
2281             goto not_there;
2282 #endif
2283         if (strEQ(name, "WNOHANG"))
2284 #ifdef WNOHANG
2285             return WNOHANG;
2286 #else
2287             goto not_there;
2288 #endif
2289         if (strEQ(name, "WUNTRACED"))
2290 #ifdef WUNTRACED
2291             return WUNTRACED;
2292 #else
2293             goto not_there;
2294 #endif
2295         errno = EAGAIN;         /* the following aren't constants */
2296 #ifdef WEXITSTATUS
2297         if (strEQ(name, "WEXITSTATUS")) return WEXITSTATUS(arg);
2298 #endif
2299 #ifdef WIFEXITED
2300         if (strEQ(name, "WIFEXITED")) return WIFEXITED(arg);
2301 #endif
2302 #ifdef WIFSIGNALED
2303         if (strEQ(name, "WIFSIGNALED")) return WIFSIGNALED(arg);
2304 #endif
2305 #ifdef WIFSTOPPED
2306         if (strEQ(name, "WIFSTOPPED")) return WIFSTOPPED(arg);
2307 #endif
2308 #ifdef WSTOPSIG
2309         if (strEQ(name, "WSTOPSIG")) return WSTOPSIG(arg);
2310 #endif
2311 #ifdef WTERMSIG
2312         if (strEQ(name, "WTERMSIG")) return WTERMSIG(arg);
2313 #endif
2314         break;
2315     case 'X':
2316         if (strEQ(name, "X_OK"))
2317 #ifdef X_OK
2318             return X_OK;
2319 #else
2320             goto not_there;
2321 #endif
2322         break;
2323     case '_':
2324         if (strnEQ(name, "_PC_", 4)) {
2325             if (strEQ(name, "_PC_CHOWN_RESTRICTED"))
2326 #if defined(_PC_CHOWN_RESTRICTED) || HINT_SC_EXIST
2327                 return _PC_CHOWN_RESTRICTED;
2328 #else
2329                 goto not_there;
2330 #endif
2331             if (strEQ(name, "_PC_LINK_MAX"))
2332 #if defined(_PC_LINK_MAX) || HINT_SC_EXIST
2333                 return _PC_LINK_MAX;
2334 #else
2335                 goto not_there;
2336 #endif
2337             if (strEQ(name, "_PC_MAX_CANON"))
2338 #if defined(_PC_MAX_CANON) || HINT_SC_EXIST
2339                 return _PC_MAX_CANON;
2340 #else
2341                 goto not_there;
2342 #endif
2343             if (strEQ(name, "_PC_MAX_INPUT"))
2344 #if defined(_PC_MAX_INPUT) || HINT_SC_EXIST
2345                 return _PC_MAX_INPUT;
2346 #else
2347                 goto not_there;
2348 #endif
2349             if (strEQ(name, "_PC_NAME_MAX"))
2350 #if defined(_PC_NAME_MAX) || HINT_SC_EXIST
2351                 return _PC_NAME_MAX;
2352 #else
2353                 goto not_there;
2354 #endif
2355             if (strEQ(name, "_PC_NO_TRUNC"))
2356 #if defined(_PC_NO_TRUNC) || HINT_SC_EXIST
2357                 return _PC_NO_TRUNC;
2358 #else
2359                 goto not_there;
2360 #endif
2361             if (strEQ(name, "_PC_PATH_MAX"))
2362 #if defined(_PC_PATH_MAX) || HINT_SC_EXIST
2363                 return _PC_PATH_MAX;
2364 #else
2365                 goto not_there;
2366 #endif
2367             if (strEQ(name, "_PC_PIPE_BUF"))
2368 #if defined(_PC_PIPE_BUF) || HINT_SC_EXIST
2369                 return _PC_PIPE_BUF;
2370 #else
2371                 goto not_there;
2372 #endif
2373             if (strEQ(name, "_PC_VDISABLE"))
2374 #if defined(_PC_VDISABLE) || HINT_SC_EXIST
2375                 return _PC_VDISABLE;
2376 #else
2377                 goto not_there;
2378 #endif
2379             break;
2380         }
2381         if (strnEQ(name, "_POSIX_", 7)) {
2382             if (strEQ(name, "_POSIX_ARG_MAX"))
2383 #ifdef _POSIX_ARG_MAX
2384                 return _POSIX_ARG_MAX;
2385 #else
2386                 return 0;
2387 #endif
2388             if (strEQ(name, "_POSIX_CHILD_MAX"))
2389 #ifdef _POSIX_CHILD_MAX
2390                 return _POSIX_CHILD_MAX;
2391 #else
2392                 return 0;
2393 #endif
2394             if (strEQ(name, "_POSIX_CHOWN_RESTRICTED"))
2395 #ifdef _POSIX_CHOWN_RESTRICTED
2396                 return _POSIX_CHOWN_RESTRICTED;
2397 #else
2398                 return 0;
2399 #endif
2400             if (strEQ(name, "_POSIX_JOB_CONTROL"))
2401 #ifdef _POSIX_JOB_CONTROL
2402                 return _POSIX_JOB_CONTROL;
2403 #else
2404                 return 0;
2405 #endif
2406             if (strEQ(name, "_POSIX_LINK_MAX"))
2407 #ifdef _POSIX_LINK_MAX
2408                 return _POSIX_LINK_MAX;
2409 #else
2410                 return 0;
2411 #endif
2412             if (strEQ(name, "_POSIX_MAX_CANON"))
2413 #ifdef _POSIX_MAX_CANON
2414                 return _POSIX_MAX_CANON;
2415 #else
2416                 return 0;
2417 #endif
2418             if (strEQ(name, "_POSIX_MAX_INPUT"))
2419 #ifdef _POSIX_MAX_INPUT
2420                 return _POSIX_MAX_INPUT;
2421 #else
2422                 return 0;
2423 #endif
2424             if (strEQ(name, "_POSIX_NAME_MAX"))
2425 #ifdef _POSIX_NAME_MAX
2426                 return _POSIX_NAME_MAX;
2427 #else
2428                 return 0;
2429 #endif
2430             if (strEQ(name, "_POSIX_NGROUPS_MAX"))
2431 #ifdef _POSIX_NGROUPS_MAX
2432                 return _POSIX_NGROUPS_MAX;
2433 #else
2434                 return 0;
2435 #endif
2436             if (strEQ(name, "_POSIX_NO_TRUNC"))
2437 #ifdef _POSIX_NO_TRUNC
2438                 return _POSIX_NO_TRUNC;
2439 #else
2440                 return 0;
2441 #endif
2442             if (strEQ(name, "_POSIX_OPEN_MAX"))
2443 #ifdef _POSIX_OPEN_MAX
2444                 return _POSIX_OPEN_MAX;
2445 #else
2446                 return 0;
2447 #endif
2448             if (strEQ(name, "_POSIX_PATH_MAX"))
2449 #ifdef _POSIX_PATH_MAX
2450                 return _POSIX_PATH_MAX;
2451 #else
2452                 return 0;
2453 #endif
2454             if (strEQ(name, "_POSIX_PIPE_BUF"))
2455 #ifdef _POSIX_PIPE_BUF
2456                 return _POSIX_PIPE_BUF;
2457 #else
2458                 return 0;
2459 #endif
2460             if (strEQ(name, "_POSIX_SAVED_IDS"))
2461 #ifdef _POSIX_SAVED_IDS
2462                 return _POSIX_SAVED_IDS;
2463 #else
2464                 return 0;
2465 #endif
2466             if (strEQ(name, "_POSIX_SSIZE_MAX"))
2467 #ifdef _POSIX_SSIZE_MAX
2468                 return _POSIX_SSIZE_MAX;
2469 #else
2470                 return 0;
2471 #endif
2472             if (strEQ(name, "_POSIX_STREAM_MAX"))
2473 #ifdef _POSIX_STREAM_MAX
2474                 return _POSIX_STREAM_MAX;
2475 #else
2476                 return 0;
2477 #endif
2478             if (strEQ(name, "_POSIX_TZNAME_MAX"))
2479 #ifdef _POSIX_TZNAME_MAX
2480                 return _POSIX_TZNAME_MAX;
2481 #else
2482                 return 0;
2483 #endif
2484             if (strEQ(name, "_POSIX_VDISABLE"))
2485 #ifdef _POSIX_VDISABLE
2486                 return _POSIX_VDISABLE;
2487 #else
2488                 return 0;
2489 #endif
2490             if (strEQ(name, "_POSIX_VERSION"))
2491 #ifdef _POSIX_VERSION
2492                 return _POSIX_VERSION;
2493 #else
2494                 return 0;
2495 #endif
2496             break;
2497         }
2498         if (strnEQ(name, "_SC_", 4)) {
2499             if (strEQ(name, "_SC_ARG_MAX"))
2500 #if defined(_SC_ARG_MAX) || HINT_SC_EXIST
2501                 return _SC_ARG_MAX;
2502 #else
2503                 goto not_there;
2504 #endif
2505             if (strEQ(name, "_SC_CHILD_MAX"))
2506 #if defined(_SC_CHILD_MAX) || HINT_SC_EXIST
2507                 return _SC_CHILD_MAX;
2508 #else
2509                 goto not_there;
2510 #endif
2511             if (strEQ(name, "_SC_CLK_TCK"))
2512 #if defined(_SC_CLK_TCK) || HINT_SC_EXIST
2513                 return _SC_CLK_TCK;
2514 #else
2515                 goto not_there;
2516 #endif
2517             if (strEQ(name, "_SC_JOB_CONTROL"))
2518 #if defined(_SC_JOB_CONTROL) || HINT_SC_EXIST
2519                 return _SC_JOB_CONTROL;
2520 #else
2521                 goto not_there;
2522 #endif
2523             if (strEQ(name, "_SC_NGROUPS_MAX"))
2524 #if defined(_SC_NGROUPS_MAX) || HINT_SC_EXIST
2525                 return _SC_NGROUPS_MAX;
2526 #else
2527                 goto not_there;
2528 #endif
2529             if (strEQ(name, "_SC_OPEN_MAX"))
2530 #if defined(_SC_OPEN_MAX) || HINT_SC_EXIST
2531                 return _SC_OPEN_MAX;
2532 #else
2533                 goto not_there;
2534 #endif
2535             if (strEQ(name, "_SC_SAVED_IDS"))
2536 #if defined(_SC_SAVED_IDS) || HINT_SC_EXIST
2537                 return _SC_SAVED_IDS;
2538 #else
2539                 goto not_there;
2540 #endif
2541             if (strEQ(name, "_SC_STREAM_MAX"))
2542 #if defined(_SC_STREAM_MAX) || HINT_SC_EXIST
2543                 return _SC_STREAM_MAX;
2544 #else
2545                 goto not_there;
2546 #endif
2547             if (strEQ(name, "_SC_TZNAME_MAX"))
2548 #if defined(_SC_TZNAME_MAX) || HINT_SC_EXIST
2549                 return _SC_TZNAME_MAX;
2550 #else
2551                 goto not_there;
2552 #endif
2553             if (strEQ(name, "_SC_VERSION"))
2554 #if defined(_SC_VERSION) || HINT_SC_EXIST
2555                 return _SC_VERSION;
2556 #else
2557                 goto not_there;
2558 #endif
2559             break;
2560         }
2561     }
2562     errno = EINVAL;
2563     return 0;
2564
2565 not_there:
2566     errno = ENOENT;
2567     return 0;
2568 }
2569
2570 MODULE = SigSet         PACKAGE = POSIX::SigSet         PREFIX = sig
2571
2572 POSIX::SigSet
2573 new(packname = "POSIX::SigSet", ...)
2574     char *              packname
2575     CODE:
2576         {
2577             int i;
2578             New(0, RETVAL, 1, sigset_t);
2579             sigemptyset(RETVAL);
2580             for (i = 1; i < items; i++)
2581                 sigaddset(RETVAL, SvIV(ST(i)));
2582         }
2583     OUTPUT:
2584         RETVAL
2585
2586 void
2587 DESTROY(sigset)
2588         POSIX::SigSet   sigset
2589     CODE:
2590         Safefree(sigset);
2591
2592 SysRet
2593 sigaddset(sigset, sig)
2594         POSIX::SigSet   sigset
2595         int             sig
2596
2597 SysRet
2598 sigdelset(sigset, sig)
2599         POSIX::SigSet   sigset
2600         int             sig
2601
2602 SysRet
2603 sigemptyset(sigset)
2604         POSIX::SigSet   sigset
2605
2606 SysRet
2607 sigfillset(sigset)
2608         POSIX::SigSet   sigset
2609
2610 int
2611 sigismember(sigset, sig)
2612         POSIX::SigSet   sigset
2613         int             sig
2614
2615
2616 MODULE = Termios        PACKAGE = POSIX::Termios        PREFIX = cf
2617
2618 POSIX::Termios
2619 new(packname = "POSIX::Termios", ...)
2620     char *              packname
2621     CODE:
2622         {
2623 #ifdef I_TERMIOS
2624             New(0, RETVAL, 1, struct termios);
2625 #else
2626             not_here("termios");
2627         RETVAL = 0;
2628 #endif
2629         }
2630     OUTPUT:
2631         RETVAL
2632
2633 void
2634 DESTROY(termios_ref)
2635         POSIX::Termios  termios_ref
2636     CODE:
2637 #ifdef I_TERMIOS
2638         Safefree(termios_ref);
2639 #else
2640             not_here("termios");
2641 #endif
2642
2643 SysRet
2644 getattr(termios_ref, fd = 0)
2645         POSIX::Termios  termios_ref
2646         int             fd
2647     CODE:
2648         RETVAL = tcgetattr(fd, termios_ref);
2649     OUTPUT:
2650         RETVAL
2651
2652 SysRet
2653 setattr(termios_ref, fd = 0, optional_actions = 0)
2654         POSIX::Termios  termios_ref
2655         int             fd
2656         int             optional_actions
2657     CODE:
2658         RETVAL = tcsetattr(fd, optional_actions, termios_ref);
2659     OUTPUT:
2660         RETVAL
2661
2662 speed_t
2663 cfgetispeed(termios_ref)
2664         POSIX::Termios  termios_ref
2665
2666 speed_t
2667 cfgetospeed(termios_ref)
2668         POSIX::Termios  termios_ref
2669
2670 tcflag_t
2671 getiflag(termios_ref)
2672         POSIX::Termios  termios_ref
2673     CODE:
2674 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2675         RETVAL = termios_ref->c_iflag;
2676 #else
2677      not_here("getiflag");
2678      RETVAL = 0;
2679 #endif
2680     OUTPUT:
2681         RETVAL
2682
2683 tcflag_t
2684 getoflag(termios_ref)
2685         POSIX::Termios  termios_ref
2686     CODE:
2687 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2688         RETVAL = termios_ref->c_oflag;
2689 #else
2690      not_here("getoflag");
2691      RETVAL = 0;
2692 #endif
2693     OUTPUT:
2694         RETVAL
2695
2696 tcflag_t
2697 getcflag(termios_ref)
2698         POSIX::Termios  termios_ref
2699     CODE:
2700 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2701         RETVAL = termios_ref->c_cflag;
2702 #else
2703      not_here("getcflag");
2704      RETVAL = 0;
2705 #endif
2706     OUTPUT:
2707         RETVAL
2708
2709 tcflag_t
2710 getlflag(termios_ref)
2711         POSIX::Termios  termios_ref
2712     CODE:
2713 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2714         RETVAL = termios_ref->c_lflag;
2715 #else
2716      not_here("getlflag");
2717      RETVAL = 0;
2718 #endif
2719     OUTPUT:
2720         RETVAL
2721
2722 cc_t
2723 getcc(termios_ref, ccix)
2724         POSIX::Termios  termios_ref
2725         int             ccix
2726     CODE:
2727 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2728         if (ccix >= NCCS)
2729             croak("Bad getcc subscript");
2730         RETVAL = termios_ref->c_cc[ccix];
2731 #else
2732      not_here("getcc");
2733      RETVAL = 0;
2734 #endif
2735     OUTPUT:
2736         RETVAL
2737
2738 SysRet
2739 cfsetispeed(termios_ref, speed)
2740         POSIX::Termios  termios_ref
2741         speed_t         speed
2742
2743 SysRet
2744 cfsetospeed(termios_ref, speed)
2745         POSIX::Termios  termios_ref
2746         speed_t         speed
2747
2748 void
2749 setiflag(termios_ref, iflag)
2750         POSIX::Termios  termios_ref
2751         tcflag_t        iflag
2752     CODE:
2753 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2754         termios_ref->c_iflag = iflag;
2755 #else
2756             not_here("setiflag");
2757 #endif
2758
2759 void
2760 setoflag(termios_ref, oflag)
2761         POSIX::Termios  termios_ref
2762         tcflag_t        oflag
2763     CODE:
2764 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2765         termios_ref->c_oflag = oflag;
2766 #else
2767             not_here("setoflag");
2768 #endif
2769
2770 void
2771 setcflag(termios_ref, cflag)
2772         POSIX::Termios  termios_ref
2773         tcflag_t        cflag
2774     CODE:
2775 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2776         termios_ref->c_cflag = cflag;
2777 #else
2778             not_here("setcflag");
2779 #endif
2780
2781 void
2782 setlflag(termios_ref, lflag)
2783         POSIX::Termios  termios_ref
2784         tcflag_t        lflag
2785     CODE:
2786 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2787         termios_ref->c_lflag = lflag;
2788 #else
2789             not_here("setlflag");
2790 #endif
2791
2792 void
2793 setcc(termios_ref, ccix, cc)
2794         POSIX::Termios  termios_ref
2795         int             ccix
2796         cc_t            cc
2797     CODE:
2798 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2799         if (ccix >= NCCS)
2800             croak("Bad setcc subscript");
2801         termios_ref->c_cc[ccix] = cc;
2802 #else
2803             not_here("setcc");
2804 #endif
2805
2806
2807 MODULE = POSIX          PACKAGE = POSIX
2808
2809 double
2810 constant(name,arg)
2811         char *          name
2812         int             arg
2813
2814 int
2815 isalnum(charstring)
2816         unsigned char * charstring
2817     CODE:
2818         unsigned char *s = charstring;
2819         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2820         for (RETVAL = 1; RETVAL && s < e; s++)
2821             if (!isalnum(*s))
2822                 RETVAL = 0;
2823     OUTPUT:
2824         RETVAL
2825
2826 int
2827 isalpha(charstring)
2828         unsigned char * charstring
2829     CODE:
2830         unsigned char *s = charstring;
2831         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2832         for (RETVAL = 1; RETVAL && s < e; s++)
2833             if (!isalpha(*s))
2834                 RETVAL = 0;
2835     OUTPUT:
2836         RETVAL
2837
2838 int
2839 iscntrl(charstring)
2840         unsigned char * charstring
2841     CODE:
2842         unsigned char *s = charstring;
2843         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2844         for (RETVAL = 1; RETVAL && s < e; s++)
2845             if (!iscntrl(*s))
2846                 RETVAL = 0;
2847     OUTPUT:
2848         RETVAL
2849
2850 int
2851 isdigit(charstring)
2852         unsigned char * charstring
2853     CODE:
2854         unsigned char *s = charstring;
2855         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2856         for (RETVAL = 1; RETVAL && s < e; s++)
2857             if (!isdigit(*s))
2858                 RETVAL = 0;
2859     OUTPUT:
2860         RETVAL
2861
2862 int
2863 isgraph(charstring)
2864         unsigned char * charstring
2865     CODE:
2866         unsigned char *s = charstring;
2867         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2868         for (RETVAL = 1; RETVAL && s < e; s++)
2869             if (!isgraph(*s))
2870                 RETVAL = 0;
2871     OUTPUT:
2872         RETVAL
2873
2874 int
2875 islower(charstring)
2876         unsigned char * charstring
2877     CODE:
2878         unsigned char *s = charstring;
2879         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2880         for (RETVAL = 1; RETVAL && s < e; s++)
2881             if (!islower(*s))
2882                 RETVAL = 0;
2883     OUTPUT:
2884         RETVAL
2885
2886 int
2887 isprint(charstring)
2888         unsigned char * charstring
2889     CODE:
2890         unsigned char *s = charstring;
2891         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2892         for (RETVAL = 1; RETVAL && s < e; s++)
2893             if (!isprint(*s))
2894                 RETVAL = 0;
2895     OUTPUT:
2896         RETVAL
2897
2898 int
2899 ispunct(charstring)
2900         unsigned char * charstring
2901     CODE:
2902         unsigned char *s = charstring;
2903         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2904         for (RETVAL = 1; RETVAL && s < e; s++)
2905             if (!ispunct(*s))
2906                 RETVAL = 0;
2907     OUTPUT:
2908         RETVAL
2909
2910 int
2911 isspace(charstring)
2912         unsigned char * charstring
2913     CODE:
2914         unsigned char *s = charstring;
2915         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2916         for (RETVAL = 1; RETVAL && s < e; s++)
2917             if (!isspace(*s))
2918                 RETVAL = 0;
2919     OUTPUT:
2920         RETVAL
2921
2922 int
2923 isupper(charstring)
2924         unsigned char * charstring
2925     CODE:
2926         unsigned char *s = charstring;
2927         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2928         for (RETVAL = 1; RETVAL && s < e; s++)
2929             if (!isupper(*s))
2930                 RETVAL = 0;
2931     OUTPUT:
2932         RETVAL
2933
2934 int
2935 isxdigit(charstring)
2936         unsigned char * charstring
2937     CODE:
2938         unsigned char *s = charstring;
2939         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2940         for (RETVAL = 1; RETVAL && s < e; s++)
2941             if (!isxdigit(*s))
2942                 RETVAL = 0;
2943     OUTPUT:
2944         RETVAL
2945
2946 SysRet
2947 open(filename, flags = O_RDONLY, mode = 0666)
2948         char *          filename
2949         int             flags
2950         Mode_t          mode
2951     CODE:
2952         if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
2953             TAINT_PROPER("open");
2954         RETVAL = open(filename, flags, mode);
2955     OUTPUT:
2956         RETVAL
2957
2958
2959 HV *
2960 localeconv()
2961     CODE:
2962 #ifdef HAS_LOCALECONV
2963         struct lconv *lcbuf;
2964         RETVAL = newHV();
2965         if (lcbuf = localeconv()) {
2966             /* the strings */
2967             if (lcbuf->decimal_point && *lcbuf->decimal_point)
2968                 hv_store(RETVAL, "decimal_point", 13,
2969                     newSVpv(lcbuf->decimal_point, 0), 0);
2970             if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
2971                 hv_store(RETVAL, "thousands_sep", 13,
2972                     newSVpv(lcbuf->thousands_sep, 0), 0);
2973 #ifndef NO_LOCALECONV_GROUPING
2974             if (lcbuf->grouping && *lcbuf->grouping)
2975                 hv_store(RETVAL, "grouping", 8,
2976                     newSVpv(lcbuf->grouping, 0), 0);
2977 #endif
2978             if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
2979                 hv_store(RETVAL, "int_curr_symbol", 15,
2980                     newSVpv(lcbuf->int_curr_symbol, 0), 0);
2981             if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
2982                 hv_store(RETVAL, "currency_symbol", 15,
2983                     newSVpv(lcbuf->currency_symbol, 0), 0);
2984             if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
2985                 hv_store(RETVAL, "mon_decimal_point", 17,
2986                     newSVpv(lcbuf->mon_decimal_point, 0), 0);
2987 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
2988             if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
2989                 hv_store(RETVAL, "mon_thousands_sep", 17,
2990                     newSVpv(lcbuf->mon_thousands_sep, 0), 0);
2991 #endif                    
2992 #ifndef NO_LOCALECONV_MON_GROUPING
2993             if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
2994                 hv_store(RETVAL, "mon_grouping", 12,
2995                     newSVpv(lcbuf->mon_grouping, 0), 0);
2996 #endif
2997             if (lcbuf->positive_sign && *lcbuf->positive_sign)
2998                 hv_store(RETVAL, "positive_sign", 13,
2999                     newSVpv(lcbuf->positive_sign, 0), 0);
3000             if (lcbuf->negative_sign && *lcbuf->negative_sign)
3001                 hv_store(RETVAL, "negative_sign", 13,
3002                     newSVpv(lcbuf->negative_sign, 0), 0);
3003             /* the integers */
3004             if (lcbuf->int_frac_digits != CHAR_MAX)
3005                 hv_store(RETVAL, "int_frac_digits", 15,
3006                     newSViv(lcbuf->int_frac_digits), 0);
3007             if (lcbuf->frac_digits != CHAR_MAX)
3008                 hv_store(RETVAL, "frac_digits", 11,
3009                     newSViv(lcbuf->frac_digits), 0);
3010             if (lcbuf->p_cs_precedes != CHAR_MAX)
3011                 hv_store(RETVAL, "p_cs_precedes", 13,
3012                     newSViv(lcbuf->p_cs_precedes), 0);
3013             if (lcbuf->p_sep_by_space != CHAR_MAX)
3014                 hv_store(RETVAL, "p_sep_by_space", 14,
3015                     newSViv(lcbuf->p_sep_by_space), 0);
3016             if (lcbuf->n_cs_precedes != CHAR_MAX)
3017                 hv_store(RETVAL, "n_cs_precedes", 13,
3018                     newSViv(lcbuf->n_cs_precedes), 0);
3019             if (lcbuf->n_sep_by_space != CHAR_MAX)
3020                 hv_store(RETVAL, "n_sep_by_space", 14,
3021                     newSViv(lcbuf->n_sep_by_space), 0);
3022             if (lcbuf->p_sign_posn != CHAR_MAX)
3023                 hv_store(RETVAL, "p_sign_posn", 11,
3024                     newSViv(lcbuf->p_sign_posn), 0);
3025             if (lcbuf->n_sign_posn != CHAR_MAX)
3026                 hv_store(RETVAL, "n_sign_posn", 11,
3027                     newSViv(lcbuf->n_sign_posn), 0);
3028         }
3029 #else
3030         localeconv(); /* A stub to call not_here(). */
3031 #endif
3032     OUTPUT:
3033         RETVAL
3034
3035 char *
3036 setlocale(category, locale = 0)
3037         int             category
3038         char *          locale
3039     CODE:
3040         RETVAL = setlocale(category, locale);
3041         if (RETVAL) {
3042 #ifdef USE_LOCALE_CTYPE
3043             if (category == LC_CTYPE
3044 #ifdef LC_ALL
3045                 || category == LC_ALL
3046 #endif
3047                 )
3048             {
3049                 char *newctype;
3050 #ifdef LC_ALL
3051                 if (category == LC_ALL)
3052                     newctype = setlocale(LC_CTYPE, NULL);
3053                 else
3054 #endif
3055                     newctype = RETVAL;
3056                 new_ctype(newctype);
3057             }
3058 #endif /* USE_LOCALE_CTYPE */
3059 #ifdef USE_LOCALE_COLLATE
3060             if (category == LC_COLLATE
3061 #ifdef LC_ALL
3062                 || category == LC_ALL
3063 #endif
3064                 )
3065             {
3066                 char *newcoll;
3067 #ifdef LC_ALL
3068                 if (category == LC_ALL)
3069                     newcoll = setlocale(LC_COLLATE, NULL);
3070                 else
3071 #endif
3072                     newcoll = RETVAL;
3073                 new_collate(newcoll);
3074             }
3075 #endif /* USE_LOCALE_COLLATE */
3076 #ifdef USE_LOCALE_NUMERIC
3077             if (category == LC_NUMERIC
3078 #ifdef LC_ALL
3079                 || category == LC_ALL
3080 #endif
3081                 )
3082             {
3083                 char *newnum;
3084 #ifdef LC_ALL
3085                 if (category == LC_ALL)
3086                     newnum = setlocale(LC_NUMERIC, NULL);
3087                 else
3088 #endif
3089                     newnum = RETVAL;
3090                 new_numeric(newnum);
3091             }
3092 #endif /* USE_LOCALE_NUMERIC */
3093         }
3094     OUTPUT:
3095         RETVAL
3096
3097
3098 double
3099 acos(x)
3100         double          x
3101
3102 double
3103 asin(x)
3104         double          x
3105
3106 double
3107 atan(x)
3108         double          x
3109
3110 double
3111 ceil(x)
3112         double          x
3113
3114 double
3115 cosh(x)
3116         double          x
3117
3118 double
3119 floor(x)
3120         double          x
3121
3122 double
3123 fmod(x,y)
3124         double          x
3125         double          y
3126
3127 void
3128 frexp(x)
3129         double          x
3130     PPCODE:
3131         int expvar;
3132         /* (We already know stack is long enough.) */
3133         PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
3134         PUSHs(sv_2mortal(newSViv(expvar)));
3135
3136 double
3137 ldexp(x,exp)
3138         double          x
3139         int             exp
3140
3141 double
3142 log10(x)
3143         double          x
3144
3145 void
3146 modf(x)
3147         double          x
3148     PPCODE:
3149         double intvar;
3150         /* (We already know stack is long enough.) */
3151         PUSHs(sv_2mortal(newSVnv(modf(x,&intvar))));
3152         PUSHs(sv_2mortal(newSVnv(intvar)));
3153
3154 double
3155 sinh(x)
3156         double          x
3157
3158 double
3159 tan(x)
3160         double          x
3161
3162 double
3163 tanh(x)
3164         double          x
3165
3166 SysRet
3167 sigaction(sig, action, oldaction = 0)
3168         int                     sig
3169         POSIX::SigAction        action
3170         POSIX::SigAction        oldaction
3171     CODE:
3172 #ifdef WIN32
3173         RETVAL = not_here("sigaction");
3174 #else
3175 # This code is really grody because we're trying to make the signal
3176 # interface look beautiful, which is hard.
3177
3178         if (!PL_siggv)
3179             gv_fetchpv("SIG", TRUE, SVt_PVHV);
3180
3181         {
3182             struct sigaction act;
3183             struct sigaction oact;
3184             POSIX__SigSet sigset;
3185             SV** svp;
3186             SV** sigsvp = hv_fetch(GvHVn(PL_siggv),
3187                                  PL_sig_name[sig],
3188                                  strlen(PL_sig_name[sig]),
3189                                  TRUE);
3190             STRLEN n_a;
3191
3192             /* Remember old handler name if desired. */
3193             if (oldaction) {
3194                 char *hand = SvPVx(*sigsvp, n_a);
3195                 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
3196                 sv_setpv(*svp, *hand ? hand : "DEFAULT");
3197             }
3198
3199             if (action) {
3200                 /* Vector new handler through %SIG.  (We always use sighandler
3201                    for the C signal handler, which reads %SIG to dispatch.) */
3202                 svp = hv_fetch(action, "HANDLER", 7, FALSE);
3203                 if (!svp)
3204                     croak("Can't supply an action without a HANDLER");
3205                 sv_setpv(*sigsvp, SvPV(*svp, n_a));
3206                 mg_set(*sigsvp);        /* handles DEFAULT and IGNORE */
3207                 act.sa_handler = PL_sighandlerp;
3208
3209                 /* Set up any desired mask. */
3210                 svp = hv_fetch(action, "MASK", 4, FALSE);
3211                 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
3212                     unsigned long tmp;
3213                     tmp = (unsigned long)SvNV((SV*)SvRV(*svp));
3214                     sigset = (sigset_t*) tmp;
3215                     act.sa_mask = *sigset;
3216                 }
3217                 else
3218                     sigemptyset(& act.sa_mask);
3219
3220                 /* Set up any desired flags. */
3221                 svp = hv_fetch(action, "FLAGS", 5, FALSE);
3222                 act.sa_flags = svp ? SvIV(*svp) : 0;
3223             }
3224
3225             /* Now work around sigaction oddities */
3226             if (action && oldaction)
3227                 RETVAL = sigaction(sig, & act, & oact);
3228             else if (action)
3229                 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
3230             else if (oldaction)
3231                 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
3232             else
3233                 RETVAL = -1;
3234
3235             if (oldaction) {
3236                 /* Get back the mask. */
3237                 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
3238                 if (sv_isa(*svp, "POSIX::SigSet")) {
3239                     unsigned long tmp;
3240                     tmp = (unsigned long)SvNV((SV*)SvRV(*svp));
3241                     sigset = (sigset_t*) tmp;
3242                 }
3243                 else {
3244                     New(0, sigset, 1, sigset_t);
3245                     sv_setptrobj(*svp, sigset, "POSIX::SigSet");
3246                 }
3247                 *sigset = oact.sa_mask;
3248
3249                 /* Get back the flags. */
3250                 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
3251                 sv_setiv(*svp, oact.sa_flags);
3252             }
3253         }
3254 #endif
3255     OUTPUT:
3256         RETVAL
3257
3258 SysRet
3259 sigpending(sigset)
3260         POSIX::SigSet           sigset
3261
3262 SysRet
3263 sigprocmask(how, sigset, oldsigset = 0)
3264         int                     how
3265         POSIX::SigSet           sigset
3266         POSIX::SigSet           oldsigset = NO_INIT
3267 INIT:
3268         if ( items < 3 ) {
3269             oldsigset = 0;
3270         }
3271         else if (sv_derived_from(ST(2), "POSIX::SigSet")) {
3272             IV tmp = SvIV((SV*)SvRV(ST(2)));
3273             oldsigset = (POSIX__SigSet) tmp;
3274         }
3275         else {
3276             New(0, oldsigset, 1, sigset_t);
3277             sigemptyset(oldsigset);
3278             sv_setref_pv(ST(2), "POSIX::SigSet", (void*)oldsigset);
3279         }
3280
3281 SysRet
3282 sigsuspend(signal_mask)
3283         POSIX::SigSet           signal_mask
3284
3285 void
3286 _exit(status)
3287         int             status
3288
3289 SysRet
3290 close(fd)
3291         int             fd
3292
3293 SysRet
3294 dup(fd)
3295         int             fd
3296
3297 SysRet
3298 dup2(fd1, fd2)
3299         int             fd1
3300         int             fd2
3301
3302 SysRetLong
3303 lseek(fd, offset, whence)
3304         int             fd
3305         Off_t           offset
3306         int             whence
3307
3308 SysRet
3309 nice(incr)
3310         int             incr
3311
3312 int
3313 pipe()
3314     PPCODE:
3315         int fds[2];
3316         if (pipe(fds) != -1) {
3317             EXTEND(SP,2);
3318             PUSHs(sv_2mortal(newSViv(fds[0])));
3319             PUSHs(sv_2mortal(newSViv(fds[1])));
3320         }
3321
3322 SysRet
3323 read(fd, buffer, nbytes)
3324     PREINIT:
3325         SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
3326     INPUT:
3327         int             fd
3328         size_t          nbytes
3329         char *          buffer = sv_grow( sv_buffer, nbytes+1 );
3330     CLEANUP:
3331         if (RETVAL >= 0) {
3332             SvCUR(sv_buffer) = RETVAL;
3333             SvPOK_only(sv_buffer);
3334             *SvEND(sv_buffer) = '\0';
3335             SvTAINTED_on(sv_buffer);
3336         }
3337
3338 SysRet
3339 setpgid(pid, pgid)
3340         pid_t           pid
3341         pid_t           pgid
3342
3343 pid_t
3344 setsid()
3345
3346 pid_t
3347 tcgetpgrp(fd)
3348         int             fd
3349
3350 SysRet
3351 tcsetpgrp(fd, pgrp_id)
3352         int             fd
3353         pid_t           pgrp_id
3354
3355 int
3356 uname()
3357     PPCODE:
3358 #ifdef HAS_UNAME
3359         struct utsname buf;
3360         if (uname(&buf) >= 0) {
3361             EXTEND(SP, 5);
3362             PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
3363             PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
3364             PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
3365             PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
3366             PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
3367         }
3368 #else
3369         uname((char *) 0); /* A stub to call not_here(). */
3370 #endif
3371
3372 SysRet
3373 write(fd, buffer, nbytes)
3374         int             fd
3375         char *          buffer
3376         size_t          nbytes
3377
3378 SV *
3379 tmpnam()
3380     PREINIT:
3381         STRLEN i;
3382         int len;
3383     CODE:
3384         RETVAL = newSVpvn("", 0);
3385         SvGROW(RETVAL, L_tmpnam);
3386         len = strlen(tmpnam(SvPV(RETVAL, i)));
3387         SvCUR_set(RETVAL, len);
3388     OUTPUT:
3389         RETVAL
3390
3391 void
3392 abort()
3393
3394 int
3395 mblen(s, n)
3396         char *          s
3397         size_t          n
3398
3399 size_t
3400 mbstowcs(s, pwcs, n)
3401         wchar_t *       s
3402         char *          pwcs
3403         size_t          n
3404
3405 int
3406 mbtowc(pwc, s, n)
3407         wchar_t *       pwc
3408         char *          s
3409         size_t          n
3410
3411 int
3412 wcstombs(s, pwcs, n)
3413         char *          s
3414         wchar_t *       pwcs
3415         size_t          n
3416
3417 int
3418 wctomb(s, wchar)
3419         char *          s
3420         wchar_t         wchar
3421
3422 int
3423 strcoll(s1, s2)
3424         char *          s1
3425         char *          s2
3426
3427 void
3428 strtod(str)
3429         char *          str
3430     PREINIT:
3431         double num;
3432         char *unparsed;
3433     PPCODE:
3434         SET_NUMERIC_LOCAL();
3435         num = strtod(str, &unparsed);
3436         PUSHs(sv_2mortal(newSVnv(num)));
3437         if (GIMME == G_ARRAY) {
3438             EXTEND(SP, 1);
3439             if (unparsed)
3440                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3441             else
3442                 PUSHs(&PL_sv_undef);
3443         }
3444
3445 void
3446 strtol(str, base = 0)
3447         char *          str
3448         int             base
3449     PREINIT:
3450         long num;
3451         char *unparsed;
3452     PPCODE:
3453         num = strtol(str, &unparsed, base);
3454         if (num >= IV_MIN && num <= IV_MAX)
3455             PUSHs(sv_2mortal(newSViv((IV)num)));
3456         else
3457             PUSHs(sv_2mortal(newSVnv((double)num)));
3458         if (GIMME == G_ARRAY) {
3459             EXTEND(SP, 1);
3460             if (unparsed)
3461                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3462             else
3463                 PUSHs(&PL_sv_undef);
3464         }
3465
3466 void
3467 strtoul(str, base = 0)
3468         char *          str
3469         int             base
3470     PREINIT:
3471         unsigned long num;
3472         char *unparsed;
3473     PPCODE:
3474         num = strtoul(str, &unparsed, base);
3475         if (num <= IV_MAX)
3476             PUSHs(sv_2mortal(newSViv((IV)num)));
3477         else
3478             PUSHs(sv_2mortal(newSVnv((double)num)));
3479         if (GIMME == G_ARRAY) {
3480             EXTEND(SP, 1);
3481             if (unparsed)
3482                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3483             else
3484                 PUSHs(&PL_sv_undef);
3485         }
3486
3487 SV *
3488 strxfrm(src)
3489         SV *            src
3490     CODE:
3491         {
3492           STRLEN srclen;
3493           STRLEN dstlen;
3494           char *p = SvPV(src,srclen);
3495           srclen++;
3496           ST(0) = sv_2mortal(NEWSV(800,srclen));
3497           dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
3498           if (dstlen > srclen) {
3499               dstlen++;
3500               SvGROW(ST(0), dstlen);
3501               strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
3502               dstlen--;
3503           }
3504           SvCUR(ST(0)) = dstlen;
3505             SvPOK_only(ST(0));
3506         }
3507
3508 SysRet
3509 mkfifo(filename, mode)
3510         char *          filename
3511         Mode_t          mode
3512     CODE:
3513         TAINT_PROPER("mkfifo");
3514         RETVAL = mkfifo(filename, mode);
3515     OUTPUT:
3516         RETVAL
3517
3518 SysRet
3519 tcdrain(fd)
3520         int             fd
3521
3522
3523 SysRet
3524 tcflow(fd, action)
3525         int             fd
3526         int             action
3527
3528
3529 SysRet
3530 tcflush(fd, queue_selector)
3531         int             fd
3532         int             queue_selector
3533
3534 SysRet
3535 tcsendbreak(fd, duration)
3536         int             fd
3537         int             duration
3538
3539 char *
3540 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
3541         int             sec
3542         int             min
3543         int             hour
3544         int             mday
3545         int             mon
3546         int             year
3547         int             wday
3548         int             yday
3549         int             isdst
3550     CODE:
3551         {
3552             struct tm mytm;
3553             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3554             mytm.tm_sec = sec;
3555             mytm.tm_min = min;
3556             mytm.tm_hour = hour;
3557             mytm.tm_mday = mday;
3558             mytm.tm_mon = mon;
3559             mytm.tm_year = year;
3560             mytm.tm_wday = wday;
3561             mytm.tm_yday = yday;
3562             mytm.tm_isdst = isdst;
3563             RETVAL = asctime(&mytm);
3564         }
3565     OUTPUT:
3566         RETVAL
3567
3568 long
3569 clock()
3570
3571 char *
3572 ctime(time)
3573         Time_t          &time
3574
3575 void
3576 times()
3577         PPCODE:
3578         struct tms tms;
3579         clock_t realtime;
3580         realtime = times( &tms );
3581         EXTEND(SP,5);
3582         PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
3583         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
3584         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
3585         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
3586         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
3587
3588 double
3589 difftime(time1, time2)
3590         Time_t          time1
3591         Time_t          time2
3592
3593 SysRetLong
3594 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
3595         int             sec
3596         int             min
3597         int             hour
3598         int             mday
3599         int             mon
3600         int             year
3601         int             wday
3602         int             yday
3603         int             isdst
3604     CODE:
3605         {
3606             struct tm mytm;
3607             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3608             mytm.tm_sec = sec;
3609             mytm.tm_min = min;
3610             mytm.tm_hour = hour;
3611             mytm.tm_mday = mday;
3612             mytm.tm_mon = mon;
3613             mytm.tm_year = year;
3614             mytm.tm_wday = wday;
3615             mytm.tm_yday = yday;
3616             mytm.tm_isdst = isdst;
3617             RETVAL = mktime(&mytm);
3618         }
3619     OUTPUT:
3620         RETVAL
3621
3622 char *
3623 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
3624         char *          fmt
3625         int             sec
3626         int             min
3627         int             hour
3628         int             mday
3629         int             mon
3630         int             year
3631         int             wday
3632         int             yday
3633         int             isdst
3634     CODE:
3635         {
3636             char tmpbuf[128];
3637             struct tm mytm;
3638             int len;
3639             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3640             mytm.tm_sec = sec;
3641             mytm.tm_min = min;
3642             mytm.tm_hour = hour;
3643             mytm.tm_mday = mday;
3644             mytm.tm_mon = mon;
3645             mytm.tm_year = year;
3646             mytm.tm_wday = wday;
3647             mytm.tm_yday = yday;
3648             mytm.tm_isdst = isdst;
3649             (void) mktime(&mytm);
3650             len = strftime(tmpbuf, sizeof tmpbuf, fmt, &mytm);
3651             /*
3652             ** The following is needed to handle to the situation where 
3653             ** tmpbuf overflows.  Basically we want to allocate a buffer
3654             ** and try repeatedly.  The reason why it is so complicated
3655             ** is that getting a return value of 0 from strftime can indicate
3656             ** one of the following:
3657             ** 1. buffer overflowed,
3658             ** 2. illegal conversion specifier, or
3659             ** 3. the format string specifies nothing to be returned(not
3660             **    an error).  This could be because format is an empty string
3661             **    or it specifies %p that yields an empty string in some locale.
3662             ** If there is a better way to make it portable, go ahead by
3663             ** all means.
3664             */
3665             if ( ( len > 0 && len < sizeof(tmpbuf) )
3666                         || ( len == 0 && strlen(fmt) == 0 ) ) {
3667                 ST(0) = sv_2mortal(newSVpv(tmpbuf, len));
3668             } else {
3669                 /* Possibly buf overflowed - try again with a bigger buf */
3670                 int     bufsize = strlen(fmt) + sizeof(tmpbuf);
3671                 char*   buf;
3672                 int     buflen;
3673
3674                 New(0, buf, bufsize, char);
3675                 while( buf ) {
3676                     buflen = strftime(buf, bufsize, fmt, &mytm);
3677                     if ( buflen > 0 && buflen < bufsize ) break;
3678                     bufsize *= 2;
3679                     Renew(buf, bufsize, char);
3680                 }
3681                 if ( buf ) {
3682                     ST(0) = sv_2mortal(newSVpvn(buf, buflen));
3683                     Safefree(buf);
3684                 } else {
3685                     ST(0) = sv_2mortal(newSVpvn(tmpbuf, len));
3686                 }
3687             }
3688         }
3689
3690 void
3691 tzset()
3692
3693 void
3694 tzname()
3695     PPCODE:
3696         EXTEND(SP,2);
3697         PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
3698         PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
3699
3700 SysRet
3701 access(filename, mode)
3702         char *          filename
3703         Mode_t          mode
3704
3705 char *
3706 ctermid(s = 0)
3707         char *          s = 0;
3708
3709 char *
3710 cuserid(s = 0)
3711         char *          s = 0;
3712
3713 SysRetLong
3714 fpathconf(fd, name)
3715         int             fd
3716         int             name
3717
3718 SysRetLong
3719 pathconf(filename, name)
3720         char *          filename
3721         int             name
3722
3723 SysRet
3724 pause()
3725
3726 SysRetLong
3727 sysconf(name)
3728         int             name
3729
3730 char *
3731 ttyname(fd)
3732         int             fd