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