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