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