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 #if defined(__VMS) && !defined(__POSIX_SOURCE)
86 # include <libdef.h> /* LIB$_INVARG constant */
87 # include <lib$routines.h> /* prototype for lib$ediv() */
88 # include <starlet.h> /* prototype for sys$gettim() */
89 # if DECC_VERSION < 50000000
90 # define pid_t int /* old versions of DECC miss this in types.h */
94 # define mkfifo(a,b) (not_here("mkfifo"),-1)
95 # define tzset() not_here("tzset")
97 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
98 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
100 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
102 /* The POSIX notion of ttyname() is better served by getname() under VMS */
103 static char ttnambuf[64];
104 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
106 /* The non-POSIX CRTL times() has void return type, so we just get the
107 current time directly */
108 clock_t vms_times(struct tms *bufptr) {
111 /* Get wall time and convert to 10 ms intervals to
112 * produce the return value that the POSIX standard expects */
113 # if defined(__DECC) && defined (__ALPHA)
116 _ckvmssts(sys$gettim(&vmstime));
118 retval = vmstime & 0x7fffffff;
120 /* (Older hw or ccs don't have an atomic 64-bit type, so we
121 * juggle 32-bit ints (and a float) to produce a time_t result
122 * with minimal loss of information.) */
123 long int vmstime[2],remainder,divisor = 100000;
124 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
125 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
126 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
128 /* Fill in the struct tms using the CRTL routine . . .*/
129 times((tbuffer_t *)bufptr);
130 return (clock_t) retval;
132 # define times(t) vms_times(t)
134 #if defined (__CYGWIN__)
135 # define tzname _tzname
137 #if defined (WIN32) || defined (NETWARE)
139 # define mkfifo(a,b) not_here("mkfifo")
140 # define ttyname(a) (char*)not_here("ttyname")
141 # define sigset_t long
144 # define mode_t short
147 # define mode_t short
149 # define tzset() not_here("tzset")
151 # ifndef _POSIX_OPEN_MAX
152 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
155 # define sigaction(a,b,c) not_here("sigaction")
156 # define sigpending(a) not_here("sigpending")
157 # define sigprocmask(a,b,c) not_here("sigprocmask")
158 # define sigsuspend(a) not_here("sigsuspend")
159 # define sigemptyset(a) not_here("sigemptyset")
160 # define sigaddset(a,b) not_here("sigaddset")
161 # define sigdelset(a,b) not_here("sigdelset")
162 # define sigfillset(a) not_here("sigfillset")
163 # define sigismember(a,b) not_here("sigismember")
167 # define setuid(a) not_here("setuid")
168 # define setgid(a) not_here("setgid")
174 # define mkfifo(a,b) not_here("mkfifo")
175 # else /* !( defined OS2 ) */
177 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
180 # endif /* !HAS_MKFIFO */
185 # include <sys/times.h>
187 # include <sys/utsname.h>
189 # include <sys/wait.h>
193 #endif /* WIN32 || NETWARE */
197 /* Perl on Windows assigns WSAGetLastError() return values to errno
198 * (in win32/win32sck.c). Therefore we need to map these values
199 * back to standard symbolic names, but only for those names having
200 * no existing value or an existing value >= 100. (VC++ 2010 defines
201 * a group of names with values >= 100 in its errno.h which we *do*
202 * need to redefine.) The Errno.pm module does a similar mapping.
207 # define EWOULDBLOCK WSAEWOULDBLOCK
211 # define EINPROGRESS WSAEINPROGRESS
215 # define EALREADY WSAEALREADY
219 # define ENOTSOCK WSAENOTSOCK
223 # define EDESTADDRREQ WSAEDESTADDRREQ
227 # define EMSGSIZE WSAEMSGSIZE
231 # define EPROTOTYPE WSAEPROTOTYPE
235 # define ENOPROTOOPT WSAENOPROTOOPT
236 # ifdef EPROTONOSUPPORT
237 # undef EPROTONOSUPPORT
239 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
240 # ifdef ESOCKTNOSUPPORT
241 # undef ESOCKTNOSUPPORT
243 # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
247 # define EOPNOTSUPP WSAEOPNOTSUPP
251 # define EPFNOSUPPORT WSAEPFNOSUPPORT
255 # define EAFNOSUPPORT WSAEAFNOSUPPORT
259 # define EADDRINUSE WSAEADDRINUSE
260 # ifdef EADDRNOTAVAIL
261 # undef EADDRNOTAVAIL
263 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
267 # define ENETDOWN WSAENETDOWN
271 # define ENETUNREACH WSAENETUNREACH
275 # define ENETRESET WSAENETRESET
279 # define ECONNABORTED WSAECONNABORTED
283 # define ECONNRESET WSAECONNRESET
287 # define ENOBUFS WSAENOBUFS
291 # define EISCONN WSAEISCONN
295 # define ENOTCONN WSAENOTCONN
299 # define ESHUTDOWN WSAESHUTDOWN
303 # define ETOOMANYREFS WSAETOOMANYREFS
307 # define ETIMEDOUT WSAETIMEDOUT
311 # define ECONNREFUSED WSAECONNREFUSED
315 # define ELOOP WSAELOOP
319 # define EHOSTDOWN WSAEHOSTDOWN
323 # define EHOSTUNREACH WSAEHOSTUNREACH
327 # define EPROCLIM WSAEPROCLIM
331 # define EUSERS WSAEUSERS
335 # define EDQUOT WSAEDQUOT
339 # define ESTALE WSAESTALE
343 # define EREMOTE WSAEREMOTE
347 # define EDISCON WSAEDISCON
351 typedef long SysRetLong;
352 typedef sigset_t* POSIX__SigSet;
353 typedef HV* POSIX__SigAction;
355 typedef struct termios* POSIX__Termios;
356 #else /* Define termios types to int, and call not_here for the functions.*/
357 #define POSIX__Termios int
361 #define cfgetispeed(x) not_here("cfgetispeed")
362 #define cfgetospeed(x) not_here("cfgetospeed")
363 #define tcdrain(x) not_here("tcdrain")
364 #define tcflush(x,y) not_here("tcflush")
365 #define tcsendbreak(x,y) not_here("tcsendbreak")
366 #define cfsetispeed(x,y) not_here("cfsetispeed")
367 #define cfsetospeed(x,y) not_here("cfsetospeed")
368 #define ctermid(x) (char *) not_here("ctermid")
369 #define tcflow(x,y) not_here("tcflow")
370 #define tcgetattr(x,y) not_here("tcgetattr")
371 #define tcsetattr(x,y,z) not_here("tcsetattr")
374 /* Possibly needed prototypes */
377 double strtod (const char *, char **);
378 long strtol (const char *, char **, int);
379 unsigned long strtoul (const char *, char **, int);
385 #define difftime(a,b) not_here("difftime")
388 #ifndef HAS_FPATHCONF
389 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
392 #define mktime(a) not_here("mktime")
395 #define nice(a) not_here("nice")
398 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
401 #define sysconf(n) (SysRetLong) not_here("sysconf")
404 #define readlink(a,b,c) not_here("readlink")
407 #define setpgid(a,b) not_here("setpgid")
410 #define setsid() not_here("setsid")
413 #define strcoll(s1,s2) not_here("strcoll")
416 #define strtod(s1,s2) not_here("strtod")
419 #define strtol(s1,s2,b) not_here("strtol")
422 #define strtoul(s1,s2,b) not_here("strtoul")
425 #define strxfrm(s1,s2,n) not_here("strxfrm")
427 #ifndef HAS_TCGETPGRP
428 #define tcgetpgrp(a) not_here("tcgetpgrp")
430 #ifndef HAS_TCSETPGRP
431 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
435 #define times(a) not_here("times")
439 #define uname(a) not_here("uname")
442 #define waitpid(a,b,c) not_here("waitpid")
447 #define mblen(a,b) not_here("mblen")
451 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
454 #define mbtowc(pwc, s, n) not_here("mbtowc")
457 #define wcstombs(s, pwcs, n) not_here("wcstombs")
460 #define wctomb(s, wchar) not_here("wcstombs")
462 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
463 /* If we don't have these functions, then we wouldn't have gotten a typedef
464 for wchar_t, the wide character type. Defining wchar_t allows the
465 functions referencing it to compile. Its actual type is then meaningless,
466 since without the above functions, all sections using it end up calling
467 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
473 #ifdef HAS_LOCALECONV
474 struct lconv_offset {
479 const struct lconv_offset lconv_strings[] = {
480 {"decimal_point", offsetof(struct lconv, decimal_point)},
481 {"thousands_sep", offsetof(struct lconv, thousands_sep)},
482 #ifndef NO_LOCALECONV_GROUPING
483 {"grouping", offsetof(struct lconv, grouping)},
485 {"int_curr_symbol", offsetof(struct lconv, int_curr_symbol)},
486 {"currency_symbol", offsetof(struct lconv, currency_symbol)},
487 {"mon_decimal_point", offsetof(struct lconv, mon_decimal_point)},
488 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
489 {"mon_thousands_sep", offsetof(struct lconv, mon_thousands_sep)},
491 #ifndef NO_LOCALECONV_MON_GROUPING
492 {"mon_grouping", offsetof(struct lconv, mon_grouping)},
494 {"positive_sign", offsetof(struct lconv, positive_sign)},
495 {"negative_sign", offsetof(struct lconv, negative_sign)},
499 const struct lconv_offset lconv_integers[] = {
500 {"int_frac_digits", offsetof(struct lconv, int_frac_digits)},
501 {"frac_digits", offsetof(struct lconv, frac_digits)},
502 {"p_cs_precedes", offsetof(struct lconv, p_cs_precedes)},
503 {"p_sep_by_space", offsetof(struct lconv, p_sep_by_space)},
504 {"n_cs_precedes", offsetof(struct lconv, n_cs_precedes)},
505 {"n_sep_by_space", offsetof(struct lconv, n_sep_by_space)},
506 {"p_sign_posn", offsetof(struct lconv, p_sign_posn)},
507 {"n_sign_posn", offsetof(struct lconv, n_sign_posn)},
512 #define localeconv() not_here("localeconv")
515 #ifdef HAS_LONG_DOUBLE
516 # if LONG_DOUBLESIZE > NVSIZE
517 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
521 #ifndef HAS_LONG_DOUBLE
533 /* Background: in most systems the low byte of the wait status
534 * is the signal (the lowest 7 bits) and the coredump flag is
535 * the eight bit, and the second lowest byte is the exit status.
536 * BeOS bucks the trend and has the bytes in different order.
537 * See beos/beos.c for how the reality is bent even in BeOS
538 * to follow the traditional. However, to make the POSIX
539 * wait W*() macros to work in BeOS, we need to unbend the
540 * reality back in place. --jhi */
541 /* In actual fact the code below is to blame here. Perl has an internal
542 * representation of the exit status ($?), which it re-composes from the
543 * OS's representation using the W*() POSIX macros. The code below
544 * incorrectly uses the W*() macros on the internal representation,
545 * which fails for OSs that have a different representation (namely BeOS
546 * and Haiku). WMUNGE() is a hack that converts the internal
547 * representation into the OS specific one, so that the W*() macros work
548 * as expected. The better solution would be not to use the W*() macros
549 * in the first place, though. -- Ingo Weinhold
551 #if defined(__HAIKU__)
552 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
554 # define WMUNGE(x) (x)
558 not_here(const char *s)
560 croak("POSIX::%s not implemented on this architecture", s);
564 #include "const-c.inc"
567 restore_sigmask(pTHX_ SV *osset_sv)
569 /* Fortunately, restoring the signal mask can't fail, because
570 * there's nothing we can do about it if it does -- we're not
571 * supposed to return -1 from sigaction unless the disposition
574 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
575 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
579 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
580 SV *const t = newSVrv(rv, packname);
581 void *const p = sv_grow(t, size + 1);
591 * (1) The CRT maintains its own copy of the environment, separate from
594 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
595 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
598 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
599 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
602 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
603 * calls CRT tzset(), but only the first time it is called, and in turn
604 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
605 * local copy of the environment and hence gets the original setting as
606 * perl never updates the CRT copy when assigning to $ENV{TZ}.
608 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
609 * putenv() to update the CRT copy of the environment (if it is different)
610 * whenever we're about to call tzset().
612 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
615 * (a) Each interpreter has its own copy of the environment inside the
616 * perlhost structure. That allows applications that host multiple
617 * independent Perl interpreters to isolate environment changes from
618 * each other. (This is similar to how the perlhost mechanism keeps a
619 * separate working directory for each Perl interpreter, so that calling
620 * chdir() will not affect other interpreters.)
622 * (b) Only the first Perl interpreter instantiated within a process will
623 * "write through" environment changes to the process environment.
625 * (c) Even the primary Perl interpreter won't update the CRT copy of the
626 * the environment, only the Win32API copy (it calls win32_putenv()).
628 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
629 * sense to only update the process environment when inside the main
630 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
631 * from here so we'll just have to check PL_curinterp instead.
633 * Therefore, we can simply #undef getenv() and putenv() so that those names
634 * always refer to the CRT functions, and explicitly call win32_getenv() to
635 * access perl's %ENV.
637 * We also #undef malloc() and free() to be sure we are using the CRT
638 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
639 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
640 * when the Perl interpreter is being destroyed so we'd end up with a pointer
641 * into deallocated memory in environ[] if a program embedding a Perl
642 * interpreter continues to operate even after the main Perl interpreter has
645 * Note that we don't free() the malloc()ed memory unless and until we call
646 * malloc() again ourselves because the CRT putenv() function simply puts its
647 * pointer argument into the environ[] array (it doesn't make a copy of it)
648 * so this memory must otherwise be leaked.
657 fix_win32_tzenv(void)
659 static char* oldenv = NULL;
661 const char* perl_tz_env = win32_getenv("TZ");
662 const char* crt_tz_env = getenv("TZ");
663 if (perl_tz_env == NULL)
665 if (crt_tz_env == NULL)
667 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
668 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
669 if (newenv != NULL) {
670 sprintf(newenv, "TZ=%s", perl_tz_env);
682 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
683 * This code is duplicated in the Time-Piece module, so any changes made here
684 * should be made there too.
690 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
691 if (PL_curinterp == aTHX)
698 typedef int (*isfunc_t)(int);
699 typedef void (*any_dptr_t)(void *);
701 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
703 static XSPROTO(is_common); /* prototype to pass -Wmissing-prototypes */
704 static XSPROTO(is_common)
709 croak_xs_usage(cv, "charstring");
715 unsigned char *s = (unsigned char *) SvPV(ST(0), len);
716 unsigned char *e = s + len;
717 isfunc_t isfunc = (isfunc_t) XSANY.any_dptr;
719 for (RETVAL = 1; RETVAL && s < e; s++)
728 MODULE = POSIX PACKAGE = POSIX
733 const char *file = __FILE__;
735 /* Ensure we get the function, not a macro implementation. Like the C89
736 standard says we can... */
738 cv = newXS("POSIX::isalnum", is_common, file);
739 XSANY.any_dptr = (any_dptr_t) &isalnum;
741 cv = newXS("POSIX::isalpha", is_common, file);
742 XSANY.any_dptr = (any_dptr_t) &isalpha;
744 cv = newXS("POSIX::iscntrl", is_common, file);
745 XSANY.any_dptr = (any_dptr_t) &iscntrl;
747 cv = newXS("POSIX::isdigit", is_common, file);
748 XSANY.any_dptr = (any_dptr_t) &isdigit;
750 cv = newXS("POSIX::isgraph", is_common, file);
751 XSANY.any_dptr = (any_dptr_t) &isgraph;
753 cv = newXS("POSIX::islower", is_common, file);
754 XSANY.any_dptr = (any_dptr_t) &islower;
756 cv = newXS("POSIX::isprint", is_common, file);
757 XSANY.any_dptr = (any_dptr_t) &isprint;
759 cv = newXS("POSIX::ispunct", is_common, file);
760 XSANY.any_dptr = (any_dptr_t) &ispunct;
762 cv = newXS("POSIX::isspace", is_common, file);
763 XSANY.any_dptr = (any_dptr_t) &isspace;
765 cv = newXS("POSIX::isupper", is_common, file);
766 XSANY.any_dptr = (any_dptr_t) &isupper;
768 cv = newXS("POSIX::isxdigit", is_common, file);
769 XSANY.any_dptr = (any_dptr_t) &isxdigit;
772 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
775 new(packname = "POSIX::SigSet", ...)
776 const char * packname
781 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
785 for (i = 1; i < items; i++)
786 sigaddset(s, SvIV(ST(i)));
797 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
807 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
812 sigismember(sigset, sig)
816 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
819 new(packname = "POSIX::Termios", ...)
820 const char * packname
824 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
825 sizeof(struct termios), packname);
826 /* The previous implementation stored a pointer to an uninitialised
827 struct termios. Seems safer to initialise it, particularly as
828 this implementation exposes the struct to prying from perl-space.
830 memset(p, 0, 1 + sizeof(struct termios));
838 getattr(termios_ref, fd = 0)
839 POSIX::Termios termios_ref
842 RETVAL = tcgetattr(fd, termios_ref);
846 # If we define TCSANOW here then both a found and not found constant sub
847 # are created causing a Constant subroutine TCSANOW redefined warning
849 # define DEF_SETATTR_ACTION 0
851 # define DEF_SETATTR_ACTION TCSANOW
854 setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION)
855 POSIX::Termios termios_ref
859 /* The second argument to the call is mandatory, but we'd like to give
860 it a useful default. 0 isn't valid on all operating systems - on
861 Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same
862 values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */
863 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
868 getispeed(termios_ref)
869 POSIX::Termios termios_ref
873 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
878 getiflag(termios_ref)
879 POSIX::Termios termios_ref
885 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
888 RETVAL = termios_ref->c_iflag;
891 RETVAL = termios_ref->c_oflag;
894 RETVAL = termios_ref->c_cflag;
897 RETVAL = termios_ref->c_lflag;
901 not_here(GvNAME(CvGV(cv)));
908 getcc(termios_ref, ccix)
909 POSIX::Termios termios_ref
912 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
914 croak("Bad getcc subscript");
915 RETVAL = termios_ref->c_cc[ccix];
924 setispeed(termios_ref, speed)
925 POSIX::Termios termios_ref
931 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
936 setiflag(termios_ref, flag)
937 POSIX::Termios termios_ref
944 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
947 termios_ref->c_iflag = flag;
950 termios_ref->c_oflag = flag;
953 termios_ref->c_cflag = flag;
956 termios_ref->c_lflag = flag;
960 not_here(GvNAME(CvGV(cv)));
964 setcc(termios_ref, ccix, cc)
965 POSIX::Termios termios_ref
969 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
971 croak("Bad setcc subscript");
972 termios_ref->c_cc[ccix] = cc;
978 MODULE = POSIX PACKAGE = POSIX
980 INCLUDE: const-xs.inc
987 POSIX::WIFSIGNALED = 2
988 POSIX::WIFSTOPPED = 3
992 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
993 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
994 RETVAL = 0; /* Silence compilers that notice this, but don't realise
995 that not_here() can't return. */
1000 RETVAL = WEXITSTATUS(WMUNGE(status));
1002 not_here("WEXITSTATUS");
1007 RETVAL = WIFEXITED(WMUNGE(status));
1009 not_here("WIFEXITED");
1014 RETVAL = WIFSIGNALED(WMUNGE(status));
1016 not_here("WIFSIGNALED");
1021 RETVAL = WIFSTOPPED(WMUNGE(status));
1023 not_here("WIFSTOPPED");
1028 RETVAL = WSTOPSIG(WMUNGE(status));
1030 not_here("WSTOPSIG");
1035 RETVAL = WTERMSIG(WMUNGE(status));
1037 not_here("WTERMSIG");
1041 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
1047 open(filename, flags = O_RDONLY, mode = 0666)
1052 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1053 TAINT_PROPER("open");
1054 RETVAL = open(filename, flags, mode);
1062 #ifdef HAS_LOCALECONV
1063 struct lconv *lcbuf;
1065 sv_2mortal((SV*)RETVAL);
1066 if ((lcbuf = localeconv())) {
1067 const struct lconv_offset *strings = lconv_strings;
1068 const struct lconv_offset *integers = lconv_integers;
1069 const char *ptr = (const char *) lcbuf;
1072 const char *value = *((const char **)(ptr + strings->offset));
1074 if (value && *value)
1075 (void) hv_store(RETVAL, strings->name, strlen(strings->name),
1076 newSVpv(value, 0), 0);
1077 } while ((++strings)->name);
1080 const char value = *((const char *)(ptr + integers->offset));
1082 if (value != CHAR_MAX)
1083 (void) hv_store(RETVAL, integers->name,
1084 strlen(integers->name), newSViv(value), 0);
1085 } while ((++integers)->name);
1088 localeconv(); /* A stub to call not_here(). */
1094 setlocale(category, locale = 0)
1100 retval = setlocale(category, locale);
1102 /* Save retval since subsequent setlocale() calls
1103 * may overwrite it. */
1104 RETVAL = savepv(retval);
1105 #ifdef USE_LOCALE_CTYPE
1106 if (category == LC_CTYPE
1108 || category == LC_ALL
1114 if (category == LC_ALL)
1115 newctype = setlocale(LC_CTYPE, NULL);
1119 new_ctype(newctype);
1121 #endif /* USE_LOCALE_CTYPE */
1122 #ifdef USE_LOCALE_COLLATE
1123 if (category == LC_COLLATE
1125 || category == LC_ALL
1131 if (category == LC_ALL)
1132 newcoll = setlocale(LC_COLLATE, NULL);
1136 new_collate(newcoll);
1138 #endif /* USE_LOCALE_COLLATE */
1139 #ifdef USE_LOCALE_NUMERIC
1140 if (category == LC_NUMERIC
1142 || category == LC_ALL
1148 if (category == LC_ALL)
1149 newnum = setlocale(LC_NUMERIC, NULL);
1153 new_numeric(newnum);
1155 #endif /* USE_LOCALE_NUMERIC */
1223 /* (We already know stack is long enough.) */
1224 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1225 PUSHs(sv_2mortal(newSViv(expvar)));
1237 /* (We already know stack is long enough.) */
1238 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1239 PUSHs(sv_2mortal(newSVnv(intvar)));
1242 sigaction(sig, optaction, oldaction = 0)
1245 POSIX::SigAction oldaction
1247 #if defined(WIN32) || defined(NETWARE)
1248 RETVAL = not_here("sigaction");
1250 # This code is really grody because we're trying to make the signal
1251 # interface look beautiful, which is hard.
1255 POSIX__SigAction action;
1256 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
1257 struct sigaction act;
1258 struct sigaction oact;
1262 POSIX__SigSet sigset;
1267 croak("Negative signals are not allowed");
1270 if (sig == 0 && SvPOK(ST(0))) {
1271 const char *s = SvPVX_const(ST(0));
1272 int i = whichsig(s);
1274 if (i < 0 && memEQ(s, "SIG", 3))
1275 i = whichsig(s + 3);
1277 if (ckWARN(WARN_SIGNAL))
1278 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1279 "No such signal: SIG%s", s);
1286 if (sig > NSIG) { /* NSIG - 1 is still okay. */
1287 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1288 "No such signal: %d", sig);
1292 sigsvp = hv_fetch(GvHVn(siggv),
1294 strlen(PL_sig_name[sig]),
1297 /* Check optaction and set action */
1298 if(SvTRUE(optaction)) {
1299 if(sv_isa(optaction, "POSIX::SigAction"))
1300 action = (HV*)SvRV(optaction);
1302 croak("action is not of type POSIX::SigAction");
1308 /* sigaction() is supposed to look atomic. In particular, any
1309 * signal handler invoked during a sigaction() call should
1310 * see either the old or the new disposition, and not something
1311 * in between. We use sigprocmask() to make it so.
1314 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1318 /* Restore signal mask no matter how we exit this block. */
1319 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
1320 SAVEFREESV( osset_sv );
1321 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1323 RETVAL=-1; /* In case both oldaction and action are 0. */
1325 /* Remember old disposition if desired. */
1327 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
1329 croak("Can't supply an oldaction without a HANDLER");
1330 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1331 sv_setsv(*svp, *sigsvp);
1334 sv_setpvs(*svp, "DEFAULT");
1336 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1341 /* Get back the mask. */
1342 svp = hv_fetchs(oldaction, "MASK", TRUE);
1343 if (sv_isa(*svp, "POSIX::SigSet")) {
1344 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
1347 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
1351 *sigset = oact.sa_mask;
1353 /* Get back the flags. */
1354 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
1355 sv_setiv(*svp, oact.sa_flags);
1357 /* Get back whether the old handler used safe signals. */
1358 svp = hv_fetchs(oldaction, "SAFE", TRUE);
1360 /* compare incompatible pointers by casting to integer */
1361 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
1365 /* Safe signals use "csighandler", which vectors through the
1366 PL_sighandlerp pointer when it's safe to do so.
1367 (BTW, "csighandler" is very different from "sighandler".) */
1368 svp = hv_fetchs(action, "SAFE", FALSE);
1372 (*svp && SvTRUE(*svp))
1373 ? PL_csighandlerp : PL_sighandlerp
1376 /* Vector new Perl handler through %SIG.
1377 (The core signal handlers read %SIG to dispatch.) */
1378 svp = hv_fetchs(action, "HANDLER", FALSE);
1380 croak("Can't supply an action without a HANDLER");
1381 sv_setsv(*sigsvp, *svp);
1383 /* This call actually calls sigaction() with almost the
1384 right settings, including appropriate interpretation
1385 of DEFAULT and IGNORE. However, why are we doing
1386 this when we're about to do it again just below? XXX */
1387 SvSETMAGIC(*sigsvp);
1389 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1391 const char *s=SvPVX_const(*svp);
1392 if(strEQ(s,"IGNORE")) {
1393 act.sa_handler = SIG_IGN;
1395 else if(strEQ(s,"DEFAULT")) {
1396 act.sa_handler = SIG_DFL;
1400 /* Set up any desired mask. */
1401 svp = hv_fetchs(action, "MASK", FALSE);
1402 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1403 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
1404 act.sa_mask = *sigset;
1407 sigemptyset(& act.sa_mask);
1409 /* Set up any desired flags. */
1410 svp = hv_fetchs(action, "FLAGS", FALSE);
1411 act.sa_flags = svp ? SvIV(*svp) : 0;
1413 /* Don't worry about cleaning up *sigsvp if this fails,
1414 * because that means we tried to disposition a
1415 * nonblockable signal, in which case *sigsvp is
1416 * essentially meaningless anyway.
1418 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1433 POSIX::SigSet sigset
1437 RETVAL = ix ? sigsuspend(sigset) : sigpending(sigset);
1444 sigprocmask(how, sigset, oldsigset = 0)
1446 POSIX::SigSet sigset = NO_INIT
1447 POSIX::SigSet oldsigset = NO_INIT
1449 if (! SvOK(ST(1))) {
1451 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
1452 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
1454 croak("sigset is not of type POSIX::SigSet");
1457 if (items < 3 || ! SvOK(ST(2))) {
1459 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
1460 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
1462 croak("oldsigset is not of type POSIX::SigSet");
1475 /* RT #98912 - More Microsoft muppetry - failing to actually implemented
1476 the well known documented POSIX behaviour for a POSIX API.
1477 http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
1478 RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
1480 RETVAL = dup2(fd1, fd2);
1486 lseek(fd, offset, whence)
1491 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1492 RETVAL = sizeof(Off_t) > sizeof(IV)
1493 ? newSVnv((NV)pos) : newSViv((IV)pos);
1502 if ((incr = nice(incr)) != -1 || errno == 0) {
1504 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
1506 XPUSHs(sv_2mortal(newSViv(incr)));
1513 if (pipe(fds) != -1) {
1515 PUSHs(sv_2mortal(newSViv(fds[0])));
1516 PUSHs(sv_2mortal(newSViv(fds[1])));
1520 read(fd, buffer, nbytes)
1522 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1526 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1529 SvCUR_set(sv_buffer, RETVAL);
1530 SvPOK_only(sv_buffer);
1531 *SvEND(sv_buffer) = '\0';
1532 SvTAINTED_on(sv_buffer);
1548 tcsetpgrp(fd, pgrp_id)
1557 if (uname(&buf) >= 0) {
1559 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
1560 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
1561 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
1562 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
1563 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
1566 uname((char *) 0); /* A stub to call not_here(). */
1570 write(fd, buffer, nbytes)
1581 RETVAL = newSVpvn("", 0);
1582 SvGROW(RETVAL, L_tmpnam);
1583 len = strlen(tmpnam(SvPV(RETVAL, i)));
1584 SvCUR_set(RETVAL, len);
1597 mbstowcs(s, pwcs, n)
1609 wcstombs(s, pwcs, n)
1631 SET_NUMERIC_LOCAL();
1632 num = strtod(str, &unparsed);
1633 PUSHs(sv_2mortal(newSVnv(num)));
1634 if (GIMME == G_ARRAY) {
1637 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1639 PUSHs(&PL_sv_undef);
1643 strtol(str, base = 0)
1650 num = strtol(str, &unparsed, base);
1651 #if IVSIZE <= LONGSIZE
1652 if (num < IV_MIN || num > IV_MAX)
1653 PUSHs(sv_2mortal(newSVnv((double)num)));
1656 PUSHs(sv_2mortal(newSViv((IV)num)));
1657 if (GIMME == G_ARRAY) {
1660 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1662 PUSHs(&PL_sv_undef);
1666 strtoul(str, base = 0)
1673 num = strtoul(str, &unparsed, base);
1674 #if IVSIZE <= LONGSIZE
1676 PUSHs(sv_2mortal(newSVnv((double)num)));
1679 PUSHs(sv_2mortal(newSViv((IV)num)));
1680 if (GIMME == G_ARRAY) {
1683 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1685 PUSHs(&PL_sv_undef);
1695 char *p = SvPV(src,srclen);
1697 ST(0) = sv_2mortal(newSV(srclen*4+1));
1698 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1699 if (dstlen > srclen) {
1701 SvGROW(ST(0), dstlen);
1702 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1705 SvCUR_set(ST(0), dstlen);
1710 mkfifo(filename, mode)
1717 RETVAL = access(filename, mode);
1719 TAINT_PROPER("mkfifo");
1720 RETVAL = mkfifo(filename, mode);
1732 RETVAL = ix == 1 ? close(fd)
1733 : (ix < 1 ? tcdrain(fd) : dup(fd));
1746 RETVAL = ix == 1 ? tcflush(fd, action)
1747 : (ix < 1 ? tcflow(fd, action) : tcsendbreak(fd, action));
1752 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1768 init_tm(&mytm); /* XXX workaround - see init_tm() in core util.c */
1771 mytm.tm_hour = hour;
1772 mytm.tm_mday = mday;
1774 mytm.tm_year = year;
1775 mytm.tm_wday = wday;
1776 mytm.tm_yday = yday;
1777 mytm.tm_isdst = isdst;
1779 const time_t result = mktime(&mytm);
1780 if (result == (time_t)-1)
1782 else if (result == 0)
1783 sv_setpvn(TARG, "0 but true", 10);
1785 sv_setiv(TARG, (IV)result);
1787 sv_setpv(TARG, asctime(&mytm));
1805 realtime = times( &tms );
1807 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1808 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1809 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1810 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1811 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1814 difftime(time1, time2)
1818 #XXX: if $xsubpp::WantOptimize is always the default
1819 # sv_setpv(TARG, ...) could be used rather than
1820 # ST(0) = sv_2mortal(newSVpv(...))
1822 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1835 char *buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
1837 SV *const sv = sv_newmortal();
1838 sv_usepvn_flags(sv, buf, strlen(buf), SV_HAS_TRAILING_NUL);
1855 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
1856 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
1862 #ifdef HAS_CTERMID_R
1863 s = (char *) safemalloc((size_t) L_ctermid);
1865 RETVAL = ctermid(s);
1869 #ifdef HAS_CTERMID_R
1878 RETVAL = cuserid(s);
1881 not_here("cuserid");
1892 pathconf(filename, name)
1903 unsigned int seconds
1905 RETVAL = PerlProc_sleep(seconds);
1931 XSprePUSH; PUSHTARG;
1935 lchown(uid, gid, path)
1941 /* yes, the order of arguments is different,
1942 * but consistent with CORE::chown() */
1943 RETVAL = lchown(path, uid, gid);
1945 RETVAL = not_here("lchown");