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