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