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