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