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>
73 #ifdef MACOS_TRADITIONAL
79 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
80 extern char *tzname[];
83 #if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
84 char *tzname[] = { "" , "" };
88 #ifndef PERL_UNUSED_DECL
90 # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
91 # define PERL_UNUSED_DECL
93 # define PERL_UNUSED_DECL __attribute__((unused))
96 # define PERL_UNUSED_DECL
101 #define dNOOP extern int Perl___notused PERL_UNUSED_DECL
108 #if defined(__VMS) && !defined(__POSIX_SOURCE)
109 # include <libdef.h> /* LIB$_INVARG constant */
110 # include <lib$routines.h> /* prototype for lib$ediv() */
111 # include <starlet.h> /* prototype for sys$gettim() */
112 # if DECC_VERSION < 50000000
113 # define pid_t int /* old versions of DECC miss this in types.h */
117 # define mkfifo(a,b) (not_here("mkfifo"),-1)
118 # define tzset() not_here("tzset")
120 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
121 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
122 # include <utsname.h>
123 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
125 /* The POSIX notion of ttyname() is better served by getname() under VMS */
126 static char ttnambuf[64];
127 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
129 /* The non-POSIX CRTL times() has void return type, so we just get the
130 current time directly */
131 clock_t vms_times(struct tms *bufptr) {
134 /* Get wall time and convert to 10 ms intervals to
135 * produce the return value that the POSIX standard expects */
136 # if defined(__DECC) && defined (__ALPHA)
139 _ckvmssts(sys$gettim(&vmstime));
141 retval = vmstime & 0x7fffffff;
143 /* (Older hw or ccs don't have an atomic 64-bit type, so we
144 * juggle 32-bit ints (and a float) to produce a time_t result
145 * with minimal loss of information.) */
146 long int vmstime[2],remainder,divisor = 100000;
147 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
148 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
149 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
151 /* Fill in the struct tms using the CRTL routine . . .*/
152 times((tbuffer_t *)bufptr);
153 return (clock_t) retval;
155 # define times(t) vms_times(t)
157 #if defined (__CYGWIN__)
158 # define tzname _tzname
160 #if defined (WIN32) || defined (NETWARE)
162 # define mkfifo(a,b) not_here("mkfifo")
163 # define ttyname(a) (char*)not_here("ttyname")
164 # define sigset_t long
167 # define tzname _tzname
170 # define mode_t short
173 # define mode_t short
175 # define tzset() not_here("tzset")
177 # ifndef _POSIX_OPEN_MAX
178 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
181 # define sigaction(a,b,c) not_here("sigaction")
182 # define sigpending(a) not_here("sigpending")
183 # define sigprocmask(a,b,c) not_here("sigprocmask")
184 # define sigsuspend(a) not_here("sigsuspend")
185 # define sigemptyset(a) not_here("sigemptyset")
186 # define sigaddset(a,b) not_here("sigaddset")
187 # define sigdelset(a,b) not_here("sigdelset")
188 # define sigfillset(a) not_here("sigfillset")
189 # define sigismember(a,b) not_here("sigismember")
193 # define setuid(a) not_here("setuid")
194 # define setgid(a) not_here("setgid")
199 # if defined(OS2) || defined(MACOS_TRADITIONAL)
200 # define mkfifo(a,b) not_here("mkfifo")
201 # else /* !( defined OS2 ) */
203 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
206 # endif /* !HAS_MKFIFO */
208 # ifdef MACOS_TRADITIONAL
209 # define ttyname(a) (char*)not_here("ttyname")
210 # define tzset() not_here("tzset")
215 # include <sys/times.h>
217 # include <sys/utsname.h>
219 # include <sys/wait.h>
224 #endif /* WIN32 || NETWARE */
228 typedef long SysRetLong;
229 typedef sigset_t* POSIX__SigSet;
230 typedef HV* POSIX__SigAction;
232 typedef struct termios* POSIX__Termios;
233 #else /* Define termios types to int, and call not_here for the functions.*/
234 #define POSIX__Termios int
238 #define cfgetispeed(x) not_here("cfgetispeed")
239 #define cfgetospeed(x) not_here("cfgetospeed")
240 #define tcdrain(x) not_here("tcdrain")
241 #define tcflush(x,y) not_here("tcflush")
242 #define tcsendbreak(x,y) not_here("tcsendbreak")
243 #define cfsetispeed(x,y) not_here("cfsetispeed")
244 #define cfsetospeed(x,y) not_here("cfsetospeed")
245 #define ctermid(x) (char *) not_here("ctermid")
246 #define tcflow(x,y) not_here("tcflow")
247 #define tcgetattr(x,y) not_here("tcgetattr")
248 #define tcsetattr(x,y,z) not_here("tcsetattr")
251 /* Possibly needed prototypes */
252 char *cuserid (char *);
254 double strtod (const char *, char **);
255 long strtol (const char *, char **, int);
256 unsigned long strtoul (const char *, char **, int);
260 #define cuserid(a) (char *) not_here("cuserid")
264 #define difftime(a,b) not_here("difftime")
267 #ifndef HAS_FPATHCONF
268 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
271 #define mktime(a) not_here("mktime")
274 #define nice(a) not_here("nice")
277 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
280 #define sysconf(n) (SysRetLong) not_here("sysconf")
283 #define readlink(a,b,c) not_here("readlink")
286 #define setpgid(a,b) not_here("setpgid")
289 #define setsid() not_here("setsid")
292 #define strcoll(s1,s2) not_here("strcoll")
295 #define strtod(s1,s2) not_here("strtod")
298 #define strtol(s1,s2,b) not_here("strtol")
301 #define strtoul(s1,s2,b) not_here("strtoul")
304 #define strxfrm(s1,s2,n) not_here("strxfrm")
306 #ifndef HAS_TCGETPGRP
307 #define tcgetpgrp(a) not_here("tcgetpgrp")
309 #ifndef HAS_TCSETPGRP
310 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
314 #define times(a) not_here("times")
318 #define uname(a) not_here("uname")
321 #define waitpid(a,b,c) not_here("waitpid")
326 #define mblen(a,b) not_here("mblen")
330 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
333 #define mbtowc(pwc, s, n) not_here("mbtowc")
336 #define wcstombs(s, pwcs, n) not_here("wcstombs")
339 #define wctomb(s, wchar) not_here("wcstombs")
341 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
342 /* If we don't have these functions, then we wouldn't have gotten a typedef
343 for wchar_t, the wide character type. Defining wchar_t allows the
344 functions referencing it to compile. Its actual type is then meaningless,
345 since without the above functions, all sections using it end up calling
346 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
352 #ifndef HAS_LOCALECONV
353 #define localeconv() not_here("localeconv")
356 #ifdef HAS_LONG_DOUBLE
357 # if LONG_DOUBLESIZE > NVSIZE
358 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
362 #ifndef HAS_LONG_DOUBLE
374 /* Background: in most systems the low byte of the wait status
375 * is the signal (the lowest 7 bits) and the coredump flag is
376 * the eight bit, and the second lowest byte is the exit status.
377 * BeOS bucks the trend and has the bytes in different order.
378 * See beos/beos.c for how the reality is bent even in BeOS
379 * to follow the traditional. However, to make the POSIX
380 * wait W*() macros to work in BeOS, we need to unbend the
381 * reality back in place. --jhi */
382 /* In actual fact the code below is to blame here. Perl has an internal
383 * representation of the exit status ($?), which it re-composes from the
384 * OS's representation using the W*() POSIX macros. The code below
385 * incorrectly uses the W*() macros on the internal representation,
386 * which fails for OSs that have a different representation (namely BeOS
387 * and Haiku). WMUNGE() is a hack that converts the internal
388 * representation into the OS specific one, so that the W*() macros work
389 * as expected. The better solution would be not to use the W*() macros
390 * in the first place, though. -- Ingo Weinhold
392 #if defined(__BEOS__) || defined(__HAIKU__)
393 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
395 # define WMUNGE(x) (x)
399 not_here(const char *s)
401 croak("POSIX::%s not implemented on this architecture", s);
405 #include "const-c.inc"
408 restore_sigmask(pTHX_ SV *osset_sv)
410 /* Fortunately, restoring the signal mask can't fail, because
411 * there's nothing we can do about it if it does -- we're not
412 * supposed to return -1 from sigaction unless the disposition
415 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
416 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
419 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
422 new(packname = "POSIX::SigSet", ...)
423 const char * packname
427 Newx(RETVAL, 1, sigset_t);
429 for (i = 1; i < items; i++)
430 sigaddset(RETVAL, SvIV(ST(i)));
442 sigaddset(sigset, sig)
447 sigdelset(sigset, sig)
460 sigismember(sigset, sig)
464 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
467 new(packname = "POSIX::Termios", ...)
468 const char * packname
472 Newx(RETVAL, 1, struct termios);
483 POSIX::Termios termios_ref
486 Safefree(termios_ref);
492 getattr(termios_ref, fd = 0)
493 POSIX::Termios termios_ref
496 RETVAL = tcgetattr(fd, termios_ref);
501 setattr(termios_ref, fd = 0, optional_actions = 0)
502 POSIX::Termios termios_ref
506 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
511 cfgetispeed(termios_ref)
512 POSIX::Termios termios_ref
515 cfgetospeed(termios_ref)
516 POSIX::Termios termios_ref
519 getiflag(termios_ref)
520 POSIX::Termios termios_ref
522 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
523 RETVAL = termios_ref->c_iflag;
525 not_here("getiflag");
532 getoflag(termios_ref)
533 POSIX::Termios termios_ref
535 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
536 RETVAL = termios_ref->c_oflag;
538 not_here("getoflag");
545 getcflag(termios_ref)
546 POSIX::Termios termios_ref
548 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
549 RETVAL = termios_ref->c_cflag;
551 not_here("getcflag");
558 getlflag(termios_ref)
559 POSIX::Termios termios_ref
561 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
562 RETVAL = termios_ref->c_lflag;
564 not_here("getlflag");
571 getcc(termios_ref, ccix)
572 POSIX::Termios termios_ref
575 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
577 croak("Bad getcc subscript");
578 RETVAL = termios_ref->c_cc[ccix];
587 cfsetispeed(termios_ref, speed)
588 POSIX::Termios termios_ref
592 cfsetospeed(termios_ref, speed)
593 POSIX::Termios termios_ref
597 setiflag(termios_ref, iflag)
598 POSIX::Termios termios_ref
601 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
602 termios_ref->c_iflag = iflag;
604 not_here("setiflag");
608 setoflag(termios_ref, oflag)
609 POSIX::Termios termios_ref
612 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
613 termios_ref->c_oflag = oflag;
615 not_here("setoflag");
619 setcflag(termios_ref, cflag)
620 POSIX::Termios termios_ref
623 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
624 termios_ref->c_cflag = cflag;
626 not_here("setcflag");
630 setlflag(termios_ref, lflag)
631 POSIX::Termios termios_ref
634 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
635 termios_ref->c_lflag = lflag;
637 not_here("setlflag");
641 setcc(termios_ref, ccix, cc)
642 POSIX::Termios termios_ref
646 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
648 croak("Bad setcc subscript");
649 termios_ref->c_cc[ccix] = cc;
655 MODULE = POSIX PACKAGE = POSIX
657 INCLUDE: const-xs.inc
664 POSIX::WIFSIGNALED = 2
665 POSIX::WIFSTOPPED = 3
669 #if !(defined(WEXITSTATUS) || defined(WIFEXITED) || defined(WIFSIGNALED) \
670 || defined(WIFSTOPPED) || defined(WSTOPSIG) || defined (WTERMSIG))
671 RETVAL = 0; /* Silence compilers that notice this, but don't realise
672 that not_here() can't return. */
677 RETVAL = WEXITSTATUS(WMUNGE(status));
679 not_here("WEXITSTATUS");
684 RETVAL = WIFEXITED(WMUNGE(status));
686 not_here("WIFEXITED");
691 RETVAL = WIFSIGNALED(WMUNGE(status));
693 not_here("WIFSIGNALED");
698 RETVAL = WIFSTOPPED(WMUNGE(status));
700 not_here("WIFSTOPPED");
705 RETVAL = WSTOPSIG(WMUNGE(status));
707 not_here("WSTOPSIG");
712 RETVAL = WTERMSIG(WMUNGE(status));
714 not_here("WTERMSIG");
718 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", ix);
729 unsigned char *s = (unsigned char *) SvPV(charstring, len);
730 unsigned char *e = s + len;
731 for (RETVAL = 1; RETVAL && s < e; s++)
743 unsigned char *s = (unsigned char *) SvPV(charstring, len);
744 unsigned char *e = s + len;
745 for (RETVAL = 1; RETVAL && s < e; s++)
757 unsigned char *s = (unsigned char *) SvPV(charstring, len);
758 unsigned char *e = s + len;
759 for (RETVAL = 1; RETVAL && s < e; s++)
771 unsigned char *s = (unsigned char *) SvPV(charstring, len);
772 unsigned char *e = s + len;
773 for (RETVAL = 1; RETVAL && s < e; s++)
785 unsigned char *s = (unsigned char *) SvPV(charstring, len);
786 unsigned char *e = s + len;
787 for (RETVAL = 1; RETVAL && s < e; s++)
799 unsigned char *s = (unsigned char *) SvPV(charstring, len);
800 unsigned char *e = s + len;
801 for (RETVAL = 1; RETVAL && s < e; s++)
813 unsigned char *s = (unsigned char *) SvPV(charstring, len);
814 unsigned char *e = s + len;
815 for (RETVAL = 1; RETVAL && s < e; s++)
827 unsigned char *s = (unsigned char *) SvPV(charstring, len);
828 unsigned char *e = s + len;
829 for (RETVAL = 1; RETVAL && s < e; s++)
841 unsigned char *s = (unsigned char *) SvPV(charstring, len);
842 unsigned char *e = s + len;
843 for (RETVAL = 1; RETVAL && s < e; s++)
855 unsigned char *s = (unsigned char *) SvPV(charstring, len);
856 unsigned char *e = s + len;
857 for (RETVAL = 1; RETVAL && s < e; s++)
869 unsigned char *s = (unsigned char *) SvPV(charstring, len);
870 unsigned char *e = s + len;
871 for (RETVAL = 1; RETVAL && s < e; s++)
878 open(filename, flags = O_RDONLY, mode = 0666)
883 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
884 TAINT_PROPER("open");
885 RETVAL = open(filename, flags, mode);
893 #ifdef HAS_LOCALECONV
896 sv_2mortal((SV*)RETVAL);
897 if ((lcbuf = localeconv())) {
899 if (lcbuf->decimal_point && *lcbuf->decimal_point)
900 hv_store(RETVAL, "decimal_point", 13,
901 newSVpv(lcbuf->decimal_point, 0), 0);
902 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
903 hv_store(RETVAL, "thousands_sep", 13,
904 newSVpv(lcbuf->thousands_sep, 0), 0);
905 #ifndef NO_LOCALECONV_GROUPING
906 if (lcbuf->grouping && *lcbuf->grouping)
907 hv_store(RETVAL, "grouping", 8,
908 newSVpv(lcbuf->grouping, 0), 0);
910 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
911 hv_store(RETVAL, "int_curr_symbol", 15,
912 newSVpv(lcbuf->int_curr_symbol, 0), 0);
913 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
914 hv_store(RETVAL, "currency_symbol", 15,
915 newSVpv(lcbuf->currency_symbol, 0), 0);
916 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
917 hv_store(RETVAL, "mon_decimal_point", 17,
918 newSVpv(lcbuf->mon_decimal_point, 0), 0);
919 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
920 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
921 hv_store(RETVAL, "mon_thousands_sep", 17,
922 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
924 #ifndef NO_LOCALECONV_MON_GROUPING
925 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
926 hv_store(RETVAL, "mon_grouping", 12,
927 newSVpv(lcbuf->mon_grouping, 0), 0);
929 if (lcbuf->positive_sign && *lcbuf->positive_sign)
930 hv_store(RETVAL, "positive_sign", 13,
931 newSVpv(lcbuf->positive_sign, 0), 0);
932 if (lcbuf->negative_sign && *lcbuf->negative_sign)
933 hv_store(RETVAL, "negative_sign", 13,
934 newSVpv(lcbuf->negative_sign, 0), 0);
936 if (lcbuf->int_frac_digits != CHAR_MAX)
937 hv_store(RETVAL, "int_frac_digits", 15,
938 newSViv(lcbuf->int_frac_digits), 0);
939 if (lcbuf->frac_digits != CHAR_MAX)
940 hv_store(RETVAL, "frac_digits", 11,
941 newSViv(lcbuf->frac_digits), 0);
942 if (lcbuf->p_cs_precedes != CHAR_MAX)
943 hv_store(RETVAL, "p_cs_precedes", 13,
944 newSViv(lcbuf->p_cs_precedes), 0);
945 if (lcbuf->p_sep_by_space != CHAR_MAX)
946 hv_store(RETVAL, "p_sep_by_space", 14,
947 newSViv(lcbuf->p_sep_by_space), 0);
948 if (lcbuf->n_cs_precedes != CHAR_MAX)
949 hv_store(RETVAL, "n_cs_precedes", 13,
950 newSViv(lcbuf->n_cs_precedes), 0);
951 if (lcbuf->n_sep_by_space != CHAR_MAX)
952 hv_store(RETVAL, "n_sep_by_space", 14,
953 newSViv(lcbuf->n_sep_by_space), 0);
954 if (lcbuf->p_sign_posn != CHAR_MAX)
955 hv_store(RETVAL, "p_sign_posn", 11,
956 newSViv(lcbuf->p_sign_posn), 0);
957 if (lcbuf->n_sign_posn != CHAR_MAX)
958 hv_store(RETVAL, "n_sign_posn", 11,
959 newSViv(lcbuf->n_sign_posn), 0);
962 localeconv(); /* A stub to call not_here(). */
968 setlocale(category, locale = 0)
974 retval = setlocale(category, locale);
976 /* Save retval since subsequent setlocale() calls
977 * may overwrite it. */
978 RETVAL = savepv(retval);
979 #ifdef USE_LOCALE_CTYPE
980 if (category == LC_CTYPE
982 || category == LC_ALL
988 if (category == LC_ALL)
989 newctype = setlocale(LC_CTYPE, NULL);
995 #endif /* USE_LOCALE_CTYPE */
996 #ifdef USE_LOCALE_COLLATE
997 if (category == LC_COLLATE
999 || category == LC_ALL
1005 if (category == LC_ALL)
1006 newcoll = setlocale(LC_COLLATE, NULL);
1010 new_collate(newcoll);
1012 #endif /* USE_LOCALE_COLLATE */
1013 #ifdef USE_LOCALE_NUMERIC
1014 if (category == LC_NUMERIC
1016 || category == LC_ALL
1022 if (category == LC_ALL)
1023 newnum = setlocale(LC_NUMERIC, NULL);
1027 new_numeric(newnum);
1029 #endif /* USE_LOCALE_NUMERIC */
1073 /* (We already know stack is long enough.) */
1074 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1075 PUSHs(sv_2mortal(newSViv(expvar)));
1091 /* (We already know stack is long enough.) */
1092 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1093 PUSHs(sv_2mortal(newSVnv(intvar)));
1108 sigaction(sig, optaction, oldaction = 0)
1111 POSIX::SigAction oldaction
1113 #if defined(WIN32) || defined(NETWARE)
1114 RETVAL = not_here("sigaction");
1116 # This code is really grody because we're trying to make the signal
1117 # interface look beautiful, which is hard.
1121 POSIX__SigAction action;
1122 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1123 struct sigaction act;
1124 struct sigaction oact;
1128 POSIX__SigSet sigset;
1133 croak("Negative signals are not allowed");
1136 if (sig == 0 && SvPOK(ST(0))) {
1137 const char *s = SvPVX_const(ST(0));
1138 int i = whichsig(s);
1140 if (i < 0 && memEQ(s, "SIG", 3))
1141 i = whichsig(s + 3);
1143 if (ckWARN(WARN_SIGNAL))
1144 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1145 "No such signal: SIG%s", s);
1152 if (sig > NSIG) { /* NSIG - 1 is still okay. */
1153 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1154 "No such signal: %d", sig);
1158 sigsvp = hv_fetch(GvHVn(siggv),
1160 strlen(PL_sig_name[sig]),
1163 /* Check optaction and set action */
1164 if(SvTRUE(optaction)) {
1165 if(sv_isa(optaction, "POSIX::SigAction"))
1166 action = (HV*)SvRV(optaction);
1168 croak("action is not of type POSIX::SigAction");
1174 /* sigaction() is supposed to look atomic. In particular, any
1175 * signal handler invoked during a sigaction() call should
1176 * see either the old or the new disposition, and not something
1177 * in between. We use sigprocmask() to make it so.
1180 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1184 /* Restore signal mask no matter how we exit this block. */
1185 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1186 SAVEFREESV( osset_sv );
1187 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1189 RETVAL=-1; /* In case both oldaction and action are 0. */
1191 /* Remember old disposition if desired. */
1193 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
1195 croak("Can't supply an oldaction without a HANDLER");
1196 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1197 sv_setsv(*svp, *sigsvp);
1200 sv_setpv(*svp, "DEFAULT");
1202 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1205 /* Get back the mask. */
1206 svp = hv_fetchs(oldaction, "MASK", TRUE);
1207 if (sv_isa(*svp, "POSIX::SigSet")) {
1208 IV tmp = SvIV((SV*)SvRV(*svp));
1209 sigset = INT2PTR(sigset_t*, tmp);
1212 Newx(sigset, 1, sigset_t);
1213 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1215 *sigset = oact.sa_mask;
1217 /* Get back the flags. */
1218 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
1219 sv_setiv(*svp, oact.sa_flags);
1221 /* Get back whether the old handler used safe signals. */
1222 svp = hv_fetchs(oldaction, "SAFE", TRUE);
1224 /* compare incompatible pointers by casting to integer */
1225 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
1229 /* Safe signals use "csighandler", which vectors through the
1230 PL_sighandlerp pointer when it's safe to do so.
1231 (BTW, "csighandler" is very different from "sighandler".) */
1232 svp = hv_fetchs(action, "SAFE", FALSE);
1236 (*svp && SvTRUE(*svp))
1237 ? PL_csighandlerp : PL_sighandlerp
1240 /* Vector new Perl handler through %SIG.
1241 (The core signal handlers read %SIG to dispatch.) */
1242 svp = hv_fetchs(action, "HANDLER", FALSE);
1244 croak("Can't supply an action without a HANDLER");
1245 sv_setsv(*sigsvp, *svp);
1247 /* This call actually calls sigaction() with almost the
1248 right settings, including appropriate interpretation
1249 of DEFAULT and IGNORE. However, why are we doing
1250 this when we're about to do it again just below? XXX */
1253 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1255 const char *s=SvPVX_const(*svp);
1256 if(strEQ(s,"IGNORE")) {
1257 act.sa_handler = SIG_IGN;
1259 else if(strEQ(s,"DEFAULT")) {
1260 act.sa_handler = SIG_DFL;
1264 /* Set up any desired mask. */
1265 svp = hv_fetchs(action, "MASK", FALSE);
1266 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1267 IV tmp = SvIV((SV*)SvRV(*svp));
1268 sigset = INT2PTR(sigset_t*, tmp);
1269 act.sa_mask = *sigset;
1272 sigemptyset(& act.sa_mask);
1274 /* Set up any desired flags. */
1275 svp = hv_fetchs(action, "FLAGS", FALSE);
1276 act.sa_flags = svp ? SvIV(*svp) : 0;
1278 /* Don't worry about cleaning up *sigsvp if this fails,
1279 * because that means we tried to disposition a
1280 * nonblockable signal, in which case *sigsvp is
1281 * essentially meaningless anyway.
1283 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1296 POSIX::SigSet sigset
1299 sigprocmask(how, sigset, oldsigset = 0)
1301 POSIX::SigSet sigset = NO_INIT
1302 POSIX::SigSet oldsigset = NO_INIT
1304 if (! SvOK(ST(1))) {
1306 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
1307 IV tmp = SvIV((SV*)SvRV(ST(1)));
1308 sigset = INT2PTR(POSIX__SigSet,tmp);
1310 croak("sigset is not of type POSIX::SigSet");
1313 if (items < 3 || ! SvOK(ST(2))) {
1315 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
1316 IV tmp = SvIV((SV*)SvRV(ST(2)));
1317 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1319 croak("oldsigset is not of type POSIX::SigSet");
1323 sigsuspend(signal_mask)
1324 POSIX::SigSet signal_mask
1344 lseek(fd, offset, whence)
1349 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1350 RETVAL = sizeof(Off_t) > sizeof(IV)
1351 ? newSVnv((NV)pos) : newSViv((IV)pos);
1360 if ((incr = nice(incr)) != -1 || errno == 0) {
1362 XPUSHs(sv_2mortal(newSVpvn("0 but true", 10)));
1364 XPUSHs(sv_2mortal(newSViv(incr)));
1371 if (pipe(fds) != -1) {
1373 PUSHs(sv_2mortal(newSViv(fds[0])));
1374 PUSHs(sv_2mortal(newSViv(fds[1])));
1378 read(fd, buffer, nbytes)
1380 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1384 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1387 SvCUR_set(sv_buffer, RETVAL);
1388 SvPOK_only(sv_buffer);
1389 *SvEND(sv_buffer) = '\0';
1390 SvTAINTED_on(sv_buffer);
1406 tcsetpgrp(fd, pgrp_id)
1415 if (uname(&buf) >= 0) {
1417 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1418 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1419 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1420 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1421 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1424 uname((char *) 0); /* A stub to call not_here(). */
1428 write(fd, buffer, nbytes)
1439 RETVAL = newSVpvn("", 0);
1440 SvGROW(RETVAL, L_tmpnam);
1441 len = strlen(tmpnam(SvPV(RETVAL, i)));
1442 SvCUR_set(RETVAL, len);
1455 mbstowcs(s, pwcs, n)
1467 wcstombs(s, pwcs, n)
1489 SET_NUMERIC_LOCAL();
1490 num = strtod(str, &unparsed);
1491 PUSHs(sv_2mortal(newSVnv(num)));
1492 if (GIMME == G_ARRAY) {
1495 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1497 PUSHs(&PL_sv_undef);
1501 strtol(str, base = 0)
1508 num = strtol(str, &unparsed, base);
1509 #if IVSIZE <= LONGSIZE
1510 if (num < IV_MIN || num > IV_MAX)
1511 PUSHs(sv_2mortal(newSVnv((double)num)));
1514 PUSHs(sv_2mortal(newSViv((IV)num)));
1515 if (GIMME == G_ARRAY) {
1518 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1520 PUSHs(&PL_sv_undef);
1524 strtoul(str, base = 0)
1531 num = strtoul(str, &unparsed, base);
1532 #if IVSIZE <= LONGSIZE
1534 PUSHs(sv_2mortal(newSVnv((double)num)));
1537 PUSHs(sv_2mortal(newSViv((IV)num)));
1538 if (GIMME == G_ARRAY) {
1541 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1543 PUSHs(&PL_sv_undef);
1553 char *p = SvPV(src,srclen);
1555 ST(0) = sv_2mortal(newSV(srclen*4+1));
1556 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1557 if (dstlen > srclen) {
1559 SvGROW(ST(0), dstlen);
1560 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1563 SvCUR_set(ST(0), dstlen);
1568 mkfifo(filename, mode)
1572 TAINT_PROPER("mkfifo");
1573 RETVAL = mkfifo(filename, mode);
1589 tcflush(fd, queue_selector)
1594 tcsendbreak(fd, duration)
1599 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1612 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1615 mytm.tm_hour = hour;
1616 mytm.tm_mday = mday;
1618 mytm.tm_year = year;
1619 mytm.tm_wday = wday;
1620 mytm.tm_yday = yday;
1621 mytm.tm_isdst = isdst;
1622 RETVAL = asctime(&mytm);
1639 realtime = times( &tms );
1641 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1642 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1643 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1644 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1645 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1648 difftime(time1, time2)
1653 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1666 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1669 mytm.tm_hour = hour;
1670 mytm.tm_mday = mday;
1672 mytm.tm_year = year;
1673 mytm.tm_wday = wday;
1674 mytm.tm_yday = yday;
1675 mytm.tm_isdst = isdst;
1676 RETVAL = (SysRetLong) mktime(&mytm);
1681 #XXX: if $xsubpp::WantOptimize is always the default
1682 # sv_setpv(TARG, ...) could be used rather than
1683 # ST(0) = sv_2mortal(newSVpv(...))
1685 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1698 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1700 ST(0) = sv_2mortal(newSVpv(buf, 0));
1712 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1713 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1716 access(filename, mode)
1724 #ifdef HAS_CTERMID_R
1725 s = (char *) safemalloc((size_t) L_ctermid);
1727 RETVAL = ctermid(s);
1731 #ifdef HAS_CTERMID_R
1745 pathconf(filename, name)
1759 PL_egid = getegid();
1770 PL_euid = geteuid();
1788 XSprePUSH; PUSHTARG;
1792 lchown(uid, gid, path)
1798 /* yes, the order of arguments is different,
1799 * but consistent with CORE::chown() */
1800 RETVAL = lchown(path, uid, gid);
1802 RETVAL = not_here("lchown");