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