6 * Ideally this should be somewhere down in the includes
7 * but putting it in other places is giving compiler errors.
8 * Also here I am unable to check for HAS_UNAME since it wouldn't have
9 * yet come into the file at this stage - sgp 18th Oct 2000
11 #include <sys/utsname.h>
14 #define PERL_NO_GET_CONTEXT
17 #define PERLIO_NOT_STDIO 1
20 #if defined(PERL_IMPLICIT_SYS)
24 # define open PerlLIO_open3
27 #ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
54 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
55 metaconfig for future extension writers. We don't use them in POSIX.
56 (This is really sneaky :-) --AD
58 #if defined(I_TERMIOS)
68 #include <sys/types.h>
76 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
77 extern char *tzname[];
80 #if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
81 char *tzname[] = { "" , "" };
85 #ifndef PERL_UNUSED_DECL
87 # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
88 # define PERL_UNUSED_DECL
90 # define PERL_UNUSED_DECL __attribute__((unused))
93 # define PERL_UNUSED_DECL
98 #define dNOOP extern int Perl___notused PERL_UNUSED_DECL
105 #if defined(__VMS) && !defined(__POSIX_SOURCE)
106 # include <libdef.h> /* LIB$_INVARG constant */
107 # include <lib$routines.h> /* prototype for lib$ediv() */
108 # include <starlet.h> /* prototype for sys$gettim() */
109 # if DECC_VERSION < 50000000
110 # define pid_t int /* old versions of DECC miss this in types.h */
114 # define mkfifo(a,b) (not_here("mkfifo"),-1)
115 # define tzset() not_here("tzset")
117 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
118 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
119 # include <utsname.h>
120 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
122 /* The POSIX notion of ttyname() is better served by getname() under VMS */
123 static char ttnambuf[64];
124 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
126 /* The non-POSIX CRTL times() has void return type, so we just get the
127 current time directly */
128 clock_t vms_times(struct tms *bufptr) {
131 /* Get wall time and convert to 10 ms intervals to
132 * produce the return value that the POSIX standard expects */
133 # if defined(__DECC) && defined (__ALPHA)
136 _ckvmssts(sys$gettim(&vmstime));
138 retval = vmstime & 0x7fffffff;
140 /* (Older hw or ccs don't have an atomic 64-bit type, so we
141 * juggle 32-bit ints (and a float) to produce a time_t result
142 * with minimal loss of information.) */
143 long int vmstime[2],remainder,divisor = 100000;
144 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
145 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
146 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
148 /* Fill in the struct tms using the CRTL routine . . .*/
149 times((tbuffer_t *)bufptr);
150 return (clock_t) retval;
152 # define times(t) vms_times(t)
154 #if defined (__CYGWIN__)
155 # define tzname _tzname
157 #if defined (WIN32) || defined (NETWARE)
159 # define mkfifo(a,b) not_here("mkfifo")
160 # define ttyname(a) (char*)not_here("ttyname")
161 # define sigset_t long
164 # define tzname _tzname
167 # define mode_t short
170 # define mode_t short
172 # define tzset() not_here("tzset")
174 # ifndef _POSIX_OPEN_MAX
175 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
178 # define sigaction(a,b,c) not_here("sigaction")
179 # define sigpending(a) not_here("sigpending")
180 # define sigprocmask(a,b,c) not_here("sigprocmask")
181 # define sigsuspend(a) not_here("sigsuspend")
182 # define sigemptyset(a) not_here("sigemptyset")
183 # define sigaddset(a,b) not_here("sigaddset")
184 # define sigdelset(a,b) not_here("sigdelset")
185 # define sigfillset(a) not_here("sigfillset")
186 # define sigismember(a,b) not_here("sigismember")
190 # define setuid(a) not_here("setuid")
191 # define setgid(a) not_here("setgid")
197 # define mkfifo(a,b) not_here("mkfifo")
198 # else /* !( defined OS2 ) */
200 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
203 # endif /* !HAS_MKFIFO */
208 # include <sys/times.h>
210 # include <sys/utsname.h>
212 # include <sys/wait.h>
216 #endif /* WIN32 || NETWARE */
220 typedef long SysRetLong;
221 typedef sigset_t* POSIX__SigSet;
222 typedef HV* POSIX__SigAction;
224 typedef struct termios* POSIX__Termios;
225 #else /* Define termios types to int, and call not_here for the functions.*/
226 #define POSIX__Termios int
230 #define cfgetispeed(x) not_here("cfgetispeed")
231 #define cfgetospeed(x) not_here("cfgetospeed")
232 #define tcdrain(x) not_here("tcdrain")
233 #define tcflush(x,y) not_here("tcflush")
234 #define tcsendbreak(x,y) not_here("tcsendbreak")
235 #define cfsetispeed(x,y) not_here("cfsetispeed")
236 #define cfsetospeed(x,y) not_here("cfsetospeed")
237 #define ctermid(x) (char *) not_here("ctermid")
238 #define tcflow(x,y) not_here("tcflow")
239 #define tcgetattr(x,y) not_here("tcgetattr")
240 #define tcsetattr(x,y,z) not_here("tcsetattr")
243 /* Possibly needed prototypes */
244 char *cuserid (char *);
246 double strtod (const char *, char **);
247 long strtol (const char *, char **, int);
248 unsigned long strtoul (const char *, char **, int);
252 #define cuserid(a) (char *) not_here("cuserid")
256 #define difftime(a,b) not_here("difftime")
259 #ifndef HAS_FPATHCONF
260 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
263 #define mktime(a) not_here("mktime")
266 #define nice(a) not_here("nice")
269 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
272 #define sysconf(n) (SysRetLong) not_here("sysconf")
275 #define readlink(a,b,c) not_here("readlink")
278 #define setpgid(a,b) not_here("setpgid")
281 #define setsid() not_here("setsid")
284 #define strcoll(s1,s2) not_here("strcoll")
287 #define strtod(s1,s2) not_here("strtod")
290 #define strtol(s1,s2,b) not_here("strtol")
293 #define strtoul(s1,s2,b) not_here("strtoul")
296 #define strxfrm(s1,s2,n) not_here("strxfrm")
298 #ifndef HAS_TCGETPGRP
299 #define tcgetpgrp(a) not_here("tcgetpgrp")
301 #ifndef HAS_TCSETPGRP
302 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
306 #define times(a) not_here("times")
310 #define uname(a) not_here("uname")
313 #define waitpid(a,b,c) not_here("waitpid")
318 #define mblen(a,b) not_here("mblen")
322 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
325 #define mbtowc(pwc, s, n) not_here("mbtowc")
328 #define wcstombs(s, pwcs, n) not_here("wcstombs")
331 #define wctomb(s, wchar) not_here("wcstombs")
333 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
334 /* If we don't have these functions, then we wouldn't have gotten a typedef
335 for wchar_t, the wide character type. Defining wchar_t allows the
336 functions referencing it to compile. Its actual type is then meaningless,
337 since without the above functions, all sections using it end up calling
338 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
344 #ifndef HAS_LOCALECONV
345 #define localeconv() not_here("localeconv")
348 #ifdef HAS_LONG_DOUBLE
349 # if LONG_DOUBLESIZE > NVSIZE
350 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
354 #ifndef HAS_LONG_DOUBLE
366 /* Background: in most systems the low byte of the wait status
367 * is the signal (the lowest 7 bits) and the coredump flag is
368 * the eight bit, and the second lowest byte is the exit status.
369 * BeOS bucks the trend and has the bytes in different order.
370 * See beos/beos.c for how the reality is bent even in BeOS
371 * to follow the traditional. However, to make the POSIX
372 * wait W*() macros to work in BeOS, we need to unbend the
373 * reality back in place. --jhi */
374 /* In actual fact the code below is to blame here. Perl has an internal
375 * representation of the exit status ($?), which it re-composes from the
376 * OS's representation using the W*() POSIX macros. The code below
377 * incorrectly uses the W*() macros on the internal representation,
378 * which fails for OSs that have a different representation (namely BeOS
379 * and Haiku). WMUNGE() is a hack that converts the internal
380 * representation into the OS specific one, so that the W*() macros work
381 * as expected. The better solution would be not to use the W*() macros
382 * in the first place, though. -- Ingo Weinhold
384 #if defined(__BEOS__) || defined(__HAIKU__)
385 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
387 # define WMUNGE(x) (x)
391 not_here(const char *s)
393 croak("POSIX::%s not implemented on this architecture", s);
397 #include "const-c.inc"
400 restore_sigmask(pTHX_ SV *osset_sv)
402 /* Fortunately, restoring the signal mask can't fail, because
403 * there's nothing we can do about it if it does -- we're not
404 * supposed to return -1 from sigaction unless the disposition
407 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
408 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
411 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
414 new(packname = "POSIX::SigSet", ...)
415 const char * packname
419 Newx(RETVAL, 1, sigset_t);
421 for (i = 1; i < items; i++)
422 sigaddset(RETVAL, SvIV(ST(i)));
434 sigaddset(sigset, sig)
439 sigdelset(sigset, sig)
452 sigismember(sigset, sig)
456 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
459 new(packname = "POSIX::Termios", ...)
460 const char * packname
464 Newx(RETVAL, 1, struct termios);
475 POSIX::Termios termios_ref
478 Safefree(termios_ref);
484 getattr(termios_ref, fd = 0)
485 POSIX::Termios termios_ref
488 RETVAL = tcgetattr(fd, termios_ref);
493 setattr(termios_ref, fd = 0, optional_actions = 0)
494 POSIX::Termios termios_ref
498 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
503 cfgetispeed(termios_ref)
504 POSIX::Termios termios_ref
507 cfgetospeed(termios_ref)
508 POSIX::Termios termios_ref
511 getiflag(termios_ref)
512 POSIX::Termios termios_ref
514 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
515 RETVAL = termios_ref->c_iflag;
517 not_here("getiflag");
524 getoflag(termios_ref)
525 POSIX::Termios termios_ref
527 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
528 RETVAL = termios_ref->c_oflag;
530 not_here("getoflag");
537 getcflag(termios_ref)
538 POSIX::Termios termios_ref
540 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
541 RETVAL = termios_ref->c_cflag;
543 not_here("getcflag");
550 getlflag(termios_ref)
551 POSIX::Termios termios_ref
553 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
554 RETVAL = termios_ref->c_lflag;
556 not_here("getlflag");
563 getcc(termios_ref, ccix)
564 POSIX::Termios termios_ref
567 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
569 croak("Bad getcc subscript");
570 RETVAL = termios_ref->c_cc[ccix];
579 cfsetispeed(termios_ref, speed)
580 POSIX::Termios termios_ref
584 cfsetospeed(termios_ref, speed)
585 POSIX::Termios termios_ref
589 setiflag(termios_ref, iflag)
590 POSIX::Termios termios_ref
593 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
594 termios_ref->c_iflag = iflag;
596 not_here("setiflag");
600 setoflag(termios_ref, oflag)
601 POSIX::Termios termios_ref
604 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
605 termios_ref->c_oflag = oflag;
607 not_here("setoflag");
611 setcflag(termios_ref, cflag)
612 POSIX::Termios termios_ref
615 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
616 termios_ref->c_cflag = cflag;
618 not_here("setcflag");
622 setlflag(termios_ref, lflag)
623 POSIX::Termios termios_ref
626 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
627 termios_ref->c_lflag = lflag;
629 not_here("setlflag");
633 setcc(termios_ref, ccix, cc)
634 POSIX::Termios termios_ref
638 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
640 croak("Bad setcc subscript");
641 termios_ref->c_cc[ccix] = cc;
647 MODULE = POSIX PACKAGE = POSIX
649 INCLUDE: const-xs.inc
656 POSIX::WIFSIGNALED = 2
657 POSIX::WIFSTOPPED = 3
661 #if !(defined(WEXITSTATUS) || defined(WIFEXITED) || defined(WIFSIGNALED) \
662 || defined(WIFSTOPPED) || defined(WSTOPSIG) || defined (WTERMSIG))
663 RETVAL = 0; /* Silence compilers that notice this, but don't realise
664 that not_here() can't return. */
669 RETVAL = WEXITSTATUS(WMUNGE(status));
671 not_here("WEXITSTATUS");
676 RETVAL = WIFEXITED(WMUNGE(status));
678 not_here("WIFEXITED");
683 RETVAL = WIFSIGNALED(WMUNGE(status));
685 not_here("WIFSIGNALED");
690 RETVAL = WIFSTOPPED(WMUNGE(status));
692 not_here("WIFSTOPPED");
697 RETVAL = WSTOPSIG(WMUNGE(status));
699 not_here("WSTOPSIG");
704 RETVAL = WTERMSIG(WMUNGE(status));
706 not_here("WTERMSIG");
710 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", ix);
721 unsigned char *s = (unsigned char *) SvPV(charstring, len);
722 unsigned char *e = s + len;
723 for (RETVAL = 1; RETVAL && s < e; s++)
735 unsigned char *s = (unsigned char *) SvPV(charstring, len);
736 unsigned char *e = s + len;
737 for (RETVAL = 1; RETVAL && s < e; s++)
749 unsigned char *s = (unsigned char *) SvPV(charstring, len);
750 unsigned char *e = s + len;
751 for (RETVAL = 1; RETVAL && s < e; s++)
763 unsigned char *s = (unsigned char *) SvPV(charstring, len);
764 unsigned char *e = s + len;
765 for (RETVAL = 1; RETVAL && s < e; s++)
777 unsigned char *s = (unsigned char *) SvPV(charstring, len);
778 unsigned char *e = s + len;
779 for (RETVAL = 1; RETVAL && s < e; s++)
791 unsigned char *s = (unsigned char *) SvPV(charstring, len);
792 unsigned char *e = s + len;
793 for (RETVAL = 1; RETVAL && s < e; s++)
805 unsigned char *s = (unsigned char *) SvPV(charstring, len);
806 unsigned char *e = s + len;
807 for (RETVAL = 1; RETVAL && s < e; s++)
819 unsigned char *s = (unsigned char *) SvPV(charstring, len);
820 unsigned char *e = s + len;
821 for (RETVAL = 1; RETVAL && s < e; s++)
833 unsigned char *s = (unsigned char *) SvPV(charstring, len);
834 unsigned char *e = s + len;
835 for (RETVAL = 1; RETVAL && s < e; s++)
847 unsigned char *s = (unsigned char *) SvPV(charstring, len);
848 unsigned char *e = s + len;
849 for (RETVAL = 1; RETVAL && s < e; s++)
861 unsigned char *s = (unsigned char *) SvPV(charstring, len);
862 unsigned char *e = s + len;
863 for (RETVAL = 1; RETVAL && s < e; s++)
870 open(filename, flags = O_RDONLY, mode = 0666)
875 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
876 TAINT_PROPER("open");
877 RETVAL = open(filename, flags, mode);
885 #ifdef HAS_LOCALECONV
888 sv_2mortal((SV*)RETVAL);
889 if ((lcbuf = localeconv())) {
891 if (lcbuf->decimal_point && *lcbuf->decimal_point)
892 hv_store(RETVAL, "decimal_point", 13,
893 newSVpv(lcbuf->decimal_point, 0), 0);
894 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
895 hv_store(RETVAL, "thousands_sep", 13,
896 newSVpv(lcbuf->thousands_sep, 0), 0);
897 #ifndef NO_LOCALECONV_GROUPING
898 if (lcbuf->grouping && *lcbuf->grouping)
899 hv_store(RETVAL, "grouping", 8,
900 newSVpv(lcbuf->grouping, 0), 0);
902 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
903 hv_store(RETVAL, "int_curr_symbol", 15,
904 newSVpv(lcbuf->int_curr_symbol, 0), 0);
905 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
906 hv_store(RETVAL, "currency_symbol", 15,
907 newSVpv(lcbuf->currency_symbol, 0), 0);
908 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
909 hv_store(RETVAL, "mon_decimal_point", 17,
910 newSVpv(lcbuf->mon_decimal_point, 0), 0);
911 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
912 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
913 hv_store(RETVAL, "mon_thousands_sep", 17,
914 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
916 #ifndef NO_LOCALECONV_MON_GROUPING
917 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
918 hv_store(RETVAL, "mon_grouping", 12,
919 newSVpv(lcbuf->mon_grouping, 0), 0);
921 if (lcbuf->positive_sign && *lcbuf->positive_sign)
922 hv_store(RETVAL, "positive_sign", 13,
923 newSVpv(lcbuf->positive_sign, 0), 0);
924 if (lcbuf->negative_sign && *lcbuf->negative_sign)
925 hv_store(RETVAL, "negative_sign", 13,
926 newSVpv(lcbuf->negative_sign, 0), 0);
928 if (lcbuf->int_frac_digits != CHAR_MAX)
929 hv_store(RETVAL, "int_frac_digits", 15,
930 newSViv(lcbuf->int_frac_digits), 0);
931 if (lcbuf->frac_digits != CHAR_MAX)
932 hv_store(RETVAL, "frac_digits", 11,
933 newSViv(lcbuf->frac_digits), 0);
934 if (lcbuf->p_cs_precedes != CHAR_MAX)
935 hv_store(RETVAL, "p_cs_precedes", 13,
936 newSViv(lcbuf->p_cs_precedes), 0);
937 if (lcbuf->p_sep_by_space != CHAR_MAX)
938 hv_store(RETVAL, "p_sep_by_space", 14,
939 newSViv(lcbuf->p_sep_by_space), 0);
940 if (lcbuf->n_cs_precedes != CHAR_MAX)
941 hv_store(RETVAL, "n_cs_precedes", 13,
942 newSViv(lcbuf->n_cs_precedes), 0);
943 if (lcbuf->n_sep_by_space != CHAR_MAX)
944 hv_store(RETVAL, "n_sep_by_space", 14,
945 newSViv(lcbuf->n_sep_by_space), 0);
946 if (lcbuf->p_sign_posn != CHAR_MAX)
947 hv_store(RETVAL, "p_sign_posn", 11,
948 newSViv(lcbuf->p_sign_posn), 0);
949 if (lcbuf->n_sign_posn != CHAR_MAX)
950 hv_store(RETVAL, "n_sign_posn", 11,
951 newSViv(lcbuf->n_sign_posn), 0);
954 localeconv(); /* A stub to call not_here(). */
960 setlocale(category, locale = 0)
966 retval = setlocale(category, locale);
968 /* Save retval since subsequent setlocale() calls
969 * may overwrite it. */
970 RETVAL = savepv(retval);
971 #ifdef USE_LOCALE_CTYPE
972 if (category == LC_CTYPE
974 || category == LC_ALL
980 if (category == LC_ALL)
981 newctype = setlocale(LC_CTYPE, NULL);
987 #endif /* USE_LOCALE_CTYPE */
988 #ifdef USE_LOCALE_COLLATE
989 if (category == LC_COLLATE
991 || category == LC_ALL
997 if (category == LC_ALL)
998 newcoll = setlocale(LC_COLLATE, NULL);
1002 new_collate(newcoll);
1004 #endif /* USE_LOCALE_COLLATE */
1005 #ifdef USE_LOCALE_NUMERIC
1006 if (category == LC_NUMERIC
1008 || category == LC_ALL
1014 if (category == LC_ALL)
1015 newnum = setlocale(LC_NUMERIC, NULL);
1019 new_numeric(newnum);
1021 #endif /* USE_LOCALE_NUMERIC */
1065 /* (We already know stack is long enough.) */
1066 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1067 PUSHs(sv_2mortal(newSViv(expvar)));
1083 /* (We already know stack is long enough.) */
1084 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1085 PUSHs(sv_2mortal(newSVnv(intvar)));
1100 sigaction(sig, optaction, oldaction = 0)
1103 POSIX::SigAction oldaction
1105 #if defined(WIN32) || defined(NETWARE)
1106 RETVAL = not_here("sigaction");
1108 # This code is really grody because we're trying to make the signal
1109 # interface look beautiful, which is hard.
1113 POSIX__SigAction action;
1114 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1115 struct sigaction act;
1116 struct sigaction oact;
1120 POSIX__SigSet sigset;
1125 croak("Negative signals are not allowed");
1128 if (sig == 0 && SvPOK(ST(0))) {
1129 const char *s = SvPVX_const(ST(0));
1130 int i = whichsig(s);
1132 if (i < 0 && memEQ(s, "SIG", 3))
1133 i = whichsig(s + 3);
1135 if (ckWARN(WARN_SIGNAL))
1136 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1137 "No such signal: SIG%s", s);
1144 if (sig > NSIG) { /* NSIG - 1 is still okay. */
1145 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1146 "No such signal: %d", sig);
1150 sigsvp = hv_fetch(GvHVn(siggv),
1152 strlen(PL_sig_name[sig]),
1155 /* Check optaction and set action */
1156 if(SvTRUE(optaction)) {
1157 if(sv_isa(optaction, "POSIX::SigAction"))
1158 action = (HV*)SvRV(optaction);
1160 croak("action is not of type POSIX::SigAction");
1166 /* sigaction() is supposed to look atomic. In particular, any
1167 * signal handler invoked during a sigaction() call should
1168 * see either the old or the new disposition, and not something
1169 * in between. We use sigprocmask() to make it so.
1172 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1176 /* Restore signal mask no matter how we exit this block. */
1177 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1178 SAVEFREESV( osset_sv );
1179 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1181 RETVAL=-1; /* In case both oldaction and action are 0. */
1183 /* Remember old disposition if desired. */
1185 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
1187 croak("Can't supply an oldaction without a HANDLER");
1188 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1189 sv_setsv(*svp, *sigsvp);
1192 sv_setpv(*svp, "DEFAULT");
1194 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1197 /* Get back the mask. */
1198 svp = hv_fetchs(oldaction, "MASK", TRUE);
1199 if (sv_isa(*svp, "POSIX::SigSet")) {
1200 IV tmp = SvIV((SV*)SvRV(*svp));
1201 sigset = INT2PTR(sigset_t*, tmp);
1204 Newx(sigset, 1, sigset_t);
1205 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1207 *sigset = oact.sa_mask;
1209 /* Get back the flags. */
1210 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
1211 sv_setiv(*svp, oact.sa_flags);
1213 /* Get back whether the old handler used safe signals. */
1214 svp = hv_fetchs(oldaction, "SAFE", TRUE);
1216 /* compare incompatible pointers by casting to integer */
1217 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
1221 /* Safe signals use "csighandler", which vectors through the
1222 PL_sighandlerp pointer when it's safe to do so.
1223 (BTW, "csighandler" is very different from "sighandler".) */
1224 svp = hv_fetchs(action, "SAFE", FALSE);
1228 (*svp && SvTRUE(*svp))
1229 ? PL_csighandlerp : PL_sighandlerp
1232 /* Vector new Perl handler through %SIG.
1233 (The core signal handlers read %SIG to dispatch.) */
1234 svp = hv_fetchs(action, "HANDLER", FALSE);
1236 croak("Can't supply an action without a HANDLER");
1237 sv_setsv(*sigsvp, *svp);
1239 /* This call actually calls sigaction() with almost the
1240 right settings, including appropriate interpretation
1241 of DEFAULT and IGNORE. However, why are we doing
1242 this when we're about to do it again just below? XXX */
1245 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1247 const char *s=SvPVX_const(*svp);
1248 if(strEQ(s,"IGNORE")) {
1249 act.sa_handler = SIG_IGN;
1251 else if(strEQ(s,"DEFAULT")) {
1252 act.sa_handler = SIG_DFL;
1256 /* Set up any desired mask. */
1257 svp = hv_fetchs(action, "MASK", FALSE);
1258 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1259 IV tmp = SvIV((SV*)SvRV(*svp));
1260 sigset = INT2PTR(sigset_t*, tmp);
1261 act.sa_mask = *sigset;
1264 sigemptyset(& act.sa_mask);
1266 /* Set up any desired flags. */
1267 svp = hv_fetchs(action, "FLAGS", FALSE);
1268 act.sa_flags = svp ? SvIV(*svp) : 0;
1270 /* Don't worry about cleaning up *sigsvp if this fails,
1271 * because that means we tried to disposition a
1272 * nonblockable signal, in which case *sigsvp is
1273 * essentially meaningless anyway.
1275 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1288 POSIX::SigSet sigset
1291 sigprocmask(how, sigset, oldsigset = 0)
1293 POSIX::SigSet sigset = NO_INIT
1294 POSIX::SigSet oldsigset = NO_INIT
1296 if (! SvOK(ST(1))) {
1298 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
1299 IV tmp = SvIV((SV*)SvRV(ST(1)));
1300 sigset = INT2PTR(POSIX__SigSet,tmp);
1302 croak("sigset is not of type POSIX::SigSet");
1305 if (items < 3 || ! SvOK(ST(2))) {
1307 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
1308 IV tmp = SvIV((SV*)SvRV(ST(2)));
1309 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1311 croak("oldsigset is not of type POSIX::SigSet");
1315 sigsuspend(signal_mask)
1316 POSIX::SigSet signal_mask
1336 lseek(fd, offset, whence)
1341 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1342 RETVAL = sizeof(Off_t) > sizeof(IV)
1343 ? newSVnv((NV)pos) : newSViv((IV)pos);
1352 if ((incr = nice(incr)) != -1 || errno == 0) {
1354 XPUSHs(sv_2mortal(newSVpvn("0 but true", 10)));
1356 XPUSHs(sv_2mortal(newSViv(incr)));
1363 if (pipe(fds) != -1) {
1365 PUSHs(sv_2mortal(newSViv(fds[0])));
1366 PUSHs(sv_2mortal(newSViv(fds[1])));
1370 read(fd, buffer, nbytes)
1372 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1376 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1379 SvCUR_set(sv_buffer, RETVAL);
1380 SvPOK_only(sv_buffer);
1381 *SvEND(sv_buffer) = '\0';
1382 SvTAINTED_on(sv_buffer);
1398 tcsetpgrp(fd, pgrp_id)
1407 if (uname(&buf) >= 0) {
1409 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1410 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1411 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1412 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1413 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1416 uname((char *) 0); /* A stub to call not_here(). */
1420 write(fd, buffer, nbytes)
1431 RETVAL = newSVpvn("", 0);
1432 SvGROW(RETVAL, L_tmpnam);
1433 len = strlen(tmpnam(SvPV(RETVAL, i)));
1434 SvCUR_set(RETVAL, len);
1447 mbstowcs(s, pwcs, n)
1459 wcstombs(s, pwcs, n)
1481 SET_NUMERIC_LOCAL();
1482 num = strtod(str, &unparsed);
1483 PUSHs(sv_2mortal(newSVnv(num)));
1484 if (GIMME == G_ARRAY) {
1487 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1489 PUSHs(&PL_sv_undef);
1493 strtol(str, base = 0)
1500 num = strtol(str, &unparsed, base);
1501 #if IVSIZE <= LONGSIZE
1502 if (num < IV_MIN || num > IV_MAX)
1503 PUSHs(sv_2mortal(newSVnv((double)num)));
1506 PUSHs(sv_2mortal(newSViv((IV)num)));
1507 if (GIMME == G_ARRAY) {
1510 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1512 PUSHs(&PL_sv_undef);
1516 strtoul(str, base = 0)
1523 num = strtoul(str, &unparsed, base);
1524 #if IVSIZE <= LONGSIZE
1526 PUSHs(sv_2mortal(newSVnv((double)num)));
1529 PUSHs(sv_2mortal(newSViv((IV)num)));
1530 if (GIMME == G_ARRAY) {
1533 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1535 PUSHs(&PL_sv_undef);
1545 char *p = SvPV(src,srclen);
1547 ST(0) = sv_2mortal(newSV(srclen*4+1));
1548 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1549 if (dstlen > srclen) {
1551 SvGROW(ST(0), dstlen);
1552 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1555 SvCUR_set(ST(0), dstlen);
1560 mkfifo(filename, mode)
1564 TAINT_PROPER("mkfifo");
1565 RETVAL = mkfifo(filename, mode);
1581 tcflush(fd, queue_selector)
1586 tcsendbreak(fd, duration)
1591 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1604 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1607 mytm.tm_hour = hour;
1608 mytm.tm_mday = mday;
1610 mytm.tm_year = year;
1611 mytm.tm_wday = wday;
1612 mytm.tm_yday = yday;
1613 mytm.tm_isdst = isdst;
1614 RETVAL = asctime(&mytm);
1631 realtime = times( &tms );
1633 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1634 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1635 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1636 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1637 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1640 difftime(time1, time2)
1645 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1658 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1661 mytm.tm_hour = hour;
1662 mytm.tm_mday = mday;
1664 mytm.tm_year = year;
1665 mytm.tm_wday = wday;
1666 mytm.tm_yday = yday;
1667 mytm.tm_isdst = isdst;
1668 RETVAL = (SysRetLong) mktime(&mytm);
1673 #XXX: if $xsubpp::WantOptimize is always the default
1674 # sv_setpv(TARG, ...) could be used rather than
1675 # ST(0) = sv_2mortal(newSVpv(...))
1677 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1690 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1692 ST(0) = sv_2mortal(newSVpv(buf, 0));
1704 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1705 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1708 access(filename, mode)
1716 #ifdef HAS_CTERMID_R
1717 s = (char *) safemalloc((size_t) L_ctermid);
1719 RETVAL = ctermid(s);
1723 #ifdef HAS_CTERMID_R
1737 pathconf(filename, name)
1751 PL_egid = getegid();
1762 PL_euid = geteuid();
1780 XSprePUSH; PUSHTARG;
1784 lchown(uid, gid, path)
1790 /* yes, the order of arguments is different,
1791 * but consistent with CORE::chown() */
1792 RETVAL = lchown(path, uid, gid);
1794 RETVAL = not_here("lchown");