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 */
383 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
385 # define WMUNGE(x) (x)
389 not_here(const char *s)
391 croak("POSIX::%s not implemented on this architecture", s);
395 #include "const-c.inc"
398 restore_sigmask(pTHX_ SV *osset_sv)
400 /* Fortunately, restoring the signal mask can't fail, because
401 * there's nothing we can do about it if it does -- we're not
402 * supposed to return -1 from sigaction unless the disposition
405 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
406 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
409 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
412 new(packname = "POSIX::SigSet", ...)
413 const char * packname
417 Newx(RETVAL, 1, sigset_t);
419 for (i = 1; i < items; i++)
420 sigaddset(RETVAL, SvIV(ST(i)));
432 sigaddset(sigset, sig)
437 sigdelset(sigset, sig)
450 sigismember(sigset, sig)
454 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
457 new(packname = "POSIX::Termios", ...)
458 const char * packname
462 Newx(RETVAL, 1, struct termios);
473 POSIX::Termios termios_ref
476 Safefree(termios_ref);
482 getattr(termios_ref, fd = 0)
483 POSIX::Termios termios_ref
486 RETVAL = tcgetattr(fd, termios_ref);
491 setattr(termios_ref, fd = 0, optional_actions = 0)
492 POSIX::Termios termios_ref
496 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
501 cfgetispeed(termios_ref)
502 POSIX::Termios termios_ref
505 cfgetospeed(termios_ref)
506 POSIX::Termios termios_ref
509 getiflag(termios_ref)
510 POSIX::Termios termios_ref
512 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
513 RETVAL = termios_ref->c_iflag;
515 not_here("getiflag");
522 getoflag(termios_ref)
523 POSIX::Termios termios_ref
525 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
526 RETVAL = termios_ref->c_oflag;
528 not_here("getoflag");
535 getcflag(termios_ref)
536 POSIX::Termios termios_ref
538 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
539 RETVAL = termios_ref->c_cflag;
541 not_here("getcflag");
548 getlflag(termios_ref)
549 POSIX::Termios termios_ref
551 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
552 RETVAL = termios_ref->c_lflag;
554 not_here("getlflag");
561 getcc(termios_ref, ccix)
562 POSIX::Termios termios_ref
565 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
567 croak("Bad getcc subscript");
568 RETVAL = termios_ref->c_cc[ccix];
577 cfsetispeed(termios_ref, speed)
578 POSIX::Termios termios_ref
582 cfsetospeed(termios_ref, speed)
583 POSIX::Termios termios_ref
587 setiflag(termios_ref, iflag)
588 POSIX::Termios termios_ref
591 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
592 termios_ref->c_iflag = iflag;
594 not_here("setiflag");
598 setoflag(termios_ref, oflag)
599 POSIX::Termios termios_ref
602 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
603 termios_ref->c_oflag = oflag;
605 not_here("setoflag");
609 setcflag(termios_ref, cflag)
610 POSIX::Termios termios_ref
613 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
614 termios_ref->c_cflag = cflag;
616 not_here("setcflag");
620 setlflag(termios_ref, lflag)
621 POSIX::Termios termios_ref
624 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
625 termios_ref->c_lflag = lflag;
627 not_here("setlflag");
631 setcc(termios_ref, ccix, cc)
632 POSIX::Termios termios_ref
636 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
638 croak("Bad setcc subscript");
639 termios_ref->c_cc[ccix] = cc;
645 MODULE = POSIX PACKAGE = POSIX
647 INCLUDE: const-xs.inc
654 POSIX::WIFSIGNALED = 2
655 POSIX::WIFSTOPPED = 3
659 #if !(defined(WEXITSTATUS) || defined(WIFEXITED) || defined(WIFSIGNALED) \
660 || defined(WIFSTOPPED) || defined(WSTOPSIG) || defined (WTERMSIG))
661 RETVAL = 0; /* Silence compilers that notice this, but don't realise
662 that not_here() can't return. */
667 RETVAL = WEXITSTATUS(status);
669 not_here("WEXITSTATUS");
674 RETVAL = WIFEXITED(status);
676 not_here("WIFEXITED");
681 RETVAL = WIFSIGNALED(status);
683 not_here("WIFSIGNALED");
688 RETVAL = WIFSTOPPED(status);
690 not_here("WIFSTOPPED");
695 RETVAL = WSTOPSIG(status);
697 not_here("WSTOPSIG");
702 RETVAL = WTERMSIG(status);
704 not_here("WTERMSIG");
708 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", ix);
719 unsigned char *s = (unsigned char *) SvPV(charstring, len);
720 unsigned char *e = s + len;
721 for (RETVAL = 1; RETVAL && s < e; s++)
733 unsigned char *s = (unsigned char *) SvPV(charstring, len);
734 unsigned char *e = s + len;
735 for (RETVAL = 1; RETVAL && s < e; s++)
747 unsigned char *s = (unsigned char *) SvPV(charstring, len);
748 unsigned char *e = s + len;
749 for (RETVAL = 1; RETVAL && s < e; s++)
761 unsigned char *s = (unsigned char *) SvPV(charstring, len);
762 unsigned char *e = s + len;
763 for (RETVAL = 1; RETVAL && s < e; s++)
775 unsigned char *s = (unsigned char *) SvPV(charstring, len);
776 unsigned char *e = s + len;
777 for (RETVAL = 1; RETVAL && s < e; s++)
789 unsigned char *s = (unsigned char *) SvPV(charstring, len);
790 unsigned char *e = s + len;
791 for (RETVAL = 1; RETVAL && s < e; s++)
803 unsigned char *s = (unsigned char *) SvPV(charstring, len);
804 unsigned char *e = s + len;
805 for (RETVAL = 1; RETVAL && s < e; s++)
817 unsigned char *s = (unsigned char *) SvPV(charstring, len);
818 unsigned char *e = s + len;
819 for (RETVAL = 1; RETVAL && s < e; s++)
831 unsigned char *s = (unsigned char *) SvPV(charstring, len);
832 unsigned char *e = s + len;
833 for (RETVAL = 1; RETVAL && s < e; s++)
845 unsigned char *s = (unsigned char *) SvPV(charstring, len);
846 unsigned char *e = s + len;
847 for (RETVAL = 1; RETVAL && s < e; s++)
859 unsigned char *s = (unsigned char *) SvPV(charstring, len);
860 unsigned char *e = s + len;
861 for (RETVAL = 1; RETVAL && s < e; s++)
868 open(filename, flags = O_RDONLY, mode = 0666)
873 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
874 TAINT_PROPER("open");
875 RETVAL = open(filename, flags, mode);
883 #ifdef HAS_LOCALECONV
886 sv_2mortal((SV*)RETVAL);
887 if ((lcbuf = localeconv())) {
889 if (lcbuf->decimal_point && *lcbuf->decimal_point)
890 hv_store(RETVAL, "decimal_point", 13,
891 newSVpv(lcbuf->decimal_point, 0), 0);
892 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
893 hv_store(RETVAL, "thousands_sep", 13,
894 newSVpv(lcbuf->thousands_sep, 0), 0);
895 #ifndef NO_LOCALECONV_GROUPING
896 if (lcbuf->grouping && *lcbuf->grouping)
897 hv_store(RETVAL, "grouping", 8,
898 newSVpv(lcbuf->grouping, 0), 0);
900 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
901 hv_store(RETVAL, "int_curr_symbol", 15,
902 newSVpv(lcbuf->int_curr_symbol, 0), 0);
903 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
904 hv_store(RETVAL, "currency_symbol", 15,
905 newSVpv(lcbuf->currency_symbol, 0), 0);
906 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
907 hv_store(RETVAL, "mon_decimal_point", 17,
908 newSVpv(lcbuf->mon_decimal_point, 0), 0);
909 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
910 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
911 hv_store(RETVAL, "mon_thousands_sep", 17,
912 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
914 #ifndef NO_LOCALECONV_MON_GROUPING
915 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
916 hv_store(RETVAL, "mon_grouping", 12,
917 newSVpv(lcbuf->mon_grouping, 0), 0);
919 if (lcbuf->positive_sign && *lcbuf->positive_sign)
920 hv_store(RETVAL, "positive_sign", 13,
921 newSVpv(lcbuf->positive_sign, 0), 0);
922 if (lcbuf->negative_sign && *lcbuf->negative_sign)
923 hv_store(RETVAL, "negative_sign", 13,
924 newSVpv(lcbuf->negative_sign, 0), 0);
926 if (lcbuf->int_frac_digits != CHAR_MAX)
927 hv_store(RETVAL, "int_frac_digits", 15,
928 newSViv(lcbuf->int_frac_digits), 0);
929 if (lcbuf->frac_digits != CHAR_MAX)
930 hv_store(RETVAL, "frac_digits", 11,
931 newSViv(lcbuf->frac_digits), 0);
932 if (lcbuf->p_cs_precedes != CHAR_MAX)
933 hv_store(RETVAL, "p_cs_precedes", 13,
934 newSViv(lcbuf->p_cs_precedes), 0);
935 if (lcbuf->p_sep_by_space != CHAR_MAX)
936 hv_store(RETVAL, "p_sep_by_space", 14,
937 newSViv(lcbuf->p_sep_by_space), 0);
938 if (lcbuf->n_cs_precedes != CHAR_MAX)
939 hv_store(RETVAL, "n_cs_precedes", 13,
940 newSViv(lcbuf->n_cs_precedes), 0);
941 if (lcbuf->n_sep_by_space != CHAR_MAX)
942 hv_store(RETVAL, "n_sep_by_space", 14,
943 newSViv(lcbuf->n_sep_by_space), 0);
944 if (lcbuf->p_sign_posn != CHAR_MAX)
945 hv_store(RETVAL, "p_sign_posn", 11,
946 newSViv(lcbuf->p_sign_posn), 0);
947 if (lcbuf->n_sign_posn != CHAR_MAX)
948 hv_store(RETVAL, "n_sign_posn", 11,
949 newSViv(lcbuf->n_sign_posn), 0);
952 localeconv(); /* A stub to call not_here(). */
958 setlocale(category, locale = 0)
964 retval = setlocale(category, locale);
966 /* Save retval since subsequent setlocale() calls
967 * may overwrite it. */
968 RETVAL = savepv(retval);
969 #ifdef USE_LOCALE_CTYPE
970 if (category == LC_CTYPE
972 || category == LC_ALL
978 if (category == LC_ALL)
979 newctype = setlocale(LC_CTYPE, NULL);
985 #endif /* USE_LOCALE_CTYPE */
986 #ifdef USE_LOCALE_COLLATE
987 if (category == LC_COLLATE
989 || category == LC_ALL
995 if (category == LC_ALL)
996 newcoll = setlocale(LC_COLLATE, NULL);
1000 new_collate(newcoll);
1002 #endif /* USE_LOCALE_COLLATE */
1003 #ifdef USE_LOCALE_NUMERIC
1004 if (category == LC_NUMERIC
1006 || category == LC_ALL
1012 if (category == LC_ALL)
1013 newnum = setlocale(LC_NUMERIC, NULL);
1017 new_numeric(newnum);
1019 #endif /* USE_LOCALE_NUMERIC */
1063 /* (We already know stack is long enough.) */
1064 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1065 PUSHs(sv_2mortal(newSViv(expvar)));
1081 /* (We already know stack is long enough.) */
1082 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1083 PUSHs(sv_2mortal(newSVnv(intvar)));
1098 sigaction(sig, optaction, oldaction = 0)
1101 POSIX::SigAction oldaction
1103 #if defined(WIN32) || defined(NETWARE)
1104 RETVAL = not_here("sigaction");
1106 # This code is really grody because we're trying to make the signal
1107 # interface look beautiful, which is hard.
1111 POSIX__SigAction action;
1112 GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
1113 struct sigaction act;
1114 struct sigaction oact;
1118 POSIX__SigSet sigset;
1123 croak("Negative signals are not allowed");
1126 if (sig == 0 && SvPOK(ST(0))) {
1127 const char *s = SvPVX_const(ST(0));
1128 int i = whichsig(s);
1130 if (i < 0 && memEQ(s, "SIG", 3))
1131 i = whichsig(s + 3);
1133 if (ckWARN(WARN_SIGNAL))
1134 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1135 "No such signal: SIG%s", s);
1142 if (sig > NSIG) { /* NSIG - 1 is still okay. */
1143 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1144 "No such signal: %d", sig);
1148 sigsvp = hv_fetch(GvHVn(siggv),
1150 strlen(PL_sig_name[sig]),
1153 /* Check optaction and set action */
1154 if(SvTRUE(optaction)) {
1155 if(sv_isa(optaction, "POSIX::SigAction"))
1156 action = (HV*)SvRV(optaction);
1158 croak("action is not of type POSIX::SigAction");
1164 /* sigaction() is supposed to look atomic. In particular, any
1165 * signal handler invoked during a sigaction() call should
1166 * see either the old or the new disposition, and not something
1167 * in between. We use sigprocmask() to make it so.
1170 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1174 /* Restore signal mask no matter how we exit this block. */
1175 osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
1176 SAVEFREESV( osset_sv );
1177 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1179 RETVAL=-1; /* In case both oldaction and action are 0. */
1181 /* Remember old disposition if desired. */
1183 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
1185 croak("Can't supply an oldaction without a HANDLER");
1186 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1187 sv_setsv(*svp, *sigsvp);
1190 sv_setpv(*svp, "DEFAULT");
1192 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1195 /* Get back the mask. */
1196 svp = hv_fetchs(oldaction, "MASK", TRUE);
1197 if (sv_isa(*svp, "POSIX::SigSet")) {
1198 IV tmp = SvIV((SV*)SvRV(*svp));
1199 sigset = INT2PTR(sigset_t*, tmp);
1202 Newx(sigset, 1, sigset_t);
1203 sv_setptrobj(*svp, sigset, "POSIX::SigSet");
1205 *sigset = oact.sa_mask;
1207 /* Get back the flags. */
1208 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
1209 sv_setiv(*svp, oact.sa_flags);
1211 /* Get back whether the old handler used safe signals. */
1212 svp = hv_fetchs(oldaction, "SAFE", TRUE);
1214 /* compare incompatible pointers by casting to integer */
1215 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
1219 /* Safe signals use "csighandler", which vectors through the
1220 PL_sighandlerp pointer when it's safe to do so.
1221 (BTW, "csighandler" is very different from "sighandler".) */
1222 svp = hv_fetchs(action, "SAFE", FALSE);
1226 (*svp && SvTRUE(*svp))
1227 ? PL_csighandlerp : PL_sighandlerp
1230 /* Vector new Perl handler through %SIG.
1231 (The core signal handlers read %SIG to dispatch.) */
1232 svp = hv_fetchs(action, "HANDLER", FALSE);
1234 croak("Can't supply an action without a HANDLER");
1235 sv_setsv(*sigsvp, *svp);
1237 /* This call actually calls sigaction() with almost the
1238 right settings, including appropriate interpretation
1239 of DEFAULT and IGNORE. However, why are we doing
1240 this when we're about to do it again just below? XXX */
1243 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1245 const char *s=SvPVX_const(*svp);
1246 if(strEQ(s,"IGNORE")) {
1247 act.sa_handler = SIG_IGN;
1249 else if(strEQ(s,"DEFAULT")) {
1250 act.sa_handler = SIG_DFL;
1254 /* Set up any desired mask. */
1255 svp = hv_fetchs(action, "MASK", FALSE);
1256 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1257 IV tmp = SvIV((SV*)SvRV(*svp));
1258 sigset = INT2PTR(sigset_t*, tmp);
1259 act.sa_mask = *sigset;
1262 sigemptyset(& act.sa_mask);
1264 /* Set up any desired flags. */
1265 svp = hv_fetchs(action, "FLAGS", FALSE);
1266 act.sa_flags = svp ? SvIV(*svp) : 0;
1268 /* Don't worry about cleaning up *sigsvp if this fails,
1269 * because that means we tried to disposition a
1270 * nonblockable signal, in which case *sigsvp is
1271 * essentially meaningless anyway.
1273 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1286 POSIX::SigSet sigset
1289 sigprocmask(how, sigset, oldsigset = 0)
1291 POSIX::SigSet sigset = NO_INIT
1292 POSIX::SigSet oldsigset = NO_INIT
1294 if (! SvOK(ST(1))) {
1296 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
1297 IV tmp = SvIV((SV*)SvRV(ST(1)));
1298 sigset = INT2PTR(POSIX__SigSet,tmp);
1300 croak("sigset is not of type POSIX::SigSet");
1303 if (items < 3 || ! SvOK(ST(2))) {
1305 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
1306 IV tmp = SvIV((SV*)SvRV(ST(2)));
1307 oldsigset = INT2PTR(POSIX__SigSet,tmp);
1309 croak("oldsigset is not of type POSIX::SigSet");
1313 sigsuspend(signal_mask)
1314 POSIX::SigSet signal_mask
1334 lseek(fd, offset, whence)
1339 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1340 RETVAL = sizeof(Off_t) > sizeof(IV)
1341 ? newSVnv((NV)pos) : newSViv((IV)pos);
1350 if ((incr = nice(incr)) != -1 || errno == 0) {
1352 XPUSHs(sv_2mortal(newSVpvn("0 but true", 10)));
1354 XPUSHs(sv_2mortal(newSViv(incr)));
1361 if (pipe(fds) != -1) {
1363 PUSHs(sv_2mortal(newSViv(fds[0])));
1364 PUSHs(sv_2mortal(newSViv(fds[1])));
1368 read(fd, buffer, nbytes)
1370 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1374 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1377 SvCUR_set(sv_buffer, RETVAL);
1378 SvPOK_only(sv_buffer);
1379 *SvEND(sv_buffer) = '\0';
1380 SvTAINTED_on(sv_buffer);
1396 tcsetpgrp(fd, pgrp_id)
1405 if (uname(&buf) >= 0) {
1407 PUSHs(sv_2mortal(newSVpv(buf.sysname, 0)));
1408 PUSHs(sv_2mortal(newSVpv(buf.nodename, 0)));
1409 PUSHs(sv_2mortal(newSVpv(buf.release, 0)));
1410 PUSHs(sv_2mortal(newSVpv(buf.version, 0)));
1411 PUSHs(sv_2mortal(newSVpv(buf.machine, 0)));
1414 uname((char *) 0); /* A stub to call not_here(). */
1418 write(fd, buffer, nbytes)
1429 RETVAL = newSVpvn("", 0);
1430 SvGROW(RETVAL, L_tmpnam);
1431 len = strlen(tmpnam(SvPV(RETVAL, i)));
1432 SvCUR_set(RETVAL, len);
1445 mbstowcs(s, pwcs, n)
1457 wcstombs(s, pwcs, n)
1479 SET_NUMERIC_LOCAL();
1480 num = strtod(str, &unparsed);
1481 PUSHs(sv_2mortal(newSVnv(num)));
1482 if (GIMME == G_ARRAY) {
1485 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1487 PUSHs(&PL_sv_undef);
1491 strtol(str, base = 0)
1498 num = strtol(str, &unparsed, base);
1499 #if IVSIZE <= LONGSIZE
1500 if (num < IV_MIN || num > IV_MAX)
1501 PUSHs(sv_2mortal(newSVnv((double)num)));
1504 PUSHs(sv_2mortal(newSViv((IV)num)));
1505 if (GIMME == G_ARRAY) {
1508 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1510 PUSHs(&PL_sv_undef);
1514 strtoul(str, base = 0)
1521 num = strtoul(str, &unparsed, base);
1522 #if IVSIZE <= LONGSIZE
1524 PUSHs(sv_2mortal(newSVnv((double)num)));
1527 PUSHs(sv_2mortal(newSViv((IV)num)));
1528 if (GIMME == G_ARRAY) {
1531 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1533 PUSHs(&PL_sv_undef);
1543 char *p = SvPV(src,srclen);
1545 ST(0) = sv_2mortal(newSV(srclen*4+1));
1546 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1547 if (dstlen > srclen) {
1549 SvGROW(ST(0), dstlen);
1550 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1553 SvCUR_set(ST(0), dstlen);
1558 mkfifo(filename, mode)
1562 TAINT_PROPER("mkfifo");
1563 RETVAL = mkfifo(filename, mode);
1579 tcflush(fd, queue_selector)
1584 tcsendbreak(fd, duration)
1589 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1602 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1605 mytm.tm_hour = hour;
1606 mytm.tm_mday = mday;
1608 mytm.tm_year = year;
1609 mytm.tm_wday = wday;
1610 mytm.tm_yday = yday;
1611 mytm.tm_isdst = isdst;
1612 RETVAL = asctime(&mytm);
1629 realtime = times( &tms );
1631 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1632 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1633 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1634 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1635 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1638 difftime(time1, time2)
1643 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1656 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1659 mytm.tm_hour = hour;
1660 mytm.tm_mday = mday;
1662 mytm.tm_year = year;
1663 mytm.tm_wday = wday;
1664 mytm.tm_yday = yday;
1665 mytm.tm_isdst = isdst;
1666 RETVAL = (SysRetLong) mktime(&mytm);
1671 #XXX: if $xsubpp::WantOptimize is always the default
1672 # sv_setpv(TARG, ...) could be used rather than
1673 # ST(0) = sv_2mortal(newSVpv(...))
1675 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1688 char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst);
1690 ST(0) = sv_2mortal(newSVpv(buf, 0));
1702 PUSHs(sv_2mortal(newSVpvn(tzname[0],strlen(tzname[0]))));
1703 PUSHs(sv_2mortal(newSVpvn(tzname[1],strlen(tzname[1]))));
1706 access(filename, mode)
1714 #ifdef HAS_CTERMID_R
1715 s = (char *) safemalloc((size_t) L_ctermid);
1717 RETVAL = ctermid(s);
1721 #ifdef HAS_CTERMID_R
1735 pathconf(filename, name)
1749 PL_egid = getegid();
1760 PL_euid = geteuid();
1778 XSprePUSH; PUSHTARG;
1782 lchown(uid, gid, path)
1788 /* yes, the order of arguments is different,
1789 * but consistent with CORE::chown() */
1790 RETVAL = lchown(path, uid, gid);
1792 RETVAL = not_here("lchown");