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