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