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
16 /* Solaris needs this in order not to zero out all the untouched fields in strptime() */
17 #define _STRPTIME_DONTZERO
20 #define PERLIO_NOT_STDIO 1
23 #if defined(PERL_IMPLICIT_SYS)
27 # define open PerlLIO_open3
30 #ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
57 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
58 metaconfig for future extension writers. We don't use them in POSIX.
59 (This is really sneaky :-) --AD
61 #if defined(I_TERMIOS)
71 #include <sys/types.h>
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 #if defined(__VMS) && !defined(__POSIX_SOURCE)
89 # include <libdef.h> /* LIB$_INVARG constant */
90 # include <lib$routines.h> /* prototype for lib$ediv() */
91 # include <starlet.h> /* prototype for sys$gettim() */
92 # if DECC_VERSION < 50000000
93 # define pid_t int /* old versions of DECC miss this in types.h */
97 # define mkfifo(a,b) (not_here("mkfifo"),-1)
98 # define tzset() not_here("tzset")
100 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
101 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
102 # include <utsname.h>
103 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
105 /* The POSIX notion of ttyname() is better served by getname() under VMS */
106 static char ttnambuf[64];
107 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
109 /* The non-POSIX CRTL times() has void return type, so we just get the
110 current time directly */
111 clock_t vms_times(struct tms *bufptr) {
114 /* Get wall time and convert to 10 ms intervals to
115 * produce the return value that the POSIX standard expects */
116 # if defined(__DECC) && defined (__ALPHA)
119 _ckvmssts(sys$gettim(&vmstime));
121 retval = vmstime & 0x7fffffff;
123 /* (Older hw or ccs don't have an atomic 64-bit type, so we
124 * juggle 32-bit ints (and a float) to produce a time_t result
125 * with minimal loss of information.) */
126 long int vmstime[2],remainder,divisor = 100000;
127 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
128 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
129 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
131 /* Fill in the struct tms using the CRTL routine . . .*/
132 times((tbuffer_t *)bufptr);
133 return (clock_t) retval;
135 # define times(t) vms_times(t)
137 #if defined (__CYGWIN__)
138 # define tzname _tzname
140 #if defined (WIN32) || defined (NETWARE)
142 # define mkfifo(a,b) not_here("mkfifo")
143 # define ttyname(a) (char*)not_here("ttyname")
144 # define sigset_t long
147 # define mode_t short
150 # define mode_t short
152 # define tzset() not_here("tzset")
154 # ifndef _POSIX_OPEN_MAX
155 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
158 # define sigaction(a,b,c) not_here("sigaction")
159 # define sigpending(a) not_here("sigpending")
160 # define sigprocmask(a,b,c) not_here("sigprocmask")
161 # define sigsuspend(a) not_here("sigsuspend")
162 # define sigemptyset(a) not_here("sigemptyset")
163 # define sigaddset(a,b) not_here("sigaddset")
164 # define sigdelset(a,b) not_here("sigdelset")
165 # define sigfillset(a) not_here("sigfillset")
166 # define sigismember(a,b) not_here("sigismember")
170 # define setuid(a) not_here("setuid")
171 # define setgid(a) not_here("setgid")
177 # define mkfifo(a,b) not_here("mkfifo")
178 # else /* !( defined OS2 ) */
180 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
183 # endif /* !HAS_MKFIFO */
188 # include <sys/times.h>
190 # include <sys/utsname.h>
192 # include <sys/wait.h>
196 #endif /* WIN32 || NETWARE */
200 /* Perl on Windows assigns WSAGetLastError() return values to errno
201 * (in win32/win32sck.c). Therefore we need to map these values
202 * back to standard symbolic names, but only for those names having
203 * no existing value or an existing value >= 100. (VC++ 2010 defines
204 * a group of names with values >= 100 in its errno.h which we *do*
205 * need to redefine.) The Errno.pm module does a similar mapping.
210 # define EWOULDBLOCK WSAEWOULDBLOCK
214 # define EINPROGRESS WSAEINPROGRESS
218 # define EALREADY WSAEALREADY
222 # define ENOTSOCK WSAENOTSOCK
226 # define EDESTADDRREQ WSAEDESTADDRREQ
230 # define EMSGSIZE WSAEMSGSIZE
234 # define EPROTOTYPE WSAEPROTOTYPE
238 # define ENOPROTOOPT WSAENOPROTOOPT
239 # ifdef EPROTONOSUPPORT
240 # undef EPROTONOSUPPORT
242 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
243 # ifdef ESOCKTNOSUPPORT
244 # undef ESOCKTNOSUPPORT
246 # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
250 # define EOPNOTSUPP WSAEOPNOTSUPP
254 # define EPFNOSUPPORT WSAEPFNOSUPPORT
258 # define EAFNOSUPPORT WSAEAFNOSUPPORT
262 # define EADDRINUSE WSAEADDRINUSE
263 # ifdef EADDRNOTAVAIL
264 # undef EADDRNOTAVAIL
266 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
270 # define ENETDOWN WSAENETDOWN
274 # define ENETUNREACH WSAENETUNREACH
278 # define ENETRESET WSAENETRESET
282 # define ECONNABORTED WSAECONNABORTED
286 # define ECONNRESET WSAECONNRESET
290 # define ENOBUFS WSAENOBUFS
294 # define EISCONN WSAEISCONN
298 # define ENOTCONN WSAENOTCONN
302 # define ESHUTDOWN WSAESHUTDOWN
306 # define ETOOMANYREFS WSAETOOMANYREFS
310 # define ETIMEDOUT WSAETIMEDOUT
314 # define ECONNREFUSED WSAECONNREFUSED
318 # define ELOOP WSAELOOP
322 # define EHOSTDOWN WSAEHOSTDOWN
326 # define EHOSTUNREACH WSAEHOSTUNREACH
330 # define EPROCLIM WSAEPROCLIM
334 # define EUSERS WSAEUSERS
338 # define EDQUOT WSAEDQUOT
342 # define ESTALE WSAESTALE
346 # define EREMOTE WSAEREMOTE
350 # define EDISCON WSAEDISCON
354 typedef long SysRetLong;
355 typedef sigset_t* POSIX__SigSet;
356 typedef HV* POSIX__SigAction;
358 typedef struct termios* POSIX__Termios;
359 #else /* Define termios types to int, and call not_here for the functions.*/
360 #define POSIX__Termios int
364 #define cfgetispeed(x) not_here("cfgetispeed")
365 #define cfgetospeed(x) not_here("cfgetospeed")
366 #define tcdrain(x) not_here("tcdrain")
367 #define tcflush(x,y) not_here("tcflush")
368 #define tcsendbreak(x,y) not_here("tcsendbreak")
369 #define cfsetispeed(x,y) not_here("cfsetispeed")
370 #define cfsetospeed(x,y) not_here("cfsetospeed")
371 #define ctermid(x) (char *) not_here("ctermid")
372 #define tcflow(x,y) not_here("tcflow")
373 #define tcgetattr(x,y) not_here("tcgetattr")
374 #define tcsetattr(x,y,z) not_here("tcsetattr")
377 /* Possibly needed prototypes */
379 double strtod (const char *, char **);
380 long strtol (const char *, char **, int);
381 unsigned long strtoul (const char *, char **, int);
386 #define difftime(a,b) not_here("difftime")
389 #ifndef HAS_FPATHCONF
390 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
393 #define mktime(a) not_here("mktime")
396 #define nice(a) not_here("nice")
399 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
402 #define sysconf(n) (SysRetLong) not_here("sysconf")
405 #define readlink(a,b,c) not_here("readlink")
408 #define setpgid(a,b) not_here("setpgid")
411 #define setsid() not_here("setsid")
414 #define strcoll(s1,s2) not_here("strcoll")
417 #define strtod(s1,s2) not_here("strtod")
420 #define strtol(s1,s2,b) not_here("strtol")
423 #define strtoul(s1,s2,b) not_here("strtoul")
426 #define strxfrm(s1,s2,n) not_here("strxfrm")
428 #ifndef HAS_TCGETPGRP
429 #define tcgetpgrp(a) not_here("tcgetpgrp")
431 #ifndef HAS_TCSETPGRP
432 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
436 #define times(a) not_here("times")
440 #define uname(a) not_here("uname")
443 #define waitpid(a,b,c) not_here("waitpid")
448 #define mblen(a,b) not_here("mblen")
452 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
455 #define mbtowc(pwc, s, n) not_here("mbtowc")
458 #define wcstombs(s, pwcs, n) not_here("wcstombs")
461 #define wctomb(s, wchar) not_here("wcstombs")
463 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
464 /* If we don't have these functions, then we wouldn't have gotten a typedef
465 for wchar_t, the wide character type. Defining wchar_t allows the
466 functions referencing it to compile. Its actual type is then meaningless,
467 since without the above functions, all sections using it end up calling
468 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
474 #ifdef HAS_LOCALECONV
475 struct lconv_offset {
480 const struct lconv_offset lconv_strings[] = {
481 {"decimal_point", offsetof(struct lconv, decimal_point)},
482 {"thousands_sep", offsetof(struct lconv, thousands_sep)},
483 #ifndef NO_LOCALECONV_GROUPING
484 {"grouping", offsetof(struct lconv, grouping)},
486 {"int_curr_symbol", offsetof(struct lconv, int_curr_symbol)},
487 {"currency_symbol", offsetof(struct lconv, currency_symbol)},
488 {"mon_decimal_point", offsetof(struct lconv, mon_decimal_point)},
489 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
490 {"mon_thousands_sep", offsetof(struct lconv, mon_thousands_sep)},
492 #ifndef NO_LOCALECONV_MON_GROUPING
493 {"mon_grouping", offsetof(struct lconv, mon_grouping)},
495 {"positive_sign", offsetof(struct lconv, positive_sign)},
496 {"negative_sign", offsetof(struct lconv, negative_sign)},
500 const struct lconv_offset lconv_integers[] = {
501 {"int_frac_digits", offsetof(struct lconv, int_frac_digits)},
502 {"frac_digits", offsetof(struct lconv, frac_digits)},
503 {"p_cs_precedes", offsetof(struct lconv, p_cs_precedes)},
504 {"p_sep_by_space", offsetof(struct lconv, p_sep_by_space)},
505 {"n_cs_precedes", offsetof(struct lconv, n_cs_precedes)},
506 {"n_sep_by_space", offsetof(struct lconv, n_sep_by_space)},
507 {"p_sign_posn", offsetof(struct lconv, p_sign_posn)},
508 {"n_sign_posn", offsetof(struct lconv, n_sign_posn)},
513 #define localeconv() not_here("localeconv")
516 #ifdef HAS_LONG_DOUBLE
517 # if LONG_DOUBLESIZE > NVSIZE
518 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
522 #ifndef HAS_LONG_DOUBLE
534 /* Background: in most systems the low byte of the wait status
535 * is the signal (the lowest 7 bits) and the coredump flag is
536 * the eight bit, and the second lowest byte is the exit status.
537 * BeOS bucks the trend and has the bytes in different order.
538 * See beos/beos.c for how the reality is bent even in BeOS
539 * to follow the traditional. However, to make the POSIX
540 * wait W*() macros to work in BeOS, we need to unbend the
541 * reality back in place. --jhi */
542 /* In actual fact the code below is to blame here. Perl has an internal
543 * representation of the exit status ($?), which it re-composes from the
544 * OS's representation using the W*() POSIX macros. The code below
545 * incorrectly uses the W*() macros on the internal representation,
546 * which fails for OSs that have a different representation (namely BeOS
547 * and Haiku). WMUNGE() is a hack that converts the internal
548 * representation into the OS specific one, so that the W*() macros work
549 * as expected. The better solution would be not to use the W*() macros
550 * in the first place, though. -- Ingo Weinhold
552 #if defined(__BEOS__) || defined(__HAIKU__)
553 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
555 # define WMUNGE(x) (x)
559 not_here(const char *s)
561 croak("POSIX::%s not implemented on this architecture", s);
565 #include "const-c.inc"
568 restore_sigmask(pTHX_ SV *osset_sv)
570 /* Fortunately, restoring the signal mask can't fail, because
571 * there's nothing we can do about it if it does -- we're not
572 * supposed to return -1 from sigaction unless the disposition
575 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
576 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
580 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
581 SV *const t = newSVrv(rv, packname);
582 void *const p = sv_grow(t, size + 1);
592 * (1) The CRT maintains its own copy of the environment, separate from
595 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
596 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
599 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
600 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
603 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
604 * calls CRT tzset(), but only the first time it is called, and in turn
605 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
606 * local copy of the environment and hence gets the original setting as
607 * perl never updates the CRT copy when assigning to $ENV{TZ}.
609 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
610 * putenv() to update the CRT copy of the environment (if it is different)
611 * whenever we're about to call tzset().
613 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
616 * (a) Each interpreter has its own copy of the environment inside the
617 * perlhost structure. That allows applications that host multiple
618 * independent Perl interpreters to isolate environment changes from
619 * each other. (This is similar to how the perlhost mechanism keeps a
620 * separate working directory for each Perl interpreter, so that calling
621 * chdir() will not affect other interpreters.)
623 * (b) Only the first Perl interpreter instantiated within a process will
624 * "write through" environment changes to the process environment.
626 * (c) Even the primary Perl interpreter won't update the CRT copy of the
627 * the environment, only the Win32API copy (it calls win32_putenv()).
629 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
630 * sense to only update the process environment when inside the main
631 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
632 * from here so we'll just have to check PL_curinterp instead.
634 * Therefore, we can simply #undef getenv() and putenv() so that those names
635 * always refer to the CRT functions, and explicitly call win32_getenv() to
636 * access perl's %ENV.
638 * We also #undef malloc() and free() to be sure we are using the CRT
639 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
640 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
641 * when the Perl interpreter is being destroyed so we'd end up with a pointer
642 * into deallocated memory in environ[] if a program embedding a Perl
643 * interpreter continues to operate even after the main Perl interpreter has
646 * Note that we don't free() the malloc()ed memory unless and until we call
647 * malloc() again ourselves because the CRT putenv() function simply puts its
648 * pointer argument into the environ[] array (it doesn't make a copy of it)
649 * so this memory must otherwise be leaked.
658 fix_win32_tzenv(void)
660 static char* oldenv = NULL;
662 const char* perl_tz_env = win32_getenv("TZ");
663 const char* crt_tz_env = getenv("TZ");
664 if (perl_tz_env == NULL)
666 if (crt_tz_env == NULL)
668 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
669 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
670 if (newenv != NULL) {
671 sprintf(newenv, "TZ=%s", perl_tz_env);
683 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
684 * This code is duplicated in the Time-Piece module, so any changes made here
685 * should be made there too.
691 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
692 if (PL_curinterp == aTHX)
699 typedef int (*isfunc_t)(int);
700 typedef void (*any_dptr_t)(void *);
702 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
704 static XSPROTO(is_common); /* prototype to pass -Wmissing-prototypes */
705 static XSPROTO(is_common)
710 croak_xs_usage(cv, "charstring");
716 unsigned char *s = (unsigned char *) SvPV(ST(0), len);
717 unsigned char *e = s + len;
718 isfunc_t isfunc = (isfunc_t) XSANY.any_dptr;
720 for (RETVAL = 1; RETVAL && s < e; s++)
729 MODULE = POSIX PACKAGE = POSIX
734 const char *file = __FILE__;
736 /* Ensure we get the function, not a macro implementation. Like the C89
737 standard says we can... */
739 cv = newXS("POSIX::isalnum", is_common, file);
740 XSANY.any_dptr = (any_dptr_t) &isalnum;
742 cv = newXS("POSIX::isalpha", is_common, file);
743 XSANY.any_dptr = (any_dptr_t) &isalpha;
745 cv = newXS("POSIX::iscntrl", is_common, file);
746 XSANY.any_dptr = (any_dptr_t) &iscntrl;
748 cv = newXS("POSIX::isdigit", is_common, file);
749 XSANY.any_dptr = (any_dptr_t) &isdigit;
751 cv = newXS("POSIX::isgraph", is_common, file);
752 XSANY.any_dptr = (any_dptr_t) &isgraph;
754 cv = newXS("POSIX::islower", is_common, file);
755 XSANY.any_dptr = (any_dptr_t) &islower;
757 cv = newXS("POSIX::isprint", is_common, file);
758 XSANY.any_dptr = (any_dptr_t) &isprint;
760 cv = newXS("POSIX::ispunct", is_common, file);
761 XSANY.any_dptr = (any_dptr_t) &ispunct;
763 cv = newXS("POSIX::isspace", is_common, file);
764 XSANY.any_dptr = (any_dptr_t) &isspace;
766 cv = newXS("POSIX::isupper", is_common, file);
767 XSANY.any_dptr = (any_dptr_t) &isupper;
769 cv = newXS("POSIX::isxdigit", is_common, file);
770 XSANY.any_dptr = (any_dptr_t) &isxdigit;
773 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
776 new(packname = "POSIX::SigSet", ...)
777 const char * packname
782 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
786 for (i = 1; i < items; i++)
787 sigaddset(s, SvIV(ST(i)));
798 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
808 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
813 sigismember(sigset, sig)
817 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
820 new(packname = "POSIX::Termios", ...)
821 const char * packname
825 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
826 sizeof(struct termios), packname);
827 /* The previous implementation stored a pointer to an uninitialised
828 struct termios. Seems safer to initialise it, particularly as
829 this implementation exposes the struct to prying from perl-space.
831 memset(p, 0, 1 + sizeof(struct termios));
839 getattr(termios_ref, fd = 0)
840 POSIX::Termios termios_ref
843 RETVAL = tcgetattr(fd, termios_ref);
847 # If we define TCSANOW here then both a found and not found constant sub
848 # are created causing a Constant subroutine TCSANOW redefined warning
850 # define DEF_SETATTR_ACTION 0
852 # define DEF_SETATTR_ACTION TCSANOW
855 setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION)
856 POSIX::Termios termios_ref
860 /* The second argument to the call is mandatory, but we'd like to give
861 it a useful default. 0 isn't valid on all operating systems - on
862 Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same
863 values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */
864 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
869 getispeed(termios_ref)
870 POSIX::Termios termios_ref
874 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
879 getiflag(termios_ref)
880 POSIX::Termios termios_ref
886 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
889 RETVAL = termios_ref->c_iflag;
892 RETVAL = termios_ref->c_oflag;
895 RETVAL = termios_ref->c_cflag;
898 RETVAL = termios_ref->c_lflag;
902 not_here(GvNAME(CvGV(cv)));
909 getcc(termios_ref, ccix)
910 POSIX::Termios termios_ref
913 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
915 croak("Bad getcc subscript");
916 RETVAL = termios_ref->c_cc[ccix];
925 setispeed(termios_ref, speed)
926 POSIX::Termios termios_ref
932 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
937 setiflag(termios_ref, flag)
938 POSIX::Termios termios_ref
945 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
948 termios_ref->c_iflag = flag;
951 termios_ref->c_oflag = flag;
954 termios_ref->c_cflag = flag;
957 termios_ref->c_lflag = flag;
961 not_here(GvNAME(CvGV(cv)));
965 setcc(termios_ref, ccix, cc)
966 POSIX::Termios termios_ref
970 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
972 croak("Bad setcc subscript");
973 termios_ref->c_cc[ccix] = cc;
979 MODULE = POSIX PACKAGE = POSIX
981 INCLUDE: const-xs.inc
988 POSIX::WIFSIGNALED = 2
989 POSIX::WIFSTOPPED = 3
993 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
994 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
995 RETVAL = 0; /* Silence compilers that notice this, but don't realise
996 that not_here() can't return. */
1001 RETVAL = WEXITSTATUS(WMUNGE(status));
1003 not_here("WEXITSTATUS");
1008 RETVAL = WIFEXITED(WMUNGE(status));
1010 not_here("WIFEXITED");
1015 RETVAL = WIFSIGNALED(WMUNGE(status));
1017 not_here("WIFSIGNALED");
1022 RETVAL = WIFSTOPPED(WMUNGE(status));
1024 not_here("WIFSTOPPED");
1029 RETVAL = WSTOPSIG(WMUNGE(status));
1031 not_here("WSTOPSIG");
1036 RETVAL = WTERMSIG(WMUNGE(status));
1038 not_here("WTERMSIG");
1042 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
1048 open(filename, flags = O_RDONLY, mode = 0666)
1053 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1054 TAINT_PROPER("open");
1055 RETVAL = open(filename, flags, mode);
1063 #ifdef HAS_LOCALECONV
1064 struct lconv *lcbuf;
1066 sv_2mortal((SV*)RETVAL);
1067 if ((lcbuf = localeconv())) {
1068 const struct lconv_offset *strings = lconv_strings;
1069 const struct lconv_offset *integers = lconv_integers;
1070 const char *ptr = (const char *) lcbuf;
1073 const char *value = *((const char **)(ptr + strings->offset));
1075 if (value && *value)
1076 (void) hv_store(RETVAL, strings->name, strlen(strings->name),
1077 newSVpv(value, 0), 0);
1078 } while ((++strings)->name);
1081 const char value = *((const char *)(ptr + integers->offset));
1083 if (value != CHAR_MAX)
1084 (void) hv_store(RETVAL, integers->name,
1085 strlen(integers->name), newSViv(value), 0);
1086 } while ((++integers)->name);
1089 localeconv(); /* A stub to call not_here(). */
1095 setlocale(category, locale = 0)
1101 retval = setlocale(category, locale);
1103 /* Save retval since subsequent setlocale() calls
1104 * may overwrite it. */
1105 RETVAL = savepv(retval);
1106 #ifdef USE_LOCALE_CTYPE
1107 if (category == LC_CTYPE
1109 || category == LC_ALL
1115 if (category == LC_ALL)
1116 newctype = setlocale(LC_CTYPE, NULL);
1120 new_ctype(newctype);
1122 #endif /* USE_LOCALE_CTYPE */
1123 #ifdef USE_LOCALE_COLLATE
1124 if (category == LC_COLLATE
1126 || category == LC_ALL
1132 if (category == LC_ALL)
1133 newcoll = setlocale(LC_COLLATE, NULL);
1137 new_collate(newcoll);
1139 #endif /* USE_LOCALE_COLLATE */
1140 #ifdef USE_LOCALE_NUMERIC
1141 if (category == LC_NUMERIC
1143 || category == LC_ALL
1149 if (category == LC_ALL)
1150 newnum = setlocale(LC_NUMERIC, NULL);
1154 new_numeric(newnum);
1156 #endif /* USE_LOCALE_NUMERIC */
1224 /* (We already know stack is long enough.) */
1225 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1226 PUSHs(sv_2mortal(newSViv(expvar)));
1238 /* (We already know stack is long enough.) */
1239 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1240 PUSHs(sv_2mortal(newSVnv(intvar)));
1243 sigaction(sig, optaction, oldaction = 0)
1246 POSIX::SigAction oldaction
1248 #if defined(WIN32) || defined(NETWARE)
1249 RETVAL = not_here("sigaction");
1251 # This code is really grody because we're trying to make the signal
1252 # interface look beautiful, which is hard.
1256 POSIX__SigAction action;
1257 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
1258 struct sigaction act;
1259 struct sigaction oact;
1263 POSIX__SigSet sigset;
1268 croak("Negative signals are not allowed");
1271 if (sig == 0 && SvPOK(ST(0))) {
1272 const char *s = SvPVX_const(ST(0));
1273 int i = whichsig(s);
1275 if (i < 0 && memEQ(s, "SIG", 3))
1276 i = whichsig(s + 3);
1278 if (ckWARN(WARN_SIGNAL))
1279 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1280 "No such signal: SIG%s", s);
1287 if (sig > NSIG) { /* NSIG - 1 is still okay. */
1288 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1289 "No such signal: %d", sig);
1293 sigsvp = hv_fetch(GvHVn(siggv),
1295 strlen(PL_sig_name[sig]),
1298 /* Check optaction and set action */
1299 if(SvTRUE(optaction)) {
1300 if(sv_isa(optaction, "POSIX::SigAction"))
1301 action = (HV*)SvRV(optaction);
1303 croak("action is not of type POSIX::SigAction");
1309 /* sigaction() is supposed to look atomic. In particular, any
1310 * signal handler invoked during a sigaction() call should
1311 * see either the old or the new disposition, and not something
1312 * in between. We use sigprocmask() to make it so.
1315 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1319 /* Restore signal mask no matter how we exit this block. */
1320 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
1321 SAVEFREESV( osset_sv );
1322 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1324 RETVAL=-1; /* In case both oldaction and action are 0. */
1326 /* Remember old disposition if desired. */
1328 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
1330 croak("Can't supply an oldaction without a HANDLER");
1331 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1332 sv_setsv(*svp, *sigsvp);
1335 sv_setpvs(*svp, "DEFAULT");
1337 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1342 /* Get back the mask. */
1343 svp = hv_fetchs(oldaction, "MASK", TRUE);
1344 if (sv_isa(*svp, "POSIX::SigSet")) {
1345 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
1348 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
1352 *sigset = oact.sa_mask;
1354 /* Get back the flags. */
1355 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
1356 sv_setiv(*svp, oact.sa_flags);
1358 /* Get back whether the old handler used safe signals. */
1359 svp = hv_fetchs(oldaction, "SAFE", TRUE);
1361 /* compare incompatible pointers by casting to integer */
1362 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
1366 /* Safe signals use "csighandler", which vectors through the
1367 PL_sighandlerp pointer when it's safe to do so.
1368 (BTW, "csighandler" is very different from "sighandler".) */
1369 svp = hv_fetchs(action, "SAFE", FALSE);
1373 (*svp && SvTRUE(*svp))
1374 ? PL_csighandlerp : PL_sighandlerp
1377 /* Vector new Perl handler through %SIG.
1378 (The core signal handlers read %SIG to dispatch.) */
1379 svp = hv_fetchs(action, "HANDLER", FALSE);
1381 croak("Can't supply an action without a HANDLER");
1382 sv_setsv(*sigsvp, *svp);
1384 /* This call actually calls sigaction() with almost the
1385 right settings, including appropriate interpretation
1386 of DEFAULT and IGNORE. However, why are we doing
1387 this when we're about to do it again just below? XXX */
1388 SvSETMAGIC(*sigsvp);
1390 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1392 const char *s=SvPVX_const(*svp);
1393 if(strEQ(s,"IGNORE")) {
1394 act.sa_handler = SIG_IGN;
1396 else if(strEQ(s,"DEFAULT")) {
1397 act.sa_handler = SIG_DFL;
1401 /* Set up any desired mask. */
1402 svp = hv_fetchs(action, "MASK", FALSE);
1403 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1404 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
1405 act.sa_mask = *sigset;
1408 sigemptyset(& act.sa_mask);
1410 /* Set up any desired flags. */
1411 svp = hv_fetchs(action, "FLAGS", FALSE);
1412 act.sa_flags = svp ? SvIV(*svp) : 0;
1414 /* Don't worry about cleaning up *sigsvp if this fails,
1415 * because that means we tried to disposition a
1416 * nonblockable signal, in which case *sigsvp is
1417 * essentially meaningless anyway.
1419 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1434 POSIX::SigSet sigset
1438 RETVAL = ix ? sigsuspend(sigset) : sigpending(sigset);
1445 sigprocmask(how, sigset, oldsigset = 0)
1447 POSIX::SigSet sigset = NO_INIT
1448 POSIX::SigSet oldsigset = NO_INIT
1450 if (! SvOK(ST(1))) {
1452 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
1453 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
1455 croak("sigset is not of type POSIX::SigSet");
1458 if (items < 3 || ! SvOK(ST(2))) {
1460 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
1461 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
1463 croak("oldsigset is not of type POSIX::SigSet");
1476 /* RT #98912 - More Microsoft muppetry - failing to actually implemented
1477 the well known documented POSIX behaviour for a POSIX API.
1478 http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
1479 RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
1481 RETVAL = dup2(fd1, fd2);
1487 lseek(fd, offset, whence)
1492 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1493 RETVAL = sizeof(Off_t) > sizeof(IV)
1494 ? newSVnv((NV)pos) : newSViv((IV)pos);
1503 if ((incr = nice(incr)) != -1 || errno == 0) {
1505 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
1507 XPUSHs(sv_2mortal(newSViv(incr)));
1514 if (pipe(fds) != -1) {
1516 PUSHs(sv_2mortal(newSViv(fds[0])));
1517 PUSHs(sv_2mortal(newSViv(fds[1])));
1521 read(fd, buffer, nbytes)
1523 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1527 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1530 SvCUR_set(sv_buffer, RETVAL);
1531 SvPOK_only(sv_buffer);
1532 *SvEND(sv_buffer) = '\0';
1533 SvTAINTED_on(sv_buffer);
1549 tcsetpgrp(fd, pgrp_id)
1558 if (uname(&buf) >= 0) {
1560 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
1561 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
1562 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
1563 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
1564 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
1567 uname((char *) 0); /* A stub to call not_here(). */
1571 write(fd, buffer, nbytes)
1582 RETVAL = newSVpvn("", 0);
1583 SvGROW(RETVAL, L_tmpnam);
1584 len = strlen(tmpnam(SvPV(RETVAL, i)));
1585 SvCUR_set(RETVAL, len);
1598 mbstowcs(s, pwcs, n)
1610 wcstombs(s, pwcs, n)
1632 SET_NUMERIC_LOCAL();
1633 num = strtod(str, &unparsed);
1634 PUSHs(sv_2mortal(newSVnv(num)));
1635 if (GIMME == G_ARRAY) {
1638 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1640 PUSHs(&PL_sv_undef);
1644 strtol(str, base = 0)
1651 num = strtol(str, &unparsed, base);
1652 #if IVSIZE <= LONGSIZE
1653 if (num < IV_MIN || num > IV_MAX)
1654 PUSHs(sv_2mortal(newSVnv((double)num)));
1657 PUSHs(sv_2mortal(newSViv((IV)num)));
1658 if (GIMME == G_ARRAY) {
1661 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1663 PUSHs(&PL_sv_undef);
1667 strtoul(str, base = 0)
1674 num = strtoul(str, &unparsed, base);
1675 #if IVSIZE <= LONGSIZE
1677 PUSHs(sv_2mortal(newSVnv((double)num)));
1680 PUSHs(sv_2mortal(newSViv((IV)num)));
1681 if (GIMME == G_ARRAY) {
1684 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1686 PUSHs(&PL_sv_undef);
1696 char *p = SvPV(src,srclen);
1698 ST(0) = sv_2mortal(newSV(srclen*4+1));
1699 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1700 if (dstlen > srclen) {
1702 SvGROW(ST(0), dstlen);
1703 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1706 SvCUR_set(ST(0), dstlen);
1711 mkfifo(filename, mode)
1718 RETVAL = access(filename, mode);
1720 TAINT_PROPER("mkfifo");
1721 RETVAL = mkfifo(filename, mode);
1733 RETVAL = ix == 1 ? close(fd)
1734 : (ix < 1 ? tcdrain(fd) : dup(fd));
1747 RETVAL = ix == 1 ? tcflush(fd, action)
1748 : (ix < 1 ? tcflow(fd, action) : tcsendbreak(fd, action));
1753 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1769 init_tm(&mytm); /* XXX workaround - see init_tm() in core util.c */
1772 mytm.tm_hour = hour;
1773 mytm.tm_mday = mday;
1775 mytm.tm_year = year;
1776 mytm.tm_wday = wday;
1777 mytm.tm_yday = yday;
1778 mytm.tm_isdst = isdst;
1780 const time_t result = mktime(&mytm);
1781 if (result == (time_t)-1)
1783 else if (result == 0)
1784 sv_setpvn(TARG, "0 but true", 10);
1786 sv_setiv(TARG, (IV)result);
1788 sv_setpv(TARG, asctime(&mytm));
1806 realtime = times( &tms );
1808 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1809 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1810 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1811 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1812 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1815 difftime(time1, time2)
1819 #XXX: if $xsubpp::WantOptimize is always the default
1820 # sv_setpv(TARG, ...) could be used rather than
1821 # ST(0) = sv_2mortal(newSVpv(...))
1823 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1836 char *buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
1838 SV *const sv = sv_newmortal();
1839 sv_usepvn_flags(sv, buf, strlen(buf), SV_HAS_TRAILING_NUL);
1848 strptime(str, fmt, sec=-1, min=-1, hour=-1, mday=-1, mon=-1, year=-1, wday=-1, yday=-1, isdst=-1)
1862 const char *str_c, *str_base;
1864 MAGIC *posmg = NULL;
1868 init_tm(&tm); /* XXX workaround - see init_tm() in core util.c */
1877 tm.tm_isdst = isdst;
1882 str_base = str_c = SvPV_nolen(strref);
1884 if(SvTYPE(strref) >= SVt_PVMG && SvMAGIC(strref))
1885 posmg = mg_find(strref, PERL_MAGIC_regex_global);
1888 str_c += posmg->mg_len;
1891 str_c = SvPV_nolen(str);
1894 remains = strptime(str_c, SvPV_nolen(fmt), &tm);
1899 if(remains[0] && !strref)
1900 /* leftovers - without ref we can't signal this so this is a failure */
1905 posmg = sv_magicext(strref, NULL, PERL_MAGIC_regex_global,
1906 &PL_vtbl_mglob, NULL, 0);
1907 posmg->mg_len = remains - str_base;
1910 if(tm.tm_mday > -1 && tm.tm_mon > -1 && tm.tm_year > -1) {
1911 if(mktime(&tm) == (time_t)-1)
1916 PUSHs(sv_2mortal(newSViv(tm.tm_sec)));
1917 PUSHs(sv_2mortal(newSViv(tm.tm_min)));
1918 PUSHs(sv_2mortal(newSViv(tm.tm_hour)));
1919 PUSHs(sv_2mortal(newSViv(tm.tm_mday)));
1920 PUSHs(sv_2mortal(newSViv(tm.tm_mon)));
1921 PUSHs(sv_2mortal(newSViv(tm.tm_year)));
1922 PUSHs(sv_2mortal(newSViv(tm.tm_wday)));
1923 PUSHs(sv_2mortal(newSViv(tm.tm_yday)));
1924 PUSHs(sv_2mortal(newSViv(tm.tm_isdst)));
1936 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
1937 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
1943 #ifdef HAS_CTERMID_R
1944 s = (char *) safemalloc((size_t) L_ctermid);
1946 RETVAL = ctermid(s);
1950 #ifdef HAS_CTERMID_R
1959 RETVAL = cuserid(s);
1962 not_here("cuserid");
1973 pathconf(filename, name)
1984 unsigned int seconds
1986 RETVAL = PerlProc_sleep(seconds);
1997 PL_egid = getegid();
2008 PL_euid = geteuid();
2026 XSprePUSH; PUSHTARG;
2030 lchown(uid, gid, path)
2036 /* yes, the order of arguments is different,
2037 * but consistent with CORE::chown() */
2038 RETVAL = lchown(path, uid, gid);
2040 RETVAL = not_here("lchown");