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