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