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