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