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