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