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