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