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