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