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