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