complete s/foo/PL_foo/ changes (all escaped cases identified with
[p5sagit/p5-mst-13.2.git] / ext / POSIX / POSIX.xs
1 #ifdef WIN32
2 #define _POSIX_
3 #endif
4 #include "EXTERN.h"
5 #define PERLIO_NOT_STDIO 1
6 #include "perl.h"
7 #include "XSUB.h"
8 #ifdef PERL_OBJECT      /* XXX _very_ temporary hacks */
9 #  undef signal
10 #  undef open
11 #  define open PerlLIO_open3
12 #  undef TAINT_PROPER
13 #  define TAINT_PROPER(a)
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             if (strEQ(name, "ELOOP"))
825 #ifdef ELOOP
826                 return ELOOP;
827 #else
828                 goto not_there;
829 #endif
830             break;
831         case 'M':
832             if (strEQ(name, "EMFILE"))
833 #ifdef EMFILE
834                 return EMFILE;
835 #else
836                 goto not_there;
837 #endif
838             if (strEQ(name, "EMLINK"))
839 #ifdef EMLINK
840                 return EMLINK;
841 #else
842                 goto not_there;
843 #endif
844             if (strEQ(name, "EMSGSIZE"))
845 #ifdef EMSGSIZE
846                 return EMSGSIZE;
847 #else
848                 goto not_there;
849 #endif
850             break;
851         case 'N':
852             if (strEQ(name, "ENETDOWN"))
853 #ifdef ENETDOWN
854                 return ENETDOWN;
855 #else
856                 goto not_there;
857 #endif
858             if (strEQ(name, "ENETRESET"))
859 #ifdef ENETRESET
860                 return ENETRESET;
861 #else
862                 goto not_there;
863 #endif
864             if (strEQ(name, "ENETUNREACH"))
865 #ifdef ENETUNREACH
866                 return ENETUNREACH;
867 #else
868                 goto not_there;
869 #endif
870             if (strEQ(name, "ENOBUFS"))
871 #ifdef ENOBUFS
872                 return ENOBUFS;
873 #else
874                 goto not_there;
875 #endif
876             if (strEQ(name, "ENOEXEC"))
877 #ifdef ENOEXEC
878                 return ENOEXEC;
879 #else
880                 goto not_there;
881 #endif
882             if (strEQ(name, "ENOMEM"))
883 #ifdef ENOMEM
884                 return ENOMEM;
885 #else
886                 goto not_there;
887 #endif
888             if (strEQ(name, "ENOPROTOOPT"))
889 #ifdef ENOPROTOOPT
890                 return ENOPROTOOPT;
891 #else
892                 goto not_there;
893 #endif
894             if (strEQ(name, "ENOSPC"))
895 #ifdef ENOSPC
896                 return ENOSPC;
897 #else
898                 goto not_there;
899 #endif
900             if (strEQ(name, "ENOTBLK"))
901 #ifdef ENOTBLK
902                 return ENOTBLK;
903 #else
904                 goto not_there;
905 #endif
906             if (strEQ(name, "ENOTCONN"))
907 #ifdef ENOTCONN
908                 return ENOTCONN;
909 #else
910                 goto not_there;
911 #endif
912             if (strEQ(name, "ENOTDIR"))
913 #ifdef ENOTDIR
914                 return ENOTDIR;
915 #else
916                 goto not_there;
917 #endif
918             if (strEQ(name, "ENOTEMPTY"))
919 #ifdef ENOTEMPTY
920                 return ENOTEMPTY;
921 #else
922                 goto not_there;
923 #endif
924             if (strEQ(name, "ENOTSOCK"))
925 #ifdef ENOTSOCK
926                 return ENOTSOCK;
927 #else
928                 goto not_there;
929 #endif
930             if (strEQ(name, "ENOTTY"))
931 #ifdef ENOTTY
932                 return ENOTTY;
933 #else
934                 goto not_there;
935 #endif
936             if (strEQ(name, "ENFILE"))
937 #ifdef ENFILE
938                 return ENFILE;
939 #else
940                 goto not_there;
941 #endif
942             if (strEQ(name, "ENODEV"))
943 #ifdef ENODEV
944                 return ENODEV;
945 #else
946                 goto not_there;
947 #endif
948             if (strEQ(name, "ENOENT"))
949 #ifdef ENOENT
950                 return ENOENT;
951 #else
952                 goto not_there;
953 #endif
954             if (strEQ(name, "ENOLCK"))
955 #ifdef ENOLCK
956                 return ENOLCK;
957 #else
958                 goto not_there;
959 #endif
960             if (strEQ(name, "ENOSYS"))
961 #ifdef ENOSYS
962                 return ENOSYS;
963 #else
964                 goto not_there;
965 #endif
966             if (strEQ(name, "ENXIO"))
967 #ifdef ENXIO
968                 return ENXIO;
969 #else
970                 goto not_there;
971 #endif
972             if (strEQ(name, "ENAMETOOLONG"))
973 #ifdef ENAMETOOLONG
974                 return ENAMETOOLONG;
975 #else
976                 goto not_there;
977 #endif
978             break;
979         case 'O':
980             if (strEQ(name, "EOF"))
981 #ifdef EOF
982                 return EOF;
983 #else
984                 goto not_there;
985 #endif
986             if (strEQ(name, "EOPNOTSUPP"))
987 #ifdef EOPNOTSUPP
988                 return EOPNOTSUPP;
989 #else
990                 goto not_there;
991 #endif
992             break;
993         case 'P':
994             if (strEQ(name, "EPERM"))
995 #ifdef EPERM
996                 return EPERM;
997 #else
998                 goto not_there;
999 #endif
1000             if (strEQ(name, "EPFNOSUPPORT"))
1001 #ifdef EPFNOSUPPORT
1002                 return EPFNOSUPPORT;
1003 #else
1004                 goto not_there;
1005 #endif
1006             if (strEQ(name, "EPIPE"))
1007 #ifdef EPIPE
1008                 return EPIPE;
1009 #else
1010                 goto not_there;
1011 #endif
1012             if (strEQ(name, "EPROCLIM"))
1013 #ifdef EPROCLIM
1014                 return EPROCLIM;
1015 #else
1016                 goto not_there;
1017 #endif
1018             if (strEQ(name, "EPROTONOSUPPORT"))
1019 #ifdef EPROTONOSUPPORT
1020                 return EPROTONOSUPPORT;
1021 #else
1022                 goto not_there;
1023 #endif
1024             if (strEQ(name, "EPROTOTYPE"))
1025 #ifdef EPROTOTYPE
1026                 return EPROTOTYPE;
1027 #else
1028                 goto not_there;
1029 #endif
1030             break;
1031         case 'R':
1032             if (strEQ(name, "ERANGE"))
1033 #ifdef ERANGE
1034                 return ERANGE;
1035 #else
1036                 goto not_there;
1037 #endif
1038             if (strEQ(name, "EREMOTE"))
1039 #ifdef EREMOTE
1040                 return EREMOTE;
1041 #else
1042                 goto not_there;
1043 #endif
1044             if (strEQ(name, "ERESTART"))
1045 #ifdef ERESTART
1046                 return ERESTART;
1047 #else
1048                 goto not_there;
1049 #endif
1050             if (strEQ(name, "EROFS"))
1051 #ifdef EROFS
1052                 return EROFS;
1053 #else
1054                 goto not_there;
1055 #endif
1056             break;
1057         case 'S':
1058             if (strEQ(name, "ESHUTDOWN"))
1059 #ifdef ESHUTDOWN
1060                 return ESHUTDOWN;
1061 #else
1062                 goto not_there;
1063 #endif
1064             if (strEQ(name, "ESOCKTNOSUPPORT"))
1065 #ifdef ESOCKTNOSUPPORT
1066                 return ESOCKTNOSUPPORT;
1067 #else
1068                 goto not_there;
1069 #endif
1070             if (strEQ(name, "ESPIPE"))
1071 #ifdef ESPIPE
1072                 return ESPIPE;
1073 #else
1074                 goto not_there;
1075 #endif
1076             if (strEQ(name, "ESRCH"))
1077 #ifdef ESRCH
1078                 return ESRCH;
1079 #else
1080                 goto not_there;
1081 #endif
1082             if (strEQ(name, "ESTALE"))
1083 #ifdef ESTALE
1084                 return ESTALE;
1085 #else
1086                 goto not_there;
1087 #endif
1088             break;
1089         case 'T':
1090             if (strEQ(name, "ETIMEDOUT"))
1091 #ifdef ETIMEDOUT
1092                 return ETIMEDOUT;
1093 #else
1094                 goto not_there;
1095 #endif
1096             if (strEQ(name, "ETOOMANYREFS"))
1097 #ifdef ETOOMANYREFS
1098                 return ETOOMANYREFS;
1099 #else
1100                 goto not_there;
1101 #endif
1102             if (strEQ(name, "ETXTBSY"))
1103 #ifdef ETXTBSY
1104                 return ETXTBSY;
1105 #else
1106                 goto not_there;
1107 #endif
1108             break;
1109         case 'U':
1110             if (strEQ(name, "EUSERS"))
1111 #ifdef EUSERS
1112                 return EUSERS;
1113 #else
1114                 goto not_there;
1115 #endif
1116             break;
1117         case 'W':
1118             if (strEQ(name, "EWOULDBLOCK"))
1119 #ifdef EWOULDBLOCK
1120                 return EWOULDBLOCK;
1121 #else
1122                 goto not_there;
1123 #endif
1124             break;
1125         case 'X':
1126             if (strEQ(name, "EXIT_FAILURE"))
1127 #ifdef EXIT_FAILURE
1128                 return EXIT_FAILURE;
1129 #else
1130                 return 1;
1131 #endif
1132             if (strEQ(name, "EXIT_SUCCESS"))
1133 #ifdef EXIT_SUCCESS
1134                 return EXIT_SUCCESS;
1135 #else
1136                 return 0;
1137 #endif
1138             if (strEQ(name, "EXDEV"))
1139 #ifdef EXDEV
1140                 return EXDEV;
1141 #else
1142                 goto not_there;
1143 #endif
1144             break;
1145         }
1146         if (strEQ(name, "E2BIG"))
1147 #ifdef E2BIG
1148             return E2BIG;
1149 #else
1150             goto not_there;
1151 #endif
1152         break;
1153     case 'F':
1154         if (strnEQ(name, "FLT_", 4)) {
1155             if (strEQ(name, "FLT_MAX"))
1156 #ifdef FLT_MAX
1157                 return FLT_MAX;
1158 #else
1159                 goto not_there;
1160 #endif
1161             if (strEQ(name, "FLT_MIN"))
1162 #ifdef FLT_MIN
1163                 return FLT_MIN;
1164 #else
1165                 goto not_there;
1166 #endif
1167             if (strEQ(name, "FLT_ROUNDS"))
1168 #ifdef FLT_ROUNDS
1169                 return FLT_ROUNDS;
1170 #else
1171                 goto not_there;
1172 #endif
1173             if (strEQ(name, "FLT_DIG"))
1174 #ifdef FLT_DIG
1175                 return FLT_DIG;
1176 #else
1177                 goto not_there;
1178 #endif
1179             if (strEQ(name, "FLT_EPSILON"))
1180 #ifdef FLT_EPSILON
1181                 return FLT_EPSILON;
1182 #else
1183                 goto not_there;
1184 #endif
1185             if (strEQ(name, "FLT_MANT_DIG"))
1186 #ifdef FLT_MANT_DIG
1187                 return FLT_MANT_DIG;
1188 #else
1189                 goto not_there;
1190 #endif
1191             if (strEQ(name, "FLT_MAX_10_EXP"))
1192 #ifdef FLT_MAX_10_EXP
1193                 return FLT_MAX_10_EXP;
1194 #else
1195                 goto not_there;
1196 #endif
1197             if (strEQ(name, "FLT_MAX_EXP"))
1198 #ifdef FLT_MAX_EXP
1199                 return FLT_MAX_EXP;
1200 #else
1201                 goto not_there;
1202 #endif
1203             if (strEQ(name, "FLT_MIN_10_EXP"))
1204 #ifdef FLT_MIN_10_EXP
1205                 return FLT_MIN_10_EXP;
1206 #else
1207                 goto not_there;
1208 #endif
1209             if (strEQ(name, "FLT_MIN_EXP"))
1210 #ifdef FLT_MIN_EXP
1211                 return FLT_MIN_EXP;
1212 #else
1213                 goto not_there;
1214 #endif
1215             if (strEQ(name, "FLT_RADIX"))
1216 #ifdef FLT_RADIX
1217                 return FLT_RADIX;
1218 #else
1219                 goto not_there;
1220 #endif
1221             break;
1222         }
1223         if (strnEQ(name, "F_", 2)) {
1224             if (strEQ(name, "F_DUPFD"))
1225 #ifdef F_DUPFD
1226                 return F_DUPFD;
1227 #else
1228                 goto not_there;
1229 #endif
1230             if (strEQ(name, "F_GETFD"))
1231 #ifdef F_GETFD
1232                 return F_GETFD;
1233 #else
1234                 goto not_there;
1235 #endif
1236             if (strEQ(name, "F_GETFL"))
1237 #ifdef F_GETFL
1238                 return F_GETFL;
1239 #else
1240                 goto not_there;
1241 #endif
1242             if (strEQ(name, "F_GETLK"))
1243 #ifdef F_GETLK
1244                 return F_GETLK;
1245 #else
1246                 goto not_there;
1247 #endif
1248             if (strEQ(name, "F_OK"))
1249 #ifdef F_OK
1250                 return F_OK;
1251 #else
1252                 goto not_there;
1253 #endif
1254             if (strEQ(name, "F_RDLCK"))
1255 #ifdef F_RDLCK
1256                 return F_RDLCK;
1257 #else
1258                 goto not_there;
1259 #endif
1260             if (strEQ(name, "F_SETFD"))
1261 #ifdef F_SETFD
1262                 return F_SETFD;
1263 #else
1264                 goto not_there;
1265 #endif
1266             if (strEQ(name, "F_SETFL"))
1267 #ifdef F_SETFL
1268                 return F_SETFL;
1269 #else
1270                 goto not_there;
1271 #endif
1272             if (strEQ(name, "F_SETLK"))
1273 #ifdef F_SETLK
1274                 return F_SETLK;
1275 #else
1276                 goto not_there;
1277 #endif
1278             if (strEQ(name, "F_SETLKW"))
1279 #ifdef F_SETLKW
1280                 return F_SETLKW;
1281 #else
1282                 goto not_there;
1283 #endif
1284             if (strEQ(name, "F_UNLCK"))
1285 #ifdef F_UNLCK
1286                 return F_UNLCK;
1287 #else
1288                 goto not_there;
1289 #endif
1290             if (strEQ(name, "F_WRLCK"))
1291 #ifdef F_WRLCK
1292                 return F_WRLCK;
1293 #else
1294                 goto not_there;
1295 #endif
1296             break;
1297         }
1298         if (strEQ(name, "FD_CLOEXEC"))
1299 #ifdef FD_CLOEXEC
1300             return FD_CLOEXEC;
1301 #else
1302             goto not_there;
1303 #endif
1304         if (strEQ(name, "FILENAME_MAX"))
1305 #ifdef FILENAME_MAX
1306             return FILENAME_MAX;
1307 #else
1308             goto not_there;
1309 #endif
1310         break;
1311     case 'H':
1312         if (strEQ(name, "HUGE_VAL"))
1313 #ifdef HUGE_VAL
1314             return HUGE_VAL;
1315 #else
1316             goto not_there;
1317 #endif
1318         if (strEQ(name, "HUPCL"))
1319 #ifdef HUPCL
1320             return HUPCL;
1321 #else
1322             goto not_there;
1323 #endif
1324         break;
1325     case 'I':
1326         if (strEQ(name, "INT_MAX"))
1327 #ifdef INT_MAX
1328             return INT_MAX;
1329 #else
1330             goto not_there;
1331 #endif
1332         if (strEQ(name, "INT_MIN"))
1333 #ifdef INT_MIN
1334             return INT_MIN;
1335 #else
1336             goto not_there;
1337 #endif
1338         if (strEQ(name, "ICANON"))
1339 #ifdef ICANON
1340             return ICANON;
1341 #else
1342             goto not_there;
1343 #endif
1344         if (strEQ(name, "ICRNL"))
1345 #ifdef ICRNL
1346             return ICRNL;
1347 #else
1348             goto not_there;
1349 #endif
1350         if (strEQ(name, "IEXTEN"))
1351 #ifdef IEXTEN
1352             return IEXTEN;
1353 #else
1354             goto not_there;
1355 #endif
1356         if (strEQ(name, "IGNBRK"))
1357 #ifdef IGNBRK
1358             return IGNBRK;
1359 #else
1360             goto not_there;
1361 #endif
1362         if (strEQ(name, "IGNCR"))
1363 #ifdef IGNCR
1364             return IGNCR;
1365 #else
1366             goto not_there;
1367 #endif
1368         if (strEQ(name, "IGNPAR"))
1369 #ifdef IGNPAR
1370             return IGNPAR;
1371 #else
1372             goto not_there;
1373 #endif
1374         if (strEQ(name, "INLCR"))
1375 #ifdef INLCR
1376             return INLCR;
1377 #else
1378             goto not_there;
1379 #endif
1380         if (strEQ(name, "INPCK"))
1381 #ifdef INPCK
1382             return INPCK;
1383 #else
1384             goto not_there;
1385 #endif
1386         if (strEQ(name, "ISIG"))
1387 #ifdef ISIG
1388             return ISIG;
1389 #else
1390             goto not_there;
1391 #endif
1392         if (strEQ(name, "ISTRIP"))
1393 #ifdef ISTRIP
1394             return ISTRIP;
1395 #else
1396             goto not_there;
1397 #endif
1398         if (strEQ(name, "IXOFF"))
1399 #ifdef IXOFF
1400             return IXOFF;
1401 #else
1402             goto not_there;
1403 #endif
1404         if (strEQ(name, "IXON"))
1405 #ifdef IXON
1406             return IXON;
1407 #else
1408             goto not_there;
1409 #endif
1410         break;
1411     case 'L':
1412         if (strnEQ(name, "LC_", 3)) {
1413             if (strEQ(name, "LC_ALL"))
1414 #ifdef LC_ALL
1415                 return LC_ALL;
1416 #else
1417                 goto not_there;
1418 #endif
1419             if (strEQ(name, "LC_COLLATE"))
1420 #ifdef LC_COLLATE
1421                 return LC_COLLATE;
1422 #else
1423                 goto not_there;
1424 #endif
1425             if (strEQ(name, "LC_CTYPE"))
1426 #ifdef LC_CTYPE
1427                 return LC_CTYPE;
1428 #else
1429                 goto not_there;
1430 #endif
1431             if (strEQ(name, "LC_MONETARY"))
1432 #ifdef LC_MONETARY
1433                 return LC_MONETARY;
1434 #else
1435                 goto not_there;
1436 #endif
1437             if (strEQ(name, "LC_NUMERIC"))
1438 #ifdef LC_NUMERIC
1439                 return LC_NUMERIC;
1440 #else
1441                 goto not_there;
1442 #endif
1443             if (strEQ(name, "LC_TIME"))
1444 #ifdef LC_TIME
1445                 return LC_TIME;
1446 #else
1447                 goto not_there;
1448 #endif
1449             break;
1450         }
1451         if (strnEQ(name, "LDBL_", 5)) {
1452             if (strEQ(name, "LDBL_MAX"))
1453 #ifdef LDBL_MAX
1454                 return LDBL_MAX;
1455 #else
1456                 goto not_there;
1457 #endif
1458             if (strEQ(name, "LDBL_MIN"))
1459 #ifdef LDBL_MIN
1460                 return LDBL_MIN;
1461 #else
1462                 goto not_there;
1463 #endif
1464             if (strEQ(name, "LDBL_DIG"))
1465 #ifdef LDBL_DIG
1466                 return LDBL_DIG;
1467 #else
1468                 goto not_there;
1469 #endif
1470             if (strEQ(name, "LDBL_EPSILON"))
1471 #ifdef LDBL_EPSILON
1472                 return LDBL_EPSILON;
1473 #else
1474                 goto not_there;
1475 #endif
1476             if (strEQ(name, "LDBL_MANT_DIG"))
1477 #ifdef LDBL_MANT_DIG
1478                 return LDBL_MANT_DIG;
1479 #else
1480                 goto not_there;
1481 #endif
1482             if (strEQ(name, "LDBL_MAX_10_EXP"))
1483 #ifdef LDBL_MAX_10_EXP
1484                 return LDBL_MAX_10_EXP;
1485 #else
1486                 goto not_there;
1487 #endif
1488             if (strEQ(name, "LDBL_MAX_EXP"))
1489 #ifdef LDBL_MAX_EXP
1490                 return LDBL_MAX_EXP;
1491 #else
1492                 goto not_there;
1493 #endif
1494             if (strEQ(name, "LDBL_MIN_10_EXP"))
1495 #ifdef LDBL_MIN_10_EXP
1496                 return LDBL_MIN_10_EXP;
1497 #else
1498                 goto not_there;
1499 #endif
1500             if (strEQ(name, "LDBL_MIN_EXP"))
1501 #ifdef LDBL_MIN_EXP
1502                 return LDBL_MIN_EXP;
1503 #else
1504                 goto not_there;
1505 #endif
1506             break;
1507         }
1508         if (strnEQ(name, "L_", 2)) {
1509             if (strEQ(name, "L_ctermid"))
1510 #ifdef L_ctermid
1511                 return L_ctermid;
1512 #else
1513                 goto not_there;
1514 #endif
1515             if (strEQ(name, "L_cuserid"))
1516 #ifdef L_cuserid
1517                 return L_cuserid;
1518 #else
1519                 goto not_there;
1520 #endif
1521             if (strEQ(name, "L_tmpname"))
1522 #ifdef L_tmpname
1523                 return L_tmpname;
1524 #else
1525                 goto not_there;
1526 #endif
1527             break;
1528         }
1529         if (strEQ(name, "LONG_MAX"))
1530 #ifdef LONG_MAX
1531             return LONG_MAX;
1532 #else
1533             goto not_there;
1534 #endif
1535         if (strEQ(name, "LONG_MIN"))
1536 #ifdef LONG_MIN
1537             return LONG_MIN;
1538 #else
1539             goto not_there;
1540 #endif
1541         if (strEQ(name, "LINK_MAX"))
1542 #ifdef LINK_MAX
1543             return LINK_MAX;
1544 #else
1545             goto not_there;
1546 #endif
1547         break;
1548     case 'M':
1549         if (strEQ(name, "MAX_CANON"))
1550 #ifdef MAX_CANON
1551             return MAX_CANON;
1552 #else
1553             goto not_there;
1554 #endif
1555         if (strEQ(name, "MAX_INPUT"))
1556 #ifdef MAX_INPUT
1557             return MAX_INPUT;
1558 #else
1559             goto not_there;
1560 #endif
1561         if (strEQ(name, "MB_CUR_MAX"))
1562 #ifdef MB_CUR_MAX
1563             return MB_CUR_MAX;
1564 #else
1565             goto not_there;
1566 #endif
1567         if (strEQ(name, "MB_LEN_MAX"))
1568 #ifdef MB_LEN_MAX
1569             return MB_LEN_MAX;
1570 #else
1571             goto not_there;
1572 #endif
1573         break;
1574     case 'N':
1575         if (strEQ(name, "NULL")) return 0;
1576         if (strEQ(name, "NAME_MAX"))
1577 #ifdef NAME_MAX
1578             return NAME_MAX;
1579 #else
1580             goto not_there;
1581 #endif
1582         if (strEQ(name, "NCCS"))
1583 #ifdef NCCS
1584             return NCCS;
1585 #else
1586             goto not_there;
1587 #endif
1588         if (strEQ(name, "NGROUPS_MAX"))
1589 #ifdef NGROUPS_MAX
1590             return NGROUPS_MAX;
1591 #else
1592             goto not_there;
1593 #endif
1594         if (strEQ(name, "NOFLSH"))
1595 #ifdef NOFLSH
1596             return NOFLSH;
1597 #else
1598             goto not_there;
1599 #endif
1600         break;
1601     case 'O':
1602         if (strnEQ(name, "O_", 2)) {
1603             if (strEQ(name, "O_APPEND"))
1604 #ifdef O_APPEND
1605                 return O_APPEND;
1606 #else
1607                 goto not_there;
1608 #endif
1609             if (strEQ(name, "O_CREAT"))
1610 #ifdef O_CREAT
1611                 return O_CREAT;
1612 #else
1613                 goto not_there;
1614 #endif
1615             if (strEQ(name, "O_TRUNC"))
1616 #ifdef O_TRUNC
1617                 return O_TRUNC;
1618 #else
1619                 goto not_there;
1620 #endif
1621             if (strEQ(name, "O_RDONLY"))
1622 #ifdef O_RDONLY
1623                 return O_RDONLY;
1624 #else
1625                 goto not_there;
1626 #endif
1627             if (strEQ(name, "O_RDWR"))
1628 #ifdef O_RDWR
1629                 return O_RDWR;
1630 #else
1631                 goto not_there;
1632 #endif
1633             if (strEQ(name, "O_WRONLY"))
1634 #ifdef O_WRONLY
1635                 return O_WRONLY;
1636 #else
1637                 goto not_there;
1638 #endif
1639             if (strEQ(name, "O_EXCL"))
1640 #ifdef O_EXCL
1641                 return O_EXCL;
1642 #else
1643                 goto not_there;
1644 #endif
1645             if (strEQ(name, "O_NOCTTY"))
1646 #ifdef O_NOCTTY
1647                 return O_NOCTTY;
1648 #else
1649                 goto not_there;
1650 #endif
1651             if (strEQ(name, "O_NONBLOCK"))
1652 #ifdef O_NONBLOCK
1653                 return O_NONBLOCK;
1654 #else
1655                 goto not_there;
1656 #endif
1657             if (strEQ(name, "O_ACCMODE"))
1658 #ifdef O_ACCMODE
1659                 return O_ACCMODE;
1660 #else
1661                 goto not_there;
1662 #endif
1663             break;
1664         }
1665         if (strEQ(name, "OPEN_MAX"))
1666 #ifdef OPEN_MAX
1667             return OPEN_MAX;
1668 #else
1669             goto not_there;
1670 #endif
1671         if (strEQ(name, "OPOST"))
1672 #ifdef OPOST
1673             return OPOST;
1674 #else
1675             goto not_there;
1676 #endif
1677         break;
1678     case 'P':
1679         if (strEQ(name, "PATH_MAX"))
1680 #ifdef PATH_MAX
1681             return PATH_MAX;
1682 #else
1683             goto not_there;
1684 #endif
1685         if (strEQ(name, "PARENB"))
1686 #ifdef PARENB
1687             return PARENB;
1688 #else
1689             goto not_there;
1690 #endif
1691         if (strEQ(name, "PARMRK"))
1692 #ifdef PARMRK
1693             return PARMRK;
1694 #else
1695             goto not_there;
1696 #endif
1697         if (strEQ(name, "PARODD"))
1698 #ifdef PARODD
1699             return PARODD;
1700 #else
1701             goto not_there;
1702 #endif
1703         if (strEQ(name, "PIPE_BUF"))
1704 #ifdef PIPE_BUF
1705             return PIPE_BUF;
1706 #else
1707             goto not_there;
1708 #endif
1709         break;
1710     case 'R':
1711         if (strEQ(name, "RAND_MAX"))
1712 #ifdef RAND_MAX
1713             return RAND_MAX;
1714 #else
1715             goto not_there;
1716 #endif
1717         if (strEQ(name, "R_OK"))
1718 #ifdef R_OK
1719             return R_OK;
1720 #else
1721             goto not_there;
1722 #endif
1723         break;
1724     case 'S':
1725         if (strnEQ(name, "SIG", 3)) {
1726             if (name[3] == '_') {
1727                 if (strEQ(name, "SIG_BLOCK"))
1728 #ifdef SIG_BLOCK
1729                     return SIG_BLOCK;
1730 #else
1731                     goto not_there;
1732 #endif
1733 #ifdef SIG_DFL
1734                 if (strEQ(name, "SIG_DFL")) return (IV)SIG_DFL;
1735 #endif
1736 #ifdef SIG_ERR
1737                 if (strEQ(name, "SIG_ERR")) return (IV)SIG_ERR;
1738 #endif
1739 #ifdef SIG_IGN
1740                 if (strEQ(name, "SIG_IGN")) return (IV)SIG_IGN;
1741 #endif
1742                 if (strEQ(name, "SIG_SETMASK"))
1743 #ifdef SIG_SETMASK
1744                     return SIG_SETMASK;
1745 #else
1746                     goto not_there;
1747 #endif
1748                 if (strEQ(name, "SIG_UNBLOCK"))
1749 #ifdef SIG_UNBLOCK
1750                     return SIG_UNBLOCK;
1751 #else
1752                     goto not_there;
1753 #endif
1754                 break;
1755             }
1756             if (strEQ(name, "SIGABRT"))
1757 #ifdef SIGABRT
1758                 return SIGABRT;
1759 #else
1760                 goto not_there;
1761 #endif
1762             if (strEQ(name, "SIGALRM"))
1763 #ifdef SIGALRM
1764                 return SIGALRM;
1765 #else
1766                 goto not_there;
1767 #endif
1768             if (strEQ(name, "SIGCHLD"))
1769 #ifdef SIGCHLD
1770                 return SIGCHLD;
1771 #else
1772                 goto not_there;
1773 #endif
1774             if (strEQ(name, "SIGCONT"))
1775 #ifdef SIGCONT
1776                 return SIGCONT;
1777 #else
1778                 goto not_there;
1779 #endif
1780             if (strEQ(name, "SIGFPE"))
1781 #ifdef SIGFPE
1782                 return SIGFPE;
1783 #else
1784                 goto not_there;
1785 #endif
1786             if (strEQ(name, "SIGHUP"))
1787 #ifdef SIGHUP
1788                 return SIGHUP;
1789 #else
1790                 goto not_there;
1791 #endif
1792             if (strEQ(name, "SIGILL"))
1793 #ifdef SIGILL
1794                 return SIGILL;
1795 #else
1796                 goto not_there;
1797 #endif
1798             if (strEQ(name, "SIGINT"))
1799 #ifdef SIGINT
1800                 return SIGINT;
1801 #else
1802                 goto not_there;
1803 #endif
1804             if (strEQ(name, "SIGKILL"))
1805 #ifdef SIGKILL
1806                 return SIGKILL;
1807 #else
1808                 goto not_there;
1809 #endif
1810             if (strEQ(name, "SIGPIPE"))
1811 #ifdef SIGPIPE
1812                 return SIGPIPE;
1813 #else
1814                 goto not_there;
1815 #endif
1816             if (strEQ(name, "SIGQUIT"))
1817 #ifdef SIGQUIT
1818                 return SIGQUIT;
1819 #else
1820                 goto not_there;
1821 #endif
1822             if (strEQ(name, "SIGSEGV"))
1823 #ifdef SIGSEGV
1824                 return SIGSEGV;
1825 #else
1826                 goto not_there;
1827 #endif
1828             if (strEQ(name, "SIGSTOP"))
1829 #ifdef SIGSTOP
1830                 return SIGSTOP;
1831 #else
1832                 goto not_there;
1833 #endif
1834             if (strEQ(name, "SIGTERM"))
1835 #ifdef SIGTERM
1836                 return SIGTERM;
1837 #else
1838                 goto not_there;
1839 #endif
1840             if (strEQ(name, "SIGTSTP"))
1841 #ifdef SIGTSTP
1842                 return SIGTSTP;
1843 #else
1844                 goto not_there;
1845 #endif
1846             if (strEQ(name, "SIGTTIN"))
1847 #ifdef SIGTTIN
1848                 return SIGTTIN;
1849 #else
1850                 goto not_there;
1851 #endif
1852             if (strEQ(name, "SIGTTOU"))
1853 #ifdef SIGTTOU
1854                 return SIGTTOU;
1855 #else
1856                 goto not_there;
1857 #endif
1858             if (strEQ(name, "SIGUSR1"))
1859 #ifdef SIGUSR1
1860                 return SIGUSR1;
1861 #else
1862                 goto not_there;
1863 #endif
1864             if (strEQ(name, "SIGUSR2"))
1865 #ifdef SIGUSR2
1866                 return SIGUSR2;
1867 #else
1868                 goto not_there;
1869 #endif
1870             break;
1871         }
1872         if (name[1] == '_') {
1873             if (strEQ(name, "S_ISGID"))
1874 #ifdef S_ISGID
1875                 return S_ISGID;
1876 #else
1877                 goto not_there;
1878 #endif
1879             if (strEQ(name, "S_ISUID"))
1880 #ifdef S_ISUID
1881                 return S_ISUID;
1882 #else
1883                 goto not_there;
1884 #endif
1885             if (strEQ(name, "S_IRGRP"))
1886 #ifdef S_IRGRP
1887                 return S_IRGRP;
1888 #else
1889                 goto not_there;
1890 #endif
1891             if (strEQ(name, "S_IROTH"))
1892 #ifdef S_IROTH
1893                 return S_IROTH;
1894 #else
1895                 goto not_there;
1896 #endif
1897             if (strEQ(name, "S_IRUSR"))
1898 #ifdef S_IRUSR
1899                 return S_IRUSR;
1900 #else
1901                 goto not_there;
1902 #endif
1903             if (strEQ(name, "S_IRWXG"))
1904 #ifdef S_IRWXG
1905                 return S_IRWXG;
1906 #else
1907                 goto not_there;
1908 #endif
1909             if (strEQ(name, "S_IRWXO"))
1910 #ifdef S_IRWXO
1911                 return S_IRWXO;
1912 #else
1913                 goto not_there;
1914 #endif
1915             if (strEQ(name, "S_IRWXU"))
1916 #ifdef S_IRWXU
1917                 return S_IRWXU;
1918 #else
1919                 goto not_there;
1920 #endif
1921             if (strEQ(name, "S_IWGRP"))
1922 #ifdef S_IWGRP
1923                 return S_IWGRP;
1924 #else
1925                 goto not_there;
1926 #endif
1927             if (strEQ(name, "S_IWOTH"))
1928 #ifdef S_IWOTH
1929                 return S_IWOTH;
1930 #else
1931                 goto not_there;
1932 #endif
1933             if (strEQ(name, "S_IWUSR"))
1934 #ifdef S_IWUSR
1935                 return S_IWUSR;
1936 #else
1937                 goto not_there;
1938 #endif
1939             if (strEQ(name, "S_IXGRP"))
1940 #ifdef S_IXGRP
1941                 return S_IXGRP;
1942 #else
1943                 goto not_there;
1944 #endif
1945             if (strEQ(name, "S_IXOTH"))
1946 #ifdef S_IXOTH
1947                 return S_IXOTH;
1948 #else
1949                 goto not_there;
1950 #endif
1951             if (strEQ(name, "S_IXUSR"))
1952 #ifdef S_IXUSR
1953                 return S_IXUSR;
1954 #else
1955                 goto not_there;
1956 #endif
1957             errno = EAGAIN;             /* the following aren't constants */
1958 #ifdef S_ISBLK
1959             if (strEQ(name, "S_ISBLK")) return S_ISBLK(arg);
1960 #endif
1961 #ifdef S_ISCHR
1962             if (strEQ(name, "S_ISCHR")) return S_ISCHR(arg);
1963 #endif
1964 #ifdef S_ISDIR
1965             if (strEQ(name, "S_ISDIR")) return S_ISDIR(arg);
1966 #endif
1967 #ifdef S_ISFIFO
1968             if (strEQ(name, "S_ISFIFO")) return S_ISFIFO(arg);
1969 #endif
1970 #ifdef S_ISREG
1971             if (strEQ(name, "S_ISREG")) return S_ISREG(arg);
1972 #endif
1973             break;
1974         }
1975         if (strEQ(name, "SEEK_CUR"))
1976 #ifdef SEEK_CUR
1977             return SEEK_CUR;
1978 #else
1979             goto not_there;
1980 #endif
1981         if (strEQ(name, "SEEK_END"))
1982 #ifdef SEEK_END
1983             return SEEK_END;
1984 #else
1985             goto not_there;
1986 #endif
1987         if (strEQ(name, "SEEK_SET"))
1988 #ifdef SEEK_SET
1989             return SEEK_SET;
1990 #else
1991             goto not_there;
1992 #endif
1993         if (strEQ(name, "STREAM_MAX"))
1994 #ifdef STREAM_MAX
1995             return STREAM_MAX;
1996 #else
1997             goto not_there;
1998 #endif
1999         if (strEQ(name, "SHRT_MAX"))
2000 #ifdef SHRT_MAX
2001             return SHRT_MAX;
2002 #else
2003             goto not_there;
2004 #endif
2005         if (strEQ(name, "SHRT_MIN"))
2006 #ifdef SHRT_MIN
2007             return SHRT_MIN;
2008 #else
2009             goto not_there;
2010 #endif
2011         if (strnEQ(name, "SA_", 3)) {
2012             if (strEQ(name, "SA_NOCLDSTOP"))
2013 #ifdef SA_NOCLDSTOP
2014                 return SA_NOCLDSTOP;
2015 #else
2016                 goto not_there;
2017 #endif
2018             if (strEQ(name, "SA_NOCLDWAIT"))
2019 #ifdef SA_NOCLDWAIT
2020                 return SA_NOCLDWAIT;
2021 #else
2022                 goto not_there;
2023 #endif
2024             if (strEQ(name, "SA_NODEFER"))
2025 #ifdef SA_NODEFER
2026                 return SA_NODEFER;
2027 #else
2028                 goto not_there;
2029 #endif
2030             if (strEQ(name, "SA_ONSTACK"))
2031 #ifdef SA_ONSTACK
2032                 return SA_ONSTACK;
2033 #else
2034                 goto not_there;
2035 #endif
2036             if (strEQ(name, "SA_RESETHAND"))
2037 #ifdef SA_RESETHAND
2038                 return SA_RESETHAND;
2039 #else
2040                 goto not_there;
2041 #endif
2042             if (strEQ(name, "SA_RESTART"))
2043 #ifdef SA_RESTART
2044                 return SA_RESTART;
2045 #else
2046                 goto not_there;
2047 #endif
2048             if (strEQ(name, "SA_SIGINFO"))
2049 #ifdef SA_SIGINFO
2050                 return SA_SIGINFO;
2051 #else
2052                 goto not_there;
2053 #endif
2054             break;
2055         }
2056         if (strEQ(name, "SCHAR_MAX"))
2057 #ifdef SCHAR_MAX
2058             return SCHAR_MAX;
2059 #else
2060             goto not_there;
2061 #endif
2062         if (strEQ(name, "SCHAR_MIN"))
2063 #ifdef SCHAR_MIN
2064             return SCHAR_MIN;
2065 #else
2066             goto not_there;
2067 #endif
2068         if (strEQ(name, "SSIZE_MAX"))
2069 #ifdef SSIZE_MAX
2070             return SSIZE_MAX;
2071 #else
2072             goto not_there;
2073 #endif
2074         if (strEQ(name, "STDIN_FILENO"))
2075 #ifdef STDIN_FILENO
2076             return STDIN_FILENO;
2077 #else
2078             goto not_there;
2079 #endif
2080         if (strEQ(name, "STDOUT_FILENO"))
2081 #ifdef STDOUT_FILENO
2082             return STDOUT_FILENO;
2083 #else
2084             goto not_there;
2085 #endif
2086         if (strEQ(name, "STRERR_FILENO"))
2087 #ifdef STRERR_FILENO
2088             return STRERR_FILENO;
2089 #else
2090             goto not_there;
2091 #endif
2092         break;
2093     case 'T':
2094         if (strEQ(name, "TCIFLUSH"))
2095 #ifdef TCIFLUSH
2096             return TCIFLUSH;
2097 #else
2098             goto not_there;
2099 #endif
2100         if (strEQ(name, "TCIOFF"))
2101 #ifdef TCIOFF
2102             return TCIOFF;
2103 #else
2104             goto not_there;
2105 #endif
2106         if (strEQ(name, "TCIOFLUSH"))
2107 #ifdef TCIOFLUSH
2108             return TCIOFLUSH;
2109 #else
2110             goto not_there;
2111 #endif
2112         if (strEQ(name, "TCION"))
2113 #ifdef TCION
2114             return TCION;
2115 #else
2116             goto not_there;
2117 #endif
2118         if (strEQ(name, "TCOFLUSH"))
2119 #ifdef TCOFLUSH
2120             return TCOFLUSH;
2121 #else
2122             goto not_there;
2123 #endif
2124         if (strEQ(name, "TCOOFF"))
2125 #ifdef TCOOFF
2126             return TCOOFF;
2127 #else
2128             goto not_there;
2129 #endif
2130         if (strEQ(name, "TCOON"))
2131 #ifdef TCOON
2132             return TCOON;
2133 #else
2134             goto not_there;
2135 #endif
2136         if (strEQ(name, "TCSADRAIN"))
2137 #ifdef TCSADRAIN
2138             return TCSADRAIN;
2139 #else
2140             goto not_there;
2141 #endif
2142         if (strEQ(name, "TCSAFLUSH"))
2143 #ifdef TCSAFLUSH
2144             return TCSAFLUSH;
2145 #else
2146             goto not_there;
2147 #endif
2148         if (strEQ(name, "TCSANOW"))
2149 #ifdef TCSANOW
2150             return TCSANOW;
2151 #else
2152             goto not_there;
2153 #endif
2154         if (strEQ(name, "TMP_MAX"))
2155 #ifdef TMP_MAX
2156             return TMP_MAX;
2157 #else
2158             goto not_there;
2159 #endif
2160         if (strEQ(name, "TOSTOP"))
2161 #ifdef TOSTOP
2162             return TOSTOP;
2163 #else
2164             goto not_there;
2165 #endif
2166         if (strEQ(name, "TZNAME_MAX"))
2167 #ifdef TZNAME_MAX
2168             return TZNAME_MAX;
2169 #else
2170             goto not_there;
2171 #endif
2172         break;
2173     case 'U':
2174         if (strEQ(name, "UCHAR_MAX"))
2175 #ifdef UCHAR_MAX
2176             return UCHAR_MAX;
2177 #else
2178             goto not_there;
2179 #endif
2180         if (strEQ(name, "UINT_MAX"))
2181 #ifdef UINT_MAX
2182             return UINT_MAX;
2183 #else
2184             goto not_there;
2185 #endif
2186         if (strEQ(name, "ULONG_MAX"))
2187 #ifdef ULONG_MAX
2188             return ULONG_MAX;
2189 #else
2190             goto not_there;
2191 #endif
2192         if (strEQ(name, "USHRT_MAX"))
2193 #ifdef USHRT_MAX
2194             return USHRT_MAX;
2195 #else
2196             goto not_there;
2197 #endif
2198         break;
2199     case 'V':
2200         if (strEQ(name, "VEOF"))
2201 #ifdef VEOF
2202             return VEOF;
2203 #else
2204             goto not_there;
2205 #endif
2206         if (strEQ(name, "VEOL"))
2207 #ifdef VEOL
2208             return VEOL;
2209 #else
2210             goto not_there;
2211 #endif
2212         if (strEQ(name, "VERASE"))
2213 #ifdef VERASE
2214             return VERASE;
2215 #else
2216             goto not_there;
2217 #endif
2218         if (strEQ(name, "VINTR"))
2219 #ifdef VINTR
2220             return VINTR;
2221 #else
2222             goto not_there;
2223 #endif
2224         if (strEQ(name, "VKILL"))
2225 #ifdef VKILL
2226             return VKILL;
2227 #else
2228             goto not_there;
2229 #endif
2230         if (strEQ(name, "VMIN"))
2231 #ifdef VMIN
2232             return VMIN;
2233 #else
2234             goto not_there;
2235 #endif
2236         if (strEQ(name, "VQUIT"))
2237 #ifdef VQUIT
2238             return VQUIT;
2239 #else
2240             goto not_there;
2241 #endif
2242         if (strEQ(name, "VSTART"))
2243 #ifdef VSTART
2244             return VSTART;
2245 #else
2246             goto not_there;
2247 #endif
2248         if (strEQ(name, "VSTOP"))
2249 #ifdef VSTOP
2250             return VSTOP;
2251 #else
2252             goto not_there;
2253 #endif
2254         if (strEQ(name, "VSUSP"))
2255 #ifdef VSUSP
2256             return VSUSP;
2257 #else
2258             goto not_there;
2259 #endif
2260         if (strEQ(name, "VTIME"))
2261 #ifdef VTIME
2262             return VTIME;
2263 #else
2264             goto not_there;
2265 #endif
2266         break;
2267     case 'W':
2268         if (strEQ(name, "W_OK"))
2269 #ifdef W_OK
2270             return W_OK;
2271 #else
2272             goto not_there;
2273 #endif
2274         if (strEQ(name, "WNOHANG"))
2275 #ifdef WNOHANG
2276             return WNOHANG;
2277 #else
2278             goto not_there;
2279 #endif
2280         if (strEQ(name, "WUNTRACED"))
2281 #ifdef WUNTRACED
2282             return WUNTRACED;
2283 #else
2284             goto not_there;
2285 #endif
2286         errno = EAGAIN;         /* the following aren't constants */
2287 #ifdef WEXITSTATUS
2288         if (strEQ(name, "WEXITSTATUS")) return WEXITSTATUS(arg);
2289 #endif
2290 #ifdef WIFEXITED
2291         if (strEQ(name, "WIFEXITED")) return WIFEXITED(arg);
2292 #endif
2293 #ifdef WIFSIGNALED
2294         if (strEQ(name, "WIFSIGNALED")) return WIFSIGNALED(arg);
2295 #endif
2296 #ifdef WIFSTOPPED
2297         if (strEQ(name, "WIFSTOPPED")) return WIFSTOPPED(arg);
2298 #endif
2299 #ifdef WSTOPSIG
2300         if (strEQ(name, "WSTOPSIG")) return WSTOPSIG(arg);
2301 #endif
2302 #ifdef WTERMSIG
2303         if (strEQ(name, "WTERMSIG")) return WTERMSIG(arg);
2304 #endif
2305         break;
2306     case 'X':
2307         if (strEQ(name, "X_OK"))
2308 #ifdef X_OK
2309             return X_OK;
2310 #else
2311             goto not_there;
2312 #endif
2313         break;
2314     case '_':
2315         if (strnEQ(name, "_PC_", 4)) {
2316             if (strEQ(name, "_PC_CHOWN_RESTRICTED"))
2317 #if defined(_PC_CHOWN_RESTRICTED) || HINT_SC_EXIST
2318                 return _PC_CHOWN_RESTRICTED;
2319 #else
2320                 goto not_there;
2321 #endif
2322             if (strEQ(name, "_PC_LINK_MAX"))
2323 #if defined(_PC_LINK_MAX) || HINT_SC_EXIST
2324                 return _PC_LINK_MAX;
2325 #else
2326                 goto not_there;
2327 #endif
2328             if (strEQ(name, "_PC_MAX_CANON"))
2329 #if defined(_PC_MAX_CANON) || HINT_SC_EXIST
2330                 return _PC_MAX_CANON;
2331 #else
2332                 goto not_there;
2333 #endif
2334             if (strEQ(name, "_PC_MAX_INPUT"))
2335 #if defined(_PC_MAX_INPUT) || HINT_SC_EXIST
2336                 return _PC_MAX_INPUT;
2337 #else
2338                 goto not_there;
2339 #endif
2340             if (strEQ(name, "_PC_NAME_MAX"))
2341 #if defined(_PC_NAME_MAX) || HINT_SC_EXIST
2342                 return _PC_NAME_MAX;
2343 #else
2344                 goto not_there;
2345 #endif
2346             if (strEQ(name, "_PC_NO_TRUNC"))
2347 #if defined(_PC_NO_TRUNC) || HINT_SC_EXIST
2348                 return _PC_NO_TRUNC;
2349 #else
2350                 goto not_there;
2351 #endif
2352             if (strEQ(name, "_PC_PATH_MAX"))
2353 #if defined(_PC_PATH_MAX) || HINT_SC_EXIST
2354                 return _PC_PATH_MAX;
2355 #else
2356                 goto not_there;
2357 #endif
2358             if (strEQ(name, "_PC_PIPE_BUF"))
2359 #if defined(_PC_PIPE_BUF) || HINT_SC_EXIST
2360                 return _PC_PIPE_BUF;
2361 #else
2362                 goto not_there;
2363 #endif
2364             if (strEQ(name, "_PC_VDISABLE"))
2365 #if defined(_PC_VDISABLE) || HINT_SC_EXIST
2366                 return _PC_VDISABLE;
2367 #else
2368                 goto not_there;
2369 #endif
2370             break;
2371         }
2372         if (strnEQ(name, "_POSIX_", 7)) {
2373             if (strEQ(name, "_POSIX_ARG_MAX"))
2374 #ifdef _POSIX_ARG_MAX
2375                 return _POSIX_ARG_MAX;
2376 #else
2377                 return 0;
2378 #endif
2379             if (strEQ(name, "_POSIX_CHILD_MAX"))
2380 #ifdef _POSIX_CHILD_MAX
2381                 return _POSIX_CHILD_MAX;
2382 #else
2383                 return 0;
2384 #endif
2385             if (strEQ(name, "_POSIX_CHOWN_RESTRICTED"))
2386 #ifdef _POSIX_CHOWN_RESTRICTED
2387                 return _POSIX_CHOWN_RESTRICTED;
2388 #else
2389                 return 0;
2390 #endif
2391             if (strEQ(name, "_POSIX_JOB_CONTROL"))
2392 #ifdef _POSIX_JOB_CONTROL
2393                 return _POSIX_JOB_CONTROL;
2394 #else
2395                 return 0;
2396 #endif
2397             if (strEQ(name, "_POSIX_LINK_MAX"))
2398 #ifdef _POSIX_LINK_MAX
2399                 return _POSIX_LINK_MAX;
2400 #else
2401                 return 0;
2402 #endif
2403             if (strEQ(name, "_POSIX_MAX_CANON"))
2404 #ifdef _POSIX_MAX_CANON
2405                 return _POSIX_MAX_CANON;
2406 #else
2407                 return 0;
2408 #endif
2409             if (strEQ(name, "_POSIX_MAX_INPUT"))
2410 #ifdef _POSIX_MAX_INPUT
2411                 return _POSIX_MAX_INPUT;
2412 #else
2413                 return 0;
2414 #endif
2415             if (strEQ(name, "_POSIX_NAME_MAX"))
2416 #ifdef _POSIX_NAME_MAX
2417                 return _POSIX_NAME_MAX;
2418 #else
2419                 return 0;
2420 #endif
2421             if (strEQ(name, "_POSIX_NGROUPS_MAX"))
2422 #ifdef _POSIX_NGROUPS_MAX
2423                 return _POSIX_NGROUPS_MAX;
2424 #else
2425                 return 0;
2426 #endif
2427             if (strEQ(name, "_POSIX_NO_TRUNC"))
2428 #ifdef _POSIX_NO_TRUNC
2429                 return _POSIX_NO_TRUNC;
2430 #else
2431                 return 0;
2432 #endif
2433             if (strEQ(name, "_POSIX_OPEN_MAX"))
2434 #ifdef _POSIX_OPEN_MAX
2435                 return _POSIX_OPEN_MAX;
2436 #else
2437                 return 0;
2438 #endif
2439             if (strEQ(name, "_POSIX_PATH_MAX"))
2440 #ifdef _POSIX_PATH_MAX
2441                 return _POSIX_PATH_MAX;
2442 #else
2443                 return 0;
2444 #endif
2445             if (strEQ(name, "_POSIX_PIPE_BUF"))
2446 #ifdef _POSIX_PIPE_BUF
2447                 return _POSIX_PIPE_BUF;
2448 #else
2449                 return 0;
2450 #endif
2451             if (strEQ(name, "_POSIX_SAVED_IDS"))
2452 #ifdef _POSIX_SAVED_IDS
2453                 return _POSIX_SAVED_IDS;
2454 #else
2455                 return 0;
2456 #endif
2457             if (strEQ(name, "_POSIX_SSIZE_MAX"))
2458 #ifdef _POSIX_SSIZE_MAX
2459                 return _POSIX_SSIZE_MAX;
2460 #else
2461                 return 0;
2462 #endif
2463             if (strEQ(name, "_POSIX_STREAM_MAX"))
2464 #ifdef _POSIX_STREAM_MAX
2465                 return _POSIX_STREAM_MAX;
2466 #else
2467                 return 0;
2468 #endif
2469             if (strEQ(name, "_POSIX_TZNAME_MAX"))
2470 #ifdef _POSIX_TZNAME_MAX
2471                 return _POSIX_TZNAME_MAX;
2472 #else
2473                 return 0;
2474 #endif
2475             if (strEQ(name, "_POSIX_VDISABLE"))
2476 #ifdef _POSIX_VDISABLE
2477                 return _POSIX_VDISABLE;
2478 #else
2479                 return 0;
2480 #endif
2481             if (strEQ(name, "_POSIX_VERSION"))
2482 #ifdef _POSIX_VERSION
2483                 return _POSIX_VERSION;
2484 #else
2485                 return 0;
2486 #endif
2487             break;
2488         }
2489         if (strnEQ(name, "_SC_", 4)) {
2490             if (strEQ(name, "_SC_ARG_MAX"))
2491 #if defined(_SC_ARG_MAX) || HINT_SC_EXIST
2492                 return _SC_ARG_MAX;
2493 #else
2494                 goto not_there;
2495 #endif
2496             if (strEQ(name, "_SC_CHILD_MAX"))
2497 #if defined(_SC_CHILD_MAX) || HINT_SC_EXIST
2498                 return _SC_CHILD_MAX;
2499 #else
2500                 goto not_there;
2501 #endif
2502             if (strEQ(name, "_SC_CLK_TCK"))
2503 #if defined(_SC_CLK_TCK) || HINT_SC_EXIST
2504                 return _SC_CLK_TCK;
2505 #else
2506                 goto not_there;
2507 #endif
2508             if (strEQ(name, "_SC_JOB_CONTROL"))
2509 #if defined(_SC_JOB_CONTROL) || HINT_SC_EXIST
2510                 return _SC_JOB_CONTROL;
2511 #else
2512                 goto not_there;
2513 #endif
2514             if (strEQ(name, "_SC_NGROUPS_MAX"))
2515 #if defined(_SC_NGROUPS_MAX) || HINT_SC_EXIST
2516                 return _SC_NGROUPS_MAX;
2517 #else
2518                 goto not_there;
2519 #endif
2520             if (strEQ(name, "_SC_OPEN_MAX"))
2521 #if defined(_SC_OPEN_MAX) || HINT_SC_EXIST
2522                 return _SC_OPEN_MAX;
2523 #else
2524                 goto not_there;
2525 #endif
2526             if (strEQ(name, "_SC_SAVED_IDS"))
2527 #if defined(_SC_SAVED_IDS) || HINT_SC_EXIST
2528                 return _SC_SAVED_IDS;
2529 #else
2530                 goto not_there;
2531 #endif
2532             if (strEQ(name, "_SC_STREAM_MAX"))
2533 #if defined(_SC_STREAM_MAX) || HINT_SC_EXIST
2534                 return _SC_STREAM_MAX;
2535 #else
2536                 goto not_there;
2537 #endif
2538             if (strEQ(name, "_SC_TZNAME_MAX"))
2539 #if defined(_SC_TZNAME_MAX) || HINT_SC_EXIST
2540                 return _SC_TZNAME_MAX;
2541 #else
2542                 goto not_there;
2543 #endif
2544             if (strEQ(name, "_SC_VERSION"))
2545 #if defined(_SC_VERSION) || HINT_SC_EXIST
2546                 return _SC_VERSION;
2547 #else
2548                 goto not_there;
2549 #endif
2550             break;
2551         }
2552     }
2553     errno = EINVAL;
2554     return 0;
2555
2556 not_there:
2557     errno = ENOENT;
2558     return 0;
2559 }
2560
2561 MODULE = SigSet         PACKAGE = POSIX::SigSet         PREFIX = sig
2562
2563 POSIX::SigSet
2564 new(packname = "POSIX::SigSet", ...)
2565     char *              packname
2566     CODE:
2567         {
2568             int i;
2569             RETVAL = (sigset_t*)safemalloc(sizeof(sigset_t));
2570             sigemptyset(RETVAL);
2571             for (i = 1; i < items; i++)
2572                 sigaddset(RETVAL, SvIV(ST(i)));
2573         }
2574     OUTPUT:
2575         RETVAL
2576
2577 void
2578 DESTROY(sigset)
2579         POSIX::SigSet   sigset
2580     CODE:
2581         safefree((char *)sigset);
2582
2583 SysRet
2584 sigaddset(sigset, sig)
2585         POSIX::SigSet   sigset
2586         int             sig
2587
2588 SysRet
2589 sigdelset(sigset, sig)
2590         POSIX::SigSet   sigset
2591         int             sig
2592
2593 SysRet
2594 sigemptyset(sigset)
2595         POSIX::SigSet   sigset
2596
2597 SysRet
2598 sigfillset(sigset)
2599         POSIX::SigSet   sigset
2600
2601 int
2602 sigismember(sigset, sig)
2603         POSIX::SigSet   sigset
2604         int             sig
2605
2606
2607 MODULE = Termios        PACKAGE = POSIX::Termios        PREFIX = cf
2608
2609 POSIX::Termios
2610 new(packname = "POSIX::Termios", ...)
2611     char *              packname
2612     CODE:
2613         {
2614 #ifdef I_TERMIOS
2615             RETVAL = (struct termios*)safemalloc(sizeof(struct termios));
2616 #else
2617             not_here("termios");
2618         RETVAL = 0;
2619 #endif
2620         }
2621     OUTPUT:
2622         RETVAL
2623
2624 void
2625 DESTROY(termios_ref)
2626         POSIX::Termios  termios_ref
2627     CODE:
2628 #ifdef I_TERMIOS
2629         safefree((char *)termios_ref);
2630 #else
2631             not_here("termios");
2632 #endif
2633
2634 SysRet
2635 getattr(termios_ref, fd = 0)
2636         POSIX::Termios  termios_ref
2637         int             fd
2638     CODE:
2639         RETVAL = tcgetattr(fd, termios_ref);
2640     OUTPUT:
2641         RETVAL
2642
2643 SysRet
2644 setattr(termios_ref, fd = 0, optional_actions = 0)
2645         POSIX::Termios  termios_ref
2646         int             fd
2647         int             optional_actions
2648     CODE:
2649         RETVAL = tcsetattr(fd, optional_actions, termios_ref);
2650     OUTPUT:
2651         RETVAL
2652
2653 speed_t
2654 cfgetispeed(termios_ref)
2655         POSIX::Termios  termios_ref
2656
2657 speed_t
2658 cfgetospeed(termios_ref)
2659         POSIX::Termios  termios_ref
2660
2661 tcflag_t
2662 getiflag(termios_ref)
2663         POSIX::Termios  termios_ref
2664     CODE:
2665 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2666         RETVAL = termios_ref->c_iflag;
2667 #else
2668      not_here("getiflag");
2669      RETVAL = 0;
2670 #endif
2671     OUTPUT:
2672         RETVAL
2673
2674 tcflag_t
2675 getoflag(termios_ref)
2676         POSIX::Termios  termios_ref
2677     CODE:
2678 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2679         RETVAL = termios_ref->c_oflag;
2680 #else
2681      not_here("getoflag");
2682      RETVAL = 0;
2683 #endif
2684     OUTPUT:
2685         RETVAL
2686
2687 tcflag_t
2688 getcflag(termios_ref)
2689         POSIX::Termios  termios_ref
2690     CODE:
2691 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2692         RETVAL = termios_ref->c_cflag;
2693 #else
2694      not_here("getcflag");
2695      RETVAL = 0;
2696 #endif
2697     OUTPUT:
2698         RETVAL
2699
2700 tcflag_t
2701 getlflag(termios_ref)
2702         POSIX::Termios  termios_ref
2703     CODE:
2704 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2705         RETVAL = termios_ref->c_lflag;
2706 #else
2707      not_here("getlflag");
2708      RETVAL = 0;
2709 #endif
2710     OUTPUT:
2711         RETVAL
2712
2713 cc_t
2714 getcc(termios_ref, ccix)
2715         POSIX::Termios  termios_ref
2716         int             ccix
2717     CODE:
2718 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2719         if (ccix >= NCCS)
2720             croak("Bad getcc subscript");
2721         RETVAL = termios_ref->c_cc[ccix];
2722 #else
2723      not_here("getcc");
2724      RETVAL = 0;
2725 #endif
2726     OUTPUT:
2727         RETVAL
2728
2729 SysRet
2730 cfsetispeed(termios_ref, speed)
2731         POSIX::Termios  termios_ref
2732         speed_t         speed
2733
2734 SysRet
2735 cfsetospeed(termios_ref, speed)
2736         POSIX::Termios  termios_ref
2737         speed_t         speed
2738
2739 void
2740 setiflag(termios_ref, iflag)
2741         POSIX::Termios  termios_ref
2742         tcflag_t        iflag
2743     CODE:
2744 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2745         termios_ref->c_iflag = iflag;
2746 #else
2747             not_here("setiflag");
2748 #endif
2749
2750 void
2751 setoflag(termios_ref, oflag)
2752         POSIX::Termios  termios_ref
2753         tcflag_t        oflag
2754     CODE:
2755 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2756         termios_ref->c_oflag = oflag;
2757 #else
2758             not_here("setoflag");
2759 #endif
2760
2761 void
2762 setcflag(termios_ref, cflag)
2763         POSIX::Termios  termios_ref
2764         tcflag_t        cflag
2765     CODE:
2766 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2767         termios_ref->c_cflag = cflag;
2768 #else
2769             not_here("setcflag");
2770 #endif
2771
2772 void
2773 setlflag(termios_ref, lflag)
2774         POSIX::Termios  termios_ref
2775         tcflag_t        lflag
2776     CODE:
2777 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2778         termios_ref->c_lflag = lflag;
2779 #else
2780             not_here("setlflag");
2781 #endif
2782
2783 void
2784 setcc(termios_ref, ccix, cc)
2785         POSIX::Termios  termios_ref
2786         int             ccix
2787         cc_t            cc
2788     CODE:
2789 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
2790         if (ccix >= NCCS)
2791             croak("Bad setcc subscript");
2792         termios_ref->c_cc[ccix] = cc;
2793 #else
2794             not_here("setcc");
2795 #endif
2796
2797
2798 MODULE = POSIX          PACKAGE = POSIX
2799
2800 double
2801 constant(name,arg)
2802         char *          name
2803         int             arg
2804
2805 int
2806 isalnum(charstring)
2807         unsigned char * charstring
2808     CODE:
2809         unsigned char *s = charstring;
2810         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2811         for (RETVAL = 1; RETVAL && s < e; s++)
2812             if (!isalnum(*s))
2813                 RETVAL = 0;
2814     OUTPUT:
2815         RETVAL
2816
2817 int
2818 isalpha(charstring)
2819         unsigned char * charstring
2820     CODE:
2821         unsigned char *s = charstring;
2822         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2823         for (RETVAL = 1; RETVAL && s < e; s++)
2824             if (!isalpha(*s))
2825                 RETVAL = 0;
2826     OUTPUT:
2827         RETVAL
2828
2829 int
2830 iscntrl(charstring)
2831         unsigned char * charstring
2832     CODE:
2833         unsigned char *s = charstring;
2834         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2835         for (RETVAL = 1; RETVAL && s < e; s++)
2836             if (!iscntrl(*s))
2837                 RETVAL = 0;
2838     OUTPUT:
2839         RETVAL
2840
2841 int
2842 isdigit(charstring)
2843         unsigned char * charstring
2844     CODE:
2845         unsigned char *s = charstring;
2846         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2847         for (RETVAL = 1; RETVAL && s < e; s++)
2848             if (!isdigit(*s))
2849                 RETVAL = 0;
2850     OUTPUT:
2851         RETVAL
2852
2853 int
2854 isgraph(charstring)
2855         unsigned char * charstring
2856     CODE:
2857         unsigned char *s = charstring;
2858         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2859         for (RETVAL = 1; RETVAL && s < e; s++)
2860             if (!isgraph(*s))
2861                 RETVAL = 0;
2862     OUTPUT:
2863         RETVAL
2864
2865 int
2866 islower(charstring)
2867         unsigned char * charstring
2868     CODE:
2869         unsigned char *s = charstring;
2870         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2871         for (RETVAL = 1; RETVAL && s < e; s++)
2872             if (!islower(*s))
2873                 RETVAL = 0;
2874     OUTPUT:
2875         RETVAL
2876
2877 int
2878 isprint(charstring)
2879         unsigned char * charstring
2880     CODE:
2881         unsigned char *s = charstring;
2882         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2883         for (RETVAL = 1; RETVAL && s < e; s++)
2884             if (!isprint(*s))
2885                 RETVAL = 0;
2886     OUTPUT:
2887         RETVAL
2888
2889 int
2890 ispunct(charstring)
2891         unsigned char * charstring
2892     CODE:
2893         unsigned char *s = charstring;
2894         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2895         for (RETVAL = 1; RETVAL && s < e; s++)
2896             if (!ispunct(*s))
2897                 RETVAL = 0;
2898     OUTPUT:
2899         RETVAL
2900
2901 int
2902 isspace(charstring)
2903         unsigned char * charstring
2904     CODE:
2905         unsigned char *s = charstring;
2906         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2907         for (RETVAL = 1; RETVAL && s < e; s++)
2908             if (!isspace(*s))
2909                 RETVAL = 0;
2910     OUTPUT:
2911         RETVAL
2912
2913 int
2914 isupper(charstring)
2915         unsigned char * charstring
2916     CODE:
2917         unsigned char *s = charstring;
2918         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2919         for (RETVAL = 1; RETVAL && s < e; s++)
2920             if (!isupper(*s))
2921                 RETVAL = 0;
2922     OUTPUT:
2923         RETVAL
2924
2925 int
2926 isxdigit(charstring)
2927         unsigned char * charstring
2928     CODE:
2929         unsigned char *s = charstring;
2930         unsigned char *e = s + PL_na;   /* "PL_na" set by typemap side effect */
2931         for (RETVAL = 1; RETVAL && s < e; s++)
2932             if (!isxdigit(*s))
2933                 RETVAL = 0;
2934     OUTPUT:
2935         RETVAL
2936
2937 SysRet
2938 open(filename, flags = O_RDONLY, mode = 0666)
2939         char *          filename
2940         int             flags
2941         Mode_t          mode
2942     CODE:
2943         if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
2944             TAINT_PROPER("open");
2945         RETVAL = open(filename, flags, mode);
2946     OUTPUT:
2947         RETVAL
2948
2949
2950 HV *
2951 localeconv()
2952     CODE:
2953 #ifdef HAS_LOCALECONV
2954         struct lconv *lcbuf;
2955         RETVAL = newHV();
2956         SET_NUMERIC_LOCAL();
2957         if (lcbuf = localeconv()) {
2958             /* the strings */
2959             if (lcbuf->decimal_point && *lcbuf->decimal_point)
2960                 hv_store(RETVAL, "decimal_point", 13,
2961                     newSVpv(lcbuf->decimal_point, 0), 0);
2962             if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
2963                 hv_store(RETVAL, "thousands_sep", 13,
2964                     newSVpv(lcbuf->thousands_sep, 0), 0);
2965 #ifndef NO_LOCALECONV_GROUPING
2966             if (lcbuf->grouping && *lcbuf->grouping)
2967                 hv_store(RETVAL, "grouping", 8,
2968                     newSVpv(lcbuf->grouping, 0), 0);
2969 #endif
2970             if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
2971                 hv_store(RETVAL, "int_curr_symbol", 15,
2972                     newSVpv(lcbuf->int_curr_symbol, 0), 0);
2973             if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
2974                 hv_store(RETVAL, "currency_symbol", 15,
2975                     newSVpv(lcbuf->currency_symbol, 0), 0);
2976             if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
2977                 hv_store(RETVAL, "mon_decimal_point", 17,
2978                     newSVpv(lcbuf->mon_decimal_point, 0), 0);
2979 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
2980             if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
2981                 hv_store(RETVAL, "mon_thousands_sep", 17,
2982                     newSVpv(lcbuf->mon_thousands_sep, 0), 0);
2983 #endif                    
2984 #ifndef NO_LOCALECONV_MON_GROUPING
2985             if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
2986                 hv_store(RETVAL, "mon_grouping", 12,
2987                     newSVpv(lcbuf->mon_grouping, 0), 0);
2988 #endif
2989             if (lcbuf->positive_sign && *lcbuf->positive_sign)
2990                 hv_store(RETVAL, "positive_sign", 13,
2991                     newSVpv(lcbuf->positive_sign, 0), 0);
2992             if (lcbuf->negative_sign && *lcbuf->negative_sign)
2993                 hv_store(RETVAL, "negative_sign", 13,
2994                     newSVpv(lcbuf->negative_sign, 0), 0);
2995             /* the integers */
2996             if (lcbuf->int_frac_digits != CHAR_MAX)
2997                 hv_store(RETVAL, "int_frac_digits", 15,
2998                     newSViv(lcbuf->int_frac_digits), 0);
2999             if (lcbuf->frac_digits != CHAR_MAX)
3000                 hv_store(RETVAL, "frac_digits", 11,
3001                     newSViv(lcbuf->frac_digits), 0);
3002             if (lcbuf->p_cs_precedes != CHAR_MAX)
3003                 hv_store(RETVAL, "p_cs_precedes", 13,
3004                     newSViv(lcbuf->p_cs_precedes), 0);
3005             if (lcbuf->p_sep_by_space != CHAR_MAX)
3006                 hv_store(RETVAL, "p_sep_by_space", 14,
3007                     newSViv(lcbuf->p_sep_by_space), 0);
3008             if (lcbuf->n_cs_precedes != CHAR_MAX)
3009                 hv_store(RETVAL, "n_cs_precedes", 13,
3010                     newSViv(lcbuf->n_cs_precedes), 0);
3011             if (lcbuf->n_sep_by_space != CHAR_MAX)
3012                 hv_store(RETVAL, "n_sep_by_space", 14,
3013                     newSViv(lcbuf->n_sep_by_space), 0);
3014             if (lcbuf->p_sign_posn != CHAR_MAX)
3015                 hv_store(RETVAL, "p_sign_posn", 11,
3016                     newSViv(lcbuf->p_sign_posn), 0);
3017             if (lcbuf->n_sign_posn != CHAR_MAX)
3018                 hv_store(RETVAL, "n_sign_posn", 11,
3019                     newSViv(lcbuf->n_sign_posn), 0);
3020         }
3021 #else
3022         localeconv(); /* A stub to call not_here(). */
3023 #endif
3024     OUTPUT:
3025         RETVAL
3026
3027 char *
3028 setlocale(category, locale = 0)
3029         int             category
3030         char *          locale
3031     CODE:
3032         RETVAL = setlocale(category, locale);
3033         if (RETVAL) {
3034 #ifdef USE_LOCALE_CTYPE
3035             if (category == LC_CTYPE
3036 #ifdef LC_ALL
3037                 || category == LC_ALL
3038 #endif
3039                 )
3040             {
3041                 char *newctype;
3042 #ifdef LC_ALL
3043                 if (category == LC_ALL)
3044                     newctype = setlocale(LC_CTYPE, NULL);
3045                 else
3046 #endif
3047                     newctype = RETVAL;
3048                 perl_new_ctype(newctype);
3049             }
3050 #endif /* USE_LOCALE_CTYPE */
3051 #ifdef USE_LOCALE_COLLATE
3052             if (category == LC_COLLATE
3053 #ifdef LC_ALL
3054                 || category == LC_ALL
3055 #endif
3056                 )
3057             {
3058                 char *newcoll;
3059 #ifdef LC_ALL
3060                 if (category == LC_ALL)
3061                     newcoll = setlocale(LC_COLLATE, NULL);
3062                 else
3063 #endif
3064                     newcoll = RETVAL;
3065                 perl_new_collate(newcoll);
3066             }
3067 #endif /* USE_LOCALE_COLLATE */
3068 #ifdef USE_LOCALE_NUMERIC
3069             if (category == LC_NUMERIC
3070 #ifdef LC_ALL
3071                 || category == LC_ALL
3072 #endif
3073                 )
3074             {
3075                 char *newnum;
3076 #ifdef LC_ALL
3077                 if (category == LC_ALL)
3078                     newnum = setlocale(LC_NUMERIC, NULL);
3079                 else
3080 #endif
3081                     newnum = RETVAL;
3082                 perl_new_numeric(newnum);
3083             }
3084 #endif /* USE_LOCALE_NUMERIC */
3085         }
3086     OUTPUT:
3087         RETVAL
3088
3089
3090 double
3091 acos(x)
3092         double          x
3093
3094 double
3095 asin(x)
3096         double          x
3097
3098 double
3099 atan(x)
3100         double          x
3101
3102 double
3103 ceil(x)
3104         double          x
3105
3106 double
3107 cosh(x)
3108         double          x
3109
3110 double
3111 floor(x)
3112         double          x
3113
3114 double
3115 fmod(x,y)
3116         double          x
3117         double          y
3118
3119 void
3120 frexp(x)
3121         double          x
3122     PPCODE:
3123         int expvar;
3124         /* (We already know stack is long enough.) */
3125         PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
3126         PUSHs(sv_2mortal(newSViv(expvar)));
3127
3128 double
3129 ldexp(x,exp)
3130         double          x
3131         int             exp
3132
3133 double
3134 log10(x)
3135         double          x
3136
3137 void
3138 modf(x)
3139         double          x
3140     PPCODE:
3141         double intvar;
3142         /* (We already know stack is long enough.) */
3143         PUSHs(sv_2mortal(newSVnv(modf(x,&intvar))));
3144         PUSHs(sv_2mortal(newSVnv(intvar)));
3145
3146 double
3147 sinh(x)
3148         double          x
3149
3150 double
3151 tan(x)
3152         double          x
3153
3154 double
3155 tanh(x)
3156         double          x
3157
3158 SysRet
3159 sigaction(sig, action, oldaction = 0)
3160         int                     sig
3161         POSIX::SigAction        action
3162         POSIX::SigAction        oldaction
3163     CODE:
3164 #ifdef WIN32
3165         RETVAL = not_here("sigaction");
3166 #else
3167 # This code is really grody because we're trying to make the signal
3168 # interface look beautiful, which is hard.
3169
3170         if (!PL_siggv)
3171             gv_fetchpv("SIG", TRUE, SVt_PVHV);
3172
3173         {
3174             struct sigaction act;
3175             struct sigaction oact;
3176             POSIX__SigSet sigset;
3177             SV** svp;
3178             SV** sigsvp = hv_fetch(GvHVn(PL_siggv),
3179                                  sig_name[sig],
3180                                  strlen(sig_name[sig]),
3181                                  TRUE);
3182
3183             /* Remember old handler name if desired. */
3184             if (oldaction) {
3185                 char *hand = SvPVx(*sigsvp, PL_na);
3186                 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
3187                 sv_setpv(*svp, *hand ? hand : "DEFAULT");
3188             }
3189
3190             if (action) {
3191                 /* Vector new handler through %SIG.  (We always use sighandler
3192                    for the C signal handler, which reads %SIG to dispatch.) */
3193                 svp = hv_fetch(action, "HANDLER", 7, FALSE);
3194                 if (!svp)
3195                     croak("Can't supply an action without a HANDLER");
3196                 sv_setpv(*sigsvp, SvPV(*svp, PL_na));
3197                 mg_set(*sigsvp);        /* handles DEFAULT and IGNORE */
3198                 act.sa_handler = sighandler;
3199
3200                 /* Set up any desired mask. */
3201                 svp = hv_fetch(action, "MASK", 4, FALSE);
3202                 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
3203                     unsigned long tmp;
3204                     tmp = (unsigned long)SvNV((SV*)SvRV(*svp));
3205                     sigset = (sigset_t*) tmp;
3206                     act.sa_mask = *sigset;
3207                 }
3208                 else
3209                     sigemptyset(& act.sa_mask);
3210
3211                 /* Set up any desired flags. */
3212                 svp = hv_fetch(action, "FLAGS", 5, FALSE);
3213                 act.sa_flags = svp ? SvIV(*svp) : 0;
3214             }
3215
3216             /* Now work around sigaction oddities */
3217             if (action && oldaction)
3218                 RETVAL = sigaction(sig, & act, & oact);
3219             else if (action)
3220                 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
3221             else if (oldaction)
3222                 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
3223             else
3224                 RETVAL = -1;
3225
3226             if (oldaction) {
3227                 /* Get back the mask. */
3228                 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
3229                 if (sv_isa(*svp, "POSIX::SigSet")) {
3230                     unsigned long tmp;
3231                     tmp = (unsigned long)SvNV((SV*)SvRV(*svp));
3232                     sigset = (sigset_t*) tmp;
3233                 }
3234                 else {
3235                     sigset = (sigset_t*)safemalloc(sizeof(sigset_t));
3236                     sv_setptrobj(*svp, sigset, "POSIX::SigSet");
3237                 }
3238                 *sigset = oact.sa_mask;
3239
3240                 /* Get back the flags. */
3241                 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
3242                 sv_setiv(*svp, oact.sa_flags);
3243             }
3244         }
3245 #endif
3246     OUTPUT:
3247         RETVAL
3248
3249 SysRet
3250 sigpending(sigset)
3251         POSIX::SigSet           sigset
3252
3253 SysRet
3254 sigprocmask(how, sigset, oldsigset = 0)
3255         int                     how
3256         POSIX::SigSet           sigset
3257         POSIX::SigSet           oldsigset
3258
3259 SysRet
3260 sigsuspend(signal_mask)
3261         POSIX::SigSet           signal_mask
3262
3263 void
3264 _exit(status)
3265         int             status
3266
3267 SysRet
3268 close(fd)
3269         int             fd
3270
3271 SysRet
3272 dup(fd)
3273         int             fd
3274
3275 SysRet
3276 dup2(fd1, fd2)
3277         int             fd1
3278         int             fd2
3279
3280 SysRetLong
3281 lseek(fd, offset, whence)
3282         int             fd
3283         Off_t           offset
3284         int             whence
3285
3286 SysRet
3287 nice(incr)
3288         int             incr
3289
3290 int
3291 pipe()
3292     PPCODE:
3293         int fds[2];
3294         if (pipe(fds) != -1) {
3295             EXTEND(SP,2);
3296             PUSHs(sv_2mortal(newSViv(fds[0])));
3297             PUSHs(sv_2mortal(newSViv(fds[1])));
3298         }
3299
3300 SysRet
3301 read(fd, buffer, nbytes)
3302     PREINIT:
3303         SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
3304     INPUT:
3305         int             fd
3306         size_t          nbytes
3307         char *          buffer = sv_grow( sv_buffer, nbytes+1 );
3308     CLEANUP:
3309         if (RETVAL >= 0) {
3310             SvCUR(sv_buffer) = RETVAL;
3311             SvPOK_only(sv_buffer);
3312             *SvEND(sv_buffer) = '\0';
3313             SvTAINTED_on(sv_buffer);
3314         }
3315
3316 SysRet
3317 setpgid(pid, pgid)
3318         pid_t           pid
3319         pid_t           pgid
3320
3321 pid_t
3322 setsid()
3323
3324 pid_t
3325 tcgetpgrp(fd)
3326         int             fd
3327
3328 SysRet
3329 tcsetpgrp(fd, pgrp_id)
3330         int             fd
3331         pid_t           pgrp_id
3332
3333 int
3334 uname()
3335     PPCODE:
3336 #ifdef HAS_UNAME
3337         struct utsname buf;
3338         if (uname(&buf) >= 0) {
3339             EXTEND(SP, 5);
3340             PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
3341             PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
3342             PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
3343             PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
3344             PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
3345         }
3346 #else
3347         uname((char *) 0); /* A stub to call not_here(). */
3348 #endif
3349
3350 SysRet
3351 write(fd, buffer, nbytes)
3352         int             fd
3353         char *          buffer
3354         size_t          nbytes
3355
3356 char *
3357 tmpnam(s = 0)
3358         char *          s = 0;
3359
3360 void
3361 abort()
3362
3363 int
3364 mblen(s, n)
3365         char *          s
3366         size_t          n
3367
3368 size_t
3369 mbstowcs(s, pwcs, n)
3370         wchar_t *       s
3371         char *          pwcs
3372         size_t          n
3373
3374 int
3375 mbtowc(pwc, s, n)
3376         wchar_t *       pwc
3377         char *          s
3378         size_t          n
3379
3380 int
3381 wcstombs(s, pwcs, n)
3382         char *          s
3383         wchar_t *       pwcs
3384         size_t          n
3385
3386 int
3387 wctomb(s, wchar)
3388         char *          s
3389         wchar_t         wchar
3390
3391 int
3392 strcoll(s1, s2)
3393         char *          s1
3394         char *          s2
3395
3396 void
3397 strtod(str)
3398         char *          str
3399     PREINIT:
3400         double num;
3401         char *unparsed;
3402     PPCODE:
3403         SET_NUMERIC_LOCAL();
3404         num = strtod(str, &unparsed);
3405         PUSHs(sv_2mortal(newSVnv(num)));
3406         if (GIMME == G_ARRAY) {
3407             EXTEND(SP, 1);
3408             if (unparsed)
3409                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3410             else
3411                 PUSHs(&PL_sv_undef);
3412         }
3413
3414 void
3415 strtol(str, base = 0)
3416         char *          str
3417         int             base
3418     PREINIT:
3419         long num;
3420         char *unparsed;
3421     PPCODE:
3422         num = strtol(str, &unparsed, base);
3423         if (num >= IV_MIN && num <= IV_MAX)
3424             PUSHs(sv_2mortal(newSViv((IV)num)));
3425         else
3426             PUSHs(sv_2mortal(newSVnv((double)num)));
3427         if (GIMME == G_ARRAY) {
3428             EXTEND(SP, 1);
3429             if (unparsed)
3430                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3431             else
3432                 PUSHs(&PL_sv_undef);
3433         }
3434
3435 void
3436 strtoul(str, base = 0)
3437         char *          str
3438         int             base
3439     PREINIT:
3440         unsigned long num;
3441         char *unparsed;
3442     PPCODE:
3443         num = strtoul(str, &unparsed, base);
3444         if (num <= IV_MAX)
3445             PUSHs(sv_2mortal(newSViv((IV)num)));
3446         else
3447             PUSHs(sv_2mortal(newSVnv((double)num)));
3448         if (GIMME == G_ARRAY) {
3449             EXTEND(SP, 1);
3450             if (unparsed)
3451                 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
3452             else
3453                 PUSHs(&PL_sv_undef);
3454         }
3455
3456 SV *
3457 strxfrm(src)
3458         SV *            src
3459     CODE:
3460         {
3461           STRLEN srclen;
3462           STRLEN dstlen;
3463           char *p = SvPV(src,srclen);
3464           srclen++;
3465           ST(0) = sv_2mortal(NEWSV(800,srclen));
3466           dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
3467           if (dstlen > srclen) {
3468               dstlen++;
3469               SvGROW(ST(0), dstlen);
3470               strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
3471               dstlen--;
3472           }
3473           SvCUR(ST(0)) = dstlen;
3474             SvPOK_only(ST(0));
3475         }
3476
3477 SysRet
3478 mkfifo(filename, mode)
3479         char *          filename
3480         Mode_t          mode
3481     CODE:
3482         TAINT_PROPER("mkfifo");
3483         RETVAL = mkfifo(filename, mode);
3484     OUTPUT:
3485         RETVAL
3486
3487 SysRet
3488 tcdrain(fd)
3489         int             fd
3490
3491
3492 SysRet
3493 tcflow(fd, action)
3494         int             fd
3495         int             action
3496
3497
3498 SysRet
3499 tcflush(fd, queue_selector)
3500         int             fd
3501         int             queue_selector
3502
3503 SysRet
3504 tcsendbreak(fd, duration)
3505         int             fd
3506         int             duration
3507
3508 char *
3509 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
3510         int             sec
3511         int             min
3512         int             hour
3513         int             mday
3514         int             mon
3515         int             year
3516         int             wday
3517         int             yday
3518         int             isdst
3519     CODE:
3520         {
3521             struct tm mytm;
3522             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3523             mytm.tm_sec = sec;
3524             mytm.tm_min = min;
3525             mytm.tm_hour = hour;
3526             mytm.tm_mday = mday;
3527             mytm.tm_mon = mon;
3528             mytm.tm_year = year;
3529             mytm.tm_wday = wday;
3530             mytm.tm_yday = yday;
3531             mytm.tm_isdst = isdst;
3532             RETVAL = asctime(&mytm);
3533         }
3534     OUTPUT:
3535         RETVAL
3536
3537 long
3538 clock()
3539
3540 char *
3541 ctime(time)
3542         Time_t          &time
3543
3544 void
3545 times()
3546         PPCODE:
3547         struct tms tms;
3548         clock_t realtime;
3549         realtime = times( &tms );
3550         EXTEND(SP,5);
3551         PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
3552         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
3553         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
3554         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
3555         PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
3556
3557 double
3558 difftime(time1, time2)
3559         Time_t          time1
3560         Time_t          time2
3561
3562 SysRetLong
3563 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
3564         int             sec
3565         int             min
3566         int             hour
3567         int             mday
3568         int             mon
3569         int             year
3570         int             wday
3571         int             yday
3572         int             isdst
3573     CODE:
3574         {
3575             struct tm mytm;
3576             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3577             mytm.tm_sec = sec;
3578             mytm.tm_min = min;
3579             mytm.tm_hour = hour;
3580             mytm.tm_mday = mday;
3581             mytm.tm_mon = mon;
3582             mytm.tm_year = year;
3583             mytm.tm_wday = wday;
3584             mytm.tm_yday = yday;
3585             mytm.tm_isdst = isdst;
3586             RETVAL = mktime(&mytm);
3587         }
3588     OUTPUT:
3589         RETVAL
3590
3591 char *
3592 strftime(fmt, sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
3593         char *          fmt
3594         int             sec
3595         int             min
3596         int             hour
3597         int             mday
3598         int             mon
3599         int             year
3600         int             wday
3601         int             yday
3602         int             isdst
3603     CODE:
3604         {
3605             char tmpbuf[128];
3606             struct tm mytm;
3607             int len;
3608             init_tm(&mytm);     /* XXX workaround - see init_tm() above */
3609             mytm.tm_sec = sec;
3610             mytm.tm_min = min;
3611             mytm.tm_hour = hour;
3612             mytm.tm_mday = mday;
3613             mytm.tm_mon = mon;
3614             mytm.tm_year = year;
3615             mytm.tm_wday = wday;
3616             mytm.tm_yday = yday;
3617             mytm.tm_isdst = isdst;
3618             len = strftime(tmpbuf, sizeof tmpbuf, fmt, &mytm);
3619             ST(0) = sv_2mortal(newSVpv(tmpbuf, len));
3620         }
3621
3622 void
3623 tzset()
3624
3625 void
3626 tzname()
3627     PPCODE:
3628         EXTEND(SP,2);
3629         PUSHs(sv_2mortal(newSVpv(tzname[0],strlen(tzname[0]))));
3630         PUSHs(sv_2mortal(newSVpv(tzname[1],strlen(tzname[1]))));
3631
3632 SysRet
3633 access(filename, mode)
3634         char *          filename
3635         Mode_t          mode
3636
3637 char *
3638 ctermid(s = 0)
3639         char *          s = 0;
3640
3641 char *
3642 cuserid(s = 0)
3643         char *          s = 0;
3644
3645 SysRetLong
3646 fpathconf(fd, name)
3647         int             fd
3648         int             name
3649
3650 SysRetLong
3651 pathconf(filename, name)
3652         char *          filename
3653         int             name
3654
3655 SysRet
3656 pause()
3657
3658 SysRetLong
3659 sysconf(name)
3660         int             name
3661
3662 char *
3663 ttyname(fd)
3664         int             fd