10 * Ideally this should be somewhere down in the includes
11 * but putting it in other places is giving compiler errors.
12 * Also here I am unable to check for HAS_UNAME since it wouldn't have
13 * yet come into the file at this stage - sgp 18th Oct 2000
15 #include <sys/utsname.h>
18 #define PERL_NO_GET_CONTEXT
21 #define PERLIO_NOT_STDIO 1
24 #if defined(PERL_IMPLICIT_SYS)
28 # define open PerlLIO_open3
31 #ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
58 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
59 metaconfig for future extension writers. We don't use them in POSIX.
60 (This is really sneaky :-) --AD
62 #if defined(I_TERMIOS)
70 #include <sys/types.h>
75 #ifdef MACOS_TRADITIONAL
81 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE)
82 extern char *tzname[];
85 #if !defined(WIN32) || (defined(__MINGW32__) && !defined(tzname))
86 char *tzname[] = { "" , "" };
90 #if defined(__VMS) && !defined(__POSIX_SOURCE)
91 # include <libdef.h> /* LIB$_INVARG constant */
92 # include <lib$routines.h> /* prototype for lib$ediv() */
93 # include <starlet.h> /* prototype for sys$gettim() */
94 # if DECC_VERSION < 50000000
95 # define pid_t int /* old versions of DECC miss this in types.h */
99 # define mkfifo(a,b) (not_here("mkfifo"),-1)
100 # define tzset() not_here("tzset")
102 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
103 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
104 # include <utsname.h>
105 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
107 /* The POSIX notion of ttyname() is better served by getname() under VMS */
108 static char ttnambuf[64];
109 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
111 /* The non-POSIX CRTL times() has void return type, so we just get the
112 current time directly */
113 clock_t vms_times(struct tms *bufptr) {
116 /* Get wall time and convert to 10 ms intervals to
117 * produce the return value that the POSIX standard expects */
118 # if defined(__DECC) && defined (__ALPHA)
121 _ckvmssts(sys$gettim(&vmstime));
123 retval = vmstime & 0x7fffffff;
125 /* (Older hw or ccs don't have an atomic 64-bit type, so we
126 * juggle 32-bit ints (and a float) to produce a time_t result
127 * with minimal loss of information.) */
128 long int vmstime[2],remainder,divisor = 100000;
129 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
130 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
131 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
133 /* Fill in the struct tms using the CRTL routine . . .*/
134 times((tbuffer_t *)bufptr);
135 return (clock_t) retval;
137 # define times(t) vms_times(t)
139 #if defined (__CYGWIN__)
140 # define tzname _tzname
142 #if defined (WIN32) || defined (NETWARE)
144 # define mkfifo(a,b) not_here("mkfifo")
145 # define ttyname(a) (char*)not_here("ttyname")
146 # define sigset_t long
149 # define tzname _tzname
152 # define mode_t short
155 # define mode_t short
157 # define tzset() not_here("tzset")
159 # ifndef _POSIX_OPEN_MAX
160 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
163 # define sigaction(a,b,c) not_here("sigaction")
164 # define sigpending(a) not_here("sigpending")
165 # define sigprocmask(a,b,c) not_here("sigprocmask")
166 # define sigsuspend(a) not_here("sigsuspend")
167 # define sigemptyset(a) not_here("sigemptyset")
168 # define sigaddset(a,b) not_here("sigaddset")
169 # define sigdelset(a,b) not_here("sigdelset")
170 # define sigfillset(a) not_here("sigfillset")
171 # define sigismember(a,b) not_here("sigismember")
175 # define setuid(a) not_here("setuid")
176 # define setgid(a) not_here("setgid")
181 # if defined(OS2) || defined(MACOS_TRADITIONAL)
182 # define mkfifo(a,b) not_here("mkfifo")
183 # else /* !( defined OS2 ) */
185 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
188 # endif /* !HAS_MKFIFO */
190 # ifdef MACOS_TRADITIONAL
191 # define ttyname(a) (char*)not_here("ttyname")
192 # define tzset() not_here("tzset")
195 # include <sys/times.h>
197 # include <sys/utsname.h>
199 # include <sys/wait.h>
204 #endif /* WIN32 || NETWARE */
208 typedef long SysRetLong;
209 typedef sigset_t* POSIX__SigSet;
210 typedef HV* POSIX__SigAction;
212 typedef struct termios* POSIX__Termios;
213 #else /* Define termios types to int, and call not_here for the functions.*/
214 #define POSIX__Termios int
218 #define cfgetispeed(x) not_here("cfgetispeed")
219 #define cfgetospeed(x) not_here("cfgetospeed")
220 #define tcdrain(x) not_here("tcdrain")
221 #define tcflush(x,y) not_here("tcflush")
222 #define tcsendbreak(x,y) not_here("tcsendbreak")
223 #define cfsetispeed(x,y) not_here("cfsetispeed")
224 #define cfsetospeed(x,y) not_here("cfsetospeed")
225 #define ctermid(x) (char *) not_here("ctermid")
226 #define tcflow(x,y) not_here("tcflow")
227 #define tcgetattr(x,y) not_here("tcgetattr")
228 #define tcsetattr(x,y,z) not_here("tcsetattr")
231 /* Possibly needed prototypes */
232 char *cuserid (char *);
234 double strtod (const char *, char **);
235 long strtol (const char *, char **, int);
236 unsigned long strtoul (const char *, char **, int);
240 #define cuserid(a) (char *) not_here("cuserid")
244 #define difftime(a,b) not_here("difftime")
247 #ifndef HAS_FPATHCONF
248 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
251 #define mktime(a) not_here("mktime")
254 #define nice(a) not_here("nice")
257 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
260 #define sysconf(n) (SysRetLong) not_here("sysconf")
263 #define readlink(a,b,c) not_here("readlink")
266 #define setpgid(a,b) not_here("setpgid")
269 #define setsid() not_here("setsid")
272 #define strcoll(s1,s2) not_here("strcoll")
275 #define strtod(s1,s2) not_here("strtod")
278 #define strtol(s1,s2,b) not_here("strtol")
281 #define strtoul(s1,s2,b) not_here("strtoul")
284 #define strxfrm(s1,s2,n) not_here("strxfrm")
286 #ifndef HAS_TCGETPGRP
287 #define tcgetpgrp(a) not_here("tcgetpgrp")
289 #ifndef HAS_TCSETPGRP
290 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
294 #define times(a) not_here("times")
298 #define uname(a) not_here("uname")
301 #define waitpid(a,b,c) not_here("waitpid")
306 #define mblen(a,b) not_here("mblen")
310 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
313 #define mbtowc(pwc, s, n) not_here("mbtowc")
316 #define wcstombs(s, pwcs, n) not_here("wcstombs")
319 #define wctomb(s, wchar) not_here("wcstombs")
321 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
322 /* If we don't have these functions, then we wouldn't have gotten a typedef
323 for wchar_t, the wide character type. Defining wchar_t allows the
324 functions referencing it to compile. Its actual type is then meaningless,
325 since without the above functions, all sections using it end up calling
326 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
332 #ifndef HAS_LOCALECONV
333 #define localeconv() not_here("localeconv")
336 #ifdef HAS_LONG_DOUBLE
337 # if LONG_DOUBLESIZE > NVSIZE
338 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
342 #ifndef HAS_LONG_DOUBLE
354 /* Background: in most systems the low byte of the wait status
355 * is the signal (the lowest 7 bits) and the coredump flag is
356 * the eight bit, and the second lowest byte is the exit status.
357 * BeOS bucks the trend and has the bytes in different order.
358 * See beos/beos.c for how the reality is bent even in BeOS
359 * to follow the traditional. However, to make the POSIX
360 * wait W*() macros to work in BeOS, we need to unbend the
361 * reality back in place. --jhi */
363 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
365 # define WMUNGE(x) (x)
371 croak("POSIX::%s not implemented on this architecture", s);
375 #include "const-c.inc"
377 /* These were implemented in the old "constant" subroutine. They are actually
378 macros that take an integer argument and return an integer result. */
380 int_macro_int (const char *name, STRLEN len, IV *arg_result) {
381 /* Initially switch on the length of the name. */
382 /* This code has been edited from a "constant" function generated by:
384 use ExtUtils::Constant qw (constant_types C_constant XS_constant);
386 my $types = {map {($_, 1)} qw(IV)};
387 my @names = (qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS WIFEXITED
388 WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
390 print constant_types(); # macro defs
391 foreach (C_constant ("POSIX", 'int_macro_int', 'IV', $types, undef, 5, @names) ) {
392 print $_, "\n"; # C constant subs
394 print "#### XS Section:\n";
395 print XS_constant ("POSIX", $types);
401 /* Names all of length 7. */
402 /* S_ISBLK S_ISCHR S_ISDIR S_ISREG */
403 /* Offset 5 gives the best switch position. */
406 if (memEQ(name, "S_ISREG", 7)) {
409 *arg_result = S_ISREG(*arg_result);
410 return PERL_constant_ISIV;
412 return PERL_constant_NOTDEF;
417 if (memEQ(name, "S_ISCHR", 7)) {
420 *arg_result = S_ISCHR(*arg_result);
421 return PERL_constant_ISIV;
423 return PERL_constant_NOTDEF;
428 if (memEQ(name, "S_ISDIR", 7)) {
431 *arg_result = S_ISDIR(*arg_result);
432 return PERL_constant_ISIV;
434 return PERL_constant_NOTDEF;
439 if (memEQ(name, "S_ISBLK", 7)) {
442 *arg_result = S_ISBLK(*arg_result);
443 return PERL_constant_ISIV;
445 return PERL_constant_NOTDEF;
452 /* Names all of length 8. */
453 /* S_ISFIFO WSTOPSIG WTERMSIG */
454 /* Offset 3 gives the best switch position. */
457 if (memEQ(name, "WSTOPSIG", 8)) {
461 *arg_result = WSTOPSIG(WMUNGE(i));
462 return PERL_constant_ISIV;
464 return PERL_constant_NOTDEF;
469 if (memEQ(name, "WTERMSIG", 8)) {
473 *arg_result = WTERMSIG(WMUNGE(i));
474 return PERL_constant_ISIV;
476 return PERL_constant_NOTDEF;
481 if (memEQ(name, "S_ISFIFO", 8)) {
484 *arg_result = S_ISFIFO(*arg_result);
485 return PERL_constant_ISIV;
487 return PERL_constant_NOTDEF;
494 if (memEQ(name, "WIFEXITED", 9)) {
497 *arg_result = WIFEXITED(WMUNGE(i));
498 return PERL_constant_ISIV;
500 return PERL_constant_NOTDEF;
505 if (memEQ(name, "WIFSTOPPED", 10)) {
508 *arg_result = WIFSTOPPED(WMUNGE(i));
509 return PERL_constant_ISIV;
511 return PERL_constant_NOTDEF;
516 /* Names all of length 11. */
517 /* WEXITSTATUS WIFSIGNALED */
518 /* Offset 1 gives the best switch position. */
521 if (memEQ(name, "WEXITSTATUS", 11)) {
525 *arg_result = WEXITSTATUS(WMUNGE(i));
526 return PERL_constant_ISIV;
528 return PERL_constant_NOTDEF;
533 if (memEQ(name, "WIFSIGNALED", 11)) {
537 *arg_result = WIFSIGNALED(WMUNGE(i));
538 return PERL_constant_ISIV;
540 return PERL_constant_NOTDEF;
547 return PERL_constant_NOTFOUND;
551 restore_sigmask(pTHX_ SV *osset_sv)
553 /* Fortunately, restoring the signal mask can't fail, because
554 * there's nothing we can do about it if it does -- we're not
555 * supposed to return -1 from sigaction unless the disposition
558 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
559 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
562 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
565 new(packname = "POSIX::SigSet", ...)
570 New(0, RETVAL, 1, sigset_t);
572 for (i = 1; i < items; i++)
573 sigaddset(RETVAL, SvIV(ST(i)));
585 sigaddset(sigset, sig)
590 sigdelset(sigset, sig)
603 sigismember(sigset, sig)
608 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
611 new(packname = "POSIX::Termios", ...)
616 New(0, RETVAL, 1, struct termios);
627 POSIX::Termios termios_ref
630 Safefree(termios_ref);
636 getattr(termios_ref, fd = 0)
637 POSIX::Termios termios_ref
640 RETVAL = tcgetattr(fd, termios_ref);
645 setattr(termios_ref, fd = 0, optional_actions = 0)
646 POSIX::Termios termios_ref
650 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
655 cfgetispeed(termios_ref)
656 POSIX::Termios termios_ref
659 cfgetospeed(termios_ref)
660 POSIX::Termios termios_ref
663 getiflag(termios_ref)
664 POSIX::Termios termios_ref
666 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
667 RETVAL = termios_ref->c_iflag;
669 not_here("getiflag");
676 getoflag(termios_ref)
677 POSIX::Termios termios_ref
679 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
680 RETVAL = termios_ref->c_oflag;
682 not_here("getoflag");
689 getcflag(termios_ref)
690 POSIX::Termios termios_ref
692 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
693 RETVAL = termios_ref->c_cflag;
695 not_here("getcflag");
702 getlflag(termios_ref)
703 POSIX::Termios termios_ref
705 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
706 RETVAL = termios_ref->c_lflag;
708 not_here("getlflag");
715 getcc(termios_ref, ccix)
716 POSIX::Termios termios_ref
719 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
721 croak("Bad getcc subscript");
722 RETVAL = termios_ref->c_cc[ccix];
731 cfsetispeed(termios_ref, speed)
732 POSIX::Termios termios_ref
736 cfsetospeed(termios_ref, speed)
737 POSIX::Termios termios_ref
741 setiflag(termios_ref, iflag)
742 POSIX::Termios termios_ref
745 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
746 termios_ref->c_iflag = iflag;
748 not_here("setiflag");
752 setoflag(termios_ref, oflag)
753 POSIX::Termios termios_ref
756 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
757 termios_ref->c_oflag = oflag;
759 not_here("setoflag");
763 setcflag(termios_ref, cflag)
764 POSIX::Termios termios_ref
767 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
768 termios_ref->c_cflag = cflag;
770 not_here("setcflag");
774 setlflag(termios_ref, lflag)
775 POSIX::Termios termios_ref
778 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
779 termios_ref->c_lflag = lflag;
781 not_here("setlflag");
785 setcc(termios_ref, ccix, cc)
786 POSIX::Termios termios_ref
790 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
792 croak("Bad setcc subscript");
793 termios_ref->c_cc[ccix] = cc;
799 MODULE = POSIX PACKAGE = POSIX
801 INCLUDE: const-xs.inc
804 int_macro_int(sv, iv)
811 const char * s = SvPV(sv, len);
814 /* Change this to int_macro_int(s, len, &iv, &nv);
815 if you need to return both NVs and IVs */
816 type = int_macro_int(s, len, &iv);
817 /* Return 1 or 2 items. First is error message, or undef if no error.
818 Second, if present, is found value */
820 case PERL_constant_NOTFOUND:
821 sv = sv_2mortal(newSVpvf("%s is not a valid POSIX macro", s));
826 case PERL_constant_NOTDEF:
827 sv = sv_2mortal(newSVpvf(
828 "Your vendor has not defined POSIX macro %s, used", s));
833 case PERL_constant_ISIV:
837 sv = sv_2mortal(newSVpvf(
838 "Unexpected return type %d while processing POSIX macro %s, used",
847 unsigned char * charstring
849 unsigned char *s = charstring;
850 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
851 for (RETVAL = 1; RETVAL && s < e; s++)
859 unsigned char * charstring
861 unsigned char *s = charstring;
862 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
863 for (RETVAL = 1; RETVAL && s < e; s++)
871 unsigned char * charstring
873 unsigned char *s = charstring;
874 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
875 for (RETVAL = 1; RETVAL && s < e; s++)
883 unsigned char * charstring
885 unsigned char *s = charstring;
886 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
887 for (RETVAL = 1; RETVAL && s < e; s++)
895 unsigned char * charstring
897 unsigned char *s = charstring;
898 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
899 for (RETVAL = 1; RETVAL && s < e; s++)
907 unsigned char * charstring
909 unsigned char *s = charstring;
910 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
911 for (RETVAL = 1; RETVAL && s < e; s++)
919 unsigned char * charstring
921 unsigned char *s = charstring;
922 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
923 for (RETVAL = 1; RETVAL && s < e; s++)
931 unsigned char * charstring
933 unsigned char *s = charstring;
934 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
935 for (RETVAL = 1; RETVAL && s < e; s++)
943 unsigned char * charstring
945 unsigned char *s = charstring;
946 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
947 for (RETVAL = 1; RETVAL && s < e; s++)
955 unsigned char * charstring
957 unsigned char *s = charstring;
958 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
959 for (RETVAL = 1; RETVAL && s < e; s++)
967 unsigned char * charstring
969 unsigned char *s = charstring;
970 unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
971 for (RETVAL = 1; RETVAL && s < e; s++)
978 open(filename, flags = O_RDONLY, mode = 0666)
983 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
984 TAINT_PROPER("open");
985 RETVAL = open(filename, flags, mode);
993 #ifdef HAS_LOCALECONV
996 if ((lcbuf = localeconv())) {
998 if (lcbuf->decimal_point && *lcbuf->decimal_point)
999 hv_store(RETVAL, "decimal_point", 13,
1000 newSVpv(lcbuf->decimal_point, 0), 0);
1001 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
1002 hv_store(RETVAL, "thousands_sep", 13,
1003 newSVpv(lcbuf->thousands_sep, 0), 0);
1004 #ifndef NO_LOCALECONV_GROUPING
1005 if (lcbuf->grouping && *lcbuf->grouping)
1006 hv_store(RETVAL, "grouping", 8,
1007 newSVpv(lcbuf->grouping, 0), 0);
1009 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
1010 hv_store(RETVAL, "int_curr_symbol", 15,
1011 newSVpv(lcbuf->int_curr_symbol, 0), 0);
1012 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
1013 hv_store(RETVAL, "currency_symbol", 15,
1014 newSVpv(lcbuf->currency_symbol, 0), 0);
1015 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
1016 hv_store(RETVAL, "mon_decimal_point", 17,
1017 newSVpv(lcbuf->mon_decimal_point, 0), 0);
1018 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1019 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
1020 hv_store(RETVAL, "mon_thousands_sep", 17,
1021 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
1023 #ifndef NO_LOCALECONV_MON_GROUPING
1024 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
1025 hv_store(RETVAL, "mon_grouping", 12,
1026 newSVpv(lcbuf->mon_grouping, 0), 0);
1028 if (lcbuf->positive_sign && *lcbuf->positive_sign)
1029 hv_store(RETVAL, "positive_sign", 13,
1030 newSVpv(lcbuf->positive_sign, 0), 0);
1031 if (lcbuf->negative_sign && *lcbuf->negative_sign)
1032 hv_store(RETVAL, "negative_sign", 13,
1033 newSVpv(lcbuf->negative_sign, 0), 0);
1035 if (lcbuf->int_frac_digits != CHAR_MAX)
1036 hv_store(RETVAL, "int_frac_digits", 15,
1037 newSViv(lcbuf->int_frac_digits), 0);
1038 if (lcbuf->frac_digits != CHAR_MAX)
1039 hv_store(RETVAL, "frac_digits", 11,
1040 newSViv(lcbuf->frac_digits), 0);
1041 if (lcbuf->p_cs_precedes != CHAR_MAX)
1042 hv_store(RETVAL, "p_cs_precedes", 13,
1043 newSViv(lcbuf->p_cs_precedes), 0);
1044 if (lcbuf->p_sep_by_space != CHAR_MAX)
1045 hv_store(RETVAL, "p_sep_by_space", 14,
1046 newSViv(lcbuf->p_sep_by_space), 0);
1047 if (lcbuf->n_cs_precedes != CHAR_MAX)
1048 hv_store(RETVAL, "n_cs_precedes", 13,
1049 newSViv(lcbuf->n_cs_precedes), 0);
1050 if (lcbuf->n_sep_by_space != CHAR_MAX)
1051 hv_store(RETVAL, "n_sep_by_space", 14,
1052 newSViv(lcbuf->n_sep_by_space), 0);
1053 if (lcbuf->p_sign_posn != CHAR_MAX)
1054 hv_store(RETVAL, "p_sign_posn", 11,
1055 newSViv(lcbuf->p_sign_posn), 0);
1056 if (lcbuf->n_sign_posn != CHAR_MAX)
1057 hv_store(RETVAL, "n_sign_posn", 11,
1058 newSViv(lcbuf->n_sign_posn), 0);
1061 localeconv(); /* A stub to call not_here(). */
1067 setlocale(category, locale = 0)
1071 RETVAL = setlocale(category, locale);
1073 #ifdef USE_LOCALE_CTYPE
1074 if (category == LC_CTYPE
1076 || category == LC_ALL
1082 if (category == LC_ALL)
1083 newctype = setlocale(LC_CTYPE, NULL);
1087 new_ctype(newctype);
1089 #endif /* USE_LOCALE_CTYPE */
1090 #ifdef USE_LOCALE_COLLATE
1091 if (category == LC_COLLATE
1093 || category == LC_ALL
1099 if (category == LC_ALL)
1100 newcoll = setlocale(LC_COLLATE, NULL);
1104 new_collate(newcoll);
1106 #endif /* USE_LOCALE_COLLATE */
1107 #ifdef USE_LOCALE_NUMERIC
1108 if (category == LC_NUMERIC
1110 || category == LC_ALL
1116 if (category == LC_ALL)
1117 newnum = setlocale(LC_NUMERIC, NULL);
1121 new_numeric(newnum);
1123 #endif /* USE_LOCALE_NUMERIC */
1163 /* (We already know stack is long enough.) */
1164 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1165 PUSHs(sv_2mortal(newSViv(expvar)));
1181 /* (We already know stack is long enough.) */
1182 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1183 PUSHs(sv_2mortal(newSVnv(intvar)));
1198 sigaction(sig, optaction, oldaction = 0)
1201 POSIX::SigAction oldaction
1203 #if defined(WIN32) || defined(NETWARE)
1204 RETVAL = not_here("sigaction");
1206 # This code is really grody because we're trying to make the signal
1207 # interface look beautiful, which is hard.
1210 POSIX__SigAction action;
1211 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1212 struct sigaction act;
1213 struct sigaction oact;
1217 POSIX__SigSet sigset;
1219 SV** sigsvp = hv_fetch(GvHVn(siggv),
1221 strlen(PL_sig_name[sig]),
1224 /* Check optaction and set action */
1225 if(SvTRUE(optaction)) {
1226 if(sv_isa(optaction, "POSIX::SigAction"))
1227 action = (HV*)SvRV(optaction);
1229 croak("action is not of type POSIX::SigAction");
1235 /* sigaction() is supposed to look atomic. In particular, any
1236 * signal handler invoked during a sigaction() call should
1237 * see either the old or the new disposition, and not something
1238 * in between. We use sigprocmask() to make it so.
1241 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1245 /* Restore signal mask no matter how we exit this block. */
1246 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1247 SAVEFREESV( osset_sv );
1248 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1250 RETVAL=-1; /* In case both oldaction and action are 0. */
1252 /* Remember old disposition if desired. */
1254 svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
1256 croak("Can't supply an oldaction without a HANDLER");
1257 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1258 sv_setsv(*svp, *sigsvp);
1261 sv_setpv(*svp, "DEFAULT");
1263 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1266 /* Get back the mask. */
1267 svp = hv_fetch(oldaction, "MASK", 4, TRUE);
1268 if (sv_isa(*svp, "POSIX::SigSet")) {
1269 IV tmp = SvIV((SV*)SvRV(*svp));
1270 sigset = INT2PTR(sigset_t*, tmp);
1273 New(0, sigset, 1, sigset_t);
1274 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1276 *sigset = oact.sa_mask;
1278 /* Get back the flags. */
1279 svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
1280 sv_setiv(*svp, oact.sa_flags);
1284 /* Vector new handler through %SIG. (We always use sighandler
1285 for the C signal handler, which reads %SIG to dispatch.) */
1286 svp = hv_fetch(action, "HANDLER", 7, FALSE);
1288 croak("Can't supply an action without a HANDLER");
1289 sv_setsv(*sigsvp, *svp);
1290 mg_set(*sigsvp); /* handles DEFAULT and IGNORE */
1292 char *s=SvPVX(*svp);
1293 if(strEQ(s,"IGNORE")) {
1294 act.sa_handler = SIG_IGN;
1296 else if(strEQ(s,"DEFAULT")) {
1297 act.sa_handler = SIG_DFL;
1300 act.sa_handler = PL_sighandlerp;
1304 act.sa_handler = PL_sighandlerp;
1307 /* Set up any desired mask. */
1308 svp = hv_fetch(action, "MASK", 4, FALSE);
1309 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1310 IV tmp = SvIV((SV*)SvRV(*svp));
1311 sigset = INT2PTR(sigset_t*, tmp);
1312 act.sa_mask = *sigset;
1315 sigemptyset(& act.sa_mask);
1317 /* Set up any desired flags. */
1318 svp = hv_fetch(action, "FLAGS", 5, FALSE);
1319 act.sa_flags = svp ? SvIV(*svp) : 0;
1321 /* Don't worry about cleaning up *sigsvp if this fails,
1322 * because that means we tried to disposition a
1323 * nonblockable signal, in which case *sigsvp is
1324 * essentially meaningless anyway.
1326 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1339 POSIX::SigSet sigset
1342 sigprocmask(how, sigset, oldsigset = 0)
1344 POSIX::SigSet sigset
1345 POSIX::SigSet oldsigset = NO_INIT
1350 else if (sv_derived_from(ST(2), "POSIX::SigSet")) {
1351 IV tmp = SvIV((SV*)SvRV(ST(2)));
1352 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1355 New(0, oldsigset, 1, sigset_t);
1356 sigemptyset(oldsigset);
1357 sv_setref_pv(ST(2), "POSIX::SigSet", (void*)oldsigset);
1361 sigsuspend(signal_mask)
1362 POSIX::SigSet signal_mask
1382 lseek(fd, offset, whence)
1395 if (pipe(fds) != -1) {
1397 PUSHs(sv_2mortal(newSViv(fds[0])));
1398 PUSHs(sv_2mortal(newSViv(fds[1])));
1402 read(fd, buffer, nbytes)
1404 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1408 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1411 SvCUR(sv_buffer) = RETVAL;
1412 SvPOK_only(sv_buffer);
1413 *SvEND(sv_buffer) = '\0';
1414 SvTAINTED_on(sv_buffer);
1430 tcsetpgrp(fd, pgrp_id)
1439 if (uname(&buf) >= 0) {
1441 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1442 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1443 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1444 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1445 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1448 uname((char *) 0); /* A stub to call not_here(). */
1452 write(fd, buffer, nbytes)
1463 RETVAL = newSVpvn("", 0);
1464 SvGROW(RETVAL, L_tmpnam);
1465 len = strlen(tmpnam(SvPV(RETVAL, i)));
1466 SvCUR_set(RETVAL, len);
1479 mbstowcs(s, pwcs, n)
1491 wcstombs(s, pwcs, n)
1513 SET_NUMERIC_LOCAL();
1514 num = strtod(str, &unparsed);
1515 PUSHs(sv_2mortal(newSVnv(num)));
1516 if (GIMME == G_ARRAY) {
1519 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1521 PUSHs(&PL_sv_undef);
1525 strtol(str, base = 0)
1532 num = strtol(str, &unparsed, base);
1533 #if IVSIZE <= LONGSIZE
1534 if (num < IV_MIN || num > IV_MAX)
1535 PUSHs(sv_2mortal(newSVnv((double)num)));
1538 PUSHs(sv_2mortal(newSViv((IV)num)));
1539 if (GIMME == G_ARRAY) {
1542 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1544 PUSHs(&PL_sv_undef);
1548 strtoul(str, base = 0)
1555 num = strtoul(str, &unparsed, base);
1557 PUSHs(sv_2mortal(newSViv((IV)num)));
1559 PUSHs(sv_2mortal(newSVnv((double)num)));
1560 if (GIMME == G_ARRAY) {
1563 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1565 PUSHs(&PL_sv_undef);
1575 char *p = SvPV(src,srclen);
1577 ST(0) = sv_2mortal(NEWSV(800,srclen*4+1));
1578 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1579 if (dstlen > srclen) {
1581 SvGROW(ST(0), dstlen);
1582 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1585 SvCUR(ST(0)) = dstlen;
1590 mkfifo(filename, mode)
1594 TAINT_PROPER("mkfifo");
1595 RETVAL = mkfifo(filename, mode);
1611 tcflush(fd, queue_selector)
1616 tcsendbreak(fd, duration)
1621 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1634 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1637 mytm.tm_hour = hour;
1638 mytm.tm_mday = mday;
1640 mytm.tm_year = year;
1641 mytm.tm_wday = wday;
1642 mytm.tm_yday = yday;
1643 mytm.tm_isdst = isdst;
1644 RETVAL = asctime(&mytm);
1661 realtime = times( &tms );
1663 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1664 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1665 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1666 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1667 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1670 difftime(time1, time2)
1675 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
1688 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1691 mytm.tm_hour = hour;
1692 mytm.tm_mday = mday;
1694 mytm.tm_year = year;
1695 mytm.tm_wday = wday;
1696 mytm.tm_yday = yday;
1697 mytm.tm_isdst = isdst;
1698 RETVAL = mktime(&mytm);
1703 #XXX: if $xsubpp::WantOptimize is always the default
1704 # sv_setpv(TARG, ...) could be used rather than
1705 # ST(0) = sv_2mortal(newSVpv(...))
1707 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1720 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1722 ST(0) = sv_2mortal(newSVpv(buf, 0));
1734 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1735 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1738 access(filename, mode)
1756 pathconf(filename, name)
1785 XSprePUSH; PUSHTARG;