6 * Ideally this should be somewhere down in the includes
7 * but putting it in other places is giving compiler errors.
8 * Also here I am unable to check for HAS_UNAME since it wouldn't have
9 * yet come into the file at this stage - sgp 18th Oct 2000
11 #include <sys/utsname.h>
14 #define PERL_NO_GET_CONTEXT
17 #define PERLIO_NOT_STDIO 1
20 #if defined(PERL_IMPLICIT_SYS)
24 # define open PerlLIO_open3
27 #ifdef I_DIRENT /* XXX maybe better to just rely on perl.h? */
54 /* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
55 metaconfig for future extension writers. We don't use them in POSIX.
56 (This is really sneaky :-) --AD
58 #if defined(I_TERMIOS)
68 #include <sys/types.h>
76 # if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
77 extern char *tzname[];
80 #if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
81 char *tzname[] = { "" , "" };
85 #ifndef PERL_UNUSED_DECL
87 # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
88 # define PERL_UNUSED_DECL
90 # define PERL_UNUSED_DECL __attribute__((unused))
93 # define PERL_UNUSED_DECL
98 #define dNOOP extern int Perl___notused PERL_UNUSED_DECL
105 #if defined(__VMS) && !defined(__POSIX_SOURCE)
106 # include <libdef.h> /* LIB$_INVARG constant */
107 # include <lib$routines.h> /* prototype for lib$ediv() */
108 # include <starlet.h> /* prototype for sys$gettim() */
109 # if DECC_VERSION < 50000000
110 # define pid_t int /* old versions of DECC miss this in types.h */
114 # define mkfifo(a,b) (not_here("mkfifo"),-1)
115 # define tzset() not_here("tzset")
117 #if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
118 # define HAS_TZNAME /* shows up in VMS 7.0 or Dec C 5.6 */
119 # include <utsname.h>
120 # endif /* __VMS_VER >= 70000000 or Dec C 5.6 */
122 /* The POSIX notion of ttyname() is better served by getname() under VMS */
123 static char ttnambuf[64];
124 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
126 /* The non-POSIX CRTL times() has void return type, so we just get the
127 current time directly */
128 clock_t vms_times(struct tms *bufptr) {
131 /* Get wall time and convert to 10 ms intervals to
132 * produce the return value that the POSIX standard expects */
133 # if defined(__DECC) && defined (__ALPHA)
136 _ckvmssts(sys$gettim(&vmstime));
138 retval = vmstime & 0x7fffffff;
140 /* (Older hw or ccs don't have an atomic 64-bit type, so we
141 * juggle 32-bit ints (and a float) to produce a time_t result
142 * with minimal loss of information.) */
143 long int vmstime[2],remainder,divisor = 100000;
144 _ckvmssts(sys$gettim((unsigned long int *)vmstime));
145 vmstime[1] &= 0x7fff; /* prevent overflow in EDIV */
146 _ckvmssts(lib$ediv(&divisor,vmstime,(long int *)&retval,&remainder));
148 /* Fill in the struct tms using the CRTL routine . . .*/
149 times((tbuffer_t *)bufptr);
150 return (clock_t) retval;
152 # define times(t) vms_times(t)
154 #if defined (__CYGWIN__)
155 # define tzname _tzname
157 #if defined (WIN32) || defined (NETWARE)
159 # define mkfifo(a,b) not_here("mkfifo")
160 # define ttyname(a) (char*)not_here("ttyname")
161 # define sigset_t long
164 # define mode_t short
167 # define mode_t short
169 # define tzset() not_here("tzset")
171 # ifndef _POSIX_OPEN_MAX
172 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
175 # define sigaction(a,b,c) not_here("sigaction")
176 # define sigpending(a) not_here("sigpending")
177 # define sigprocmask(a,b,c) not_here("sigprocmask")
178 # define sigsuspend(a) not_here("sigsuspend")
179 # define sigemptyset(a) not_here("sigemptyset")
180 # define sigaddset(a,b) not_here("sigaddset")
181 # define sigdelset(a,b) not_here("sigdelset")
182 # define sigfillset(a) not_here("sigfillset")
183 # define sigismember(a,b) not_here("sigismember")
187 # define setuid(a) not_here("setuid")
188 # define setgid(a) not_here("setgid")
194 # define mkfifo(a,b) not_here("mkfifo")
195 # else /* !( defined OS2 ) */
197 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
200 # endif /* !HAS_MKFIFO */
205 # include <sys/times.h>
207 # include <sys/utsname.h>
209 # include <sys/wait.h>
213 #endif /* WIN32 || NETWARE */
217 /* Perl on Windows assigns WSAGetLastError() return values to errno
218 * (in win32/win32sck.c). Therefore we need to map these values
219 * back to standard symbolic names, but only for those names having
220 * no existing value or an existing value >= 100. (VC++ 2010 defines
221 * a group of names with values >= 100 in its errno.h which we *do*
222 * need to redefine.) The Errno.pm module does a similar mapping.
227 # define EWOULDBLOCK WSAEWOULDBLOCK
231 # define EINPROGRESS WSAEINPROGRESS
235 # define EALREADY WSAEALREADY
239 # define ENOTSOCK WSAENOTSOCK
243 # define EDESTADDRREQ WSAEDESTADDRREQ
247 # define EMSGSIZE WSAEMSGSIZE
251 # define EPROTOTYPE WSAEPROTOTYPE
255 # define ENOPROTOOPT WSAENOPROTOOPT
256 # ifdef EPROTONOSUPPORT
257 # undef EPROTONOSUPPORT
259 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
260 # ifdef ESOCKTNOSUPPORT
261 # undef ESOCKTNOSUPPORT
263 # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
267 # define EOPNOTSUPP WSAEOPNOTSUPP
271 # define EPFNOSUPPORT WSAEPFNOSUPPORT
275 # define EAFNOSUPPORT WSAEAFNOSUPPORT
279 # define EADDRINUSE WSAEADDRINUSE
280 # ifdef EADDRNOTAVAIL
281 # undef EADDRNOTAVAIL
283 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
287 # define ENETDOWN WSAENETDOWN
291 # define ENETUNREACH WSAENETUNREACH
295 # define ENETRESET WSAENETRESET
299 # define ECONNABORTED WSAECONNABORTED
303 # define ECONNRESET WSAECONNRESET
307 # define ENOBUFS WSAENOBUFS
311 # define EISCONN WSAEISCONN
315 # define ENOTCONN WSAENOTCONN
319 # define ESHUTDOWN WSAESHUTDOWN
323 # define ETOOMANYREFS WSAETOOMANYREFS
327 # define ETIMEDOUT WSAETIMEDOUT
331 # define ECONNREFUSED WSAECONNREFUSED
335 # define ELOOP WSAELOOP
339 # define EHOSTDOWN WSAEHOSTDOWN
343 # define EHOSTUNREACH WSAEHOSTUNREACH
347 # define EPROCLIM WSAEPROCLIM
351 # define EUSERS WSAEUSERS
355 # define EDQUOT WSAEDQUOT
359 # define ESTALE WSAESTALE
363 # define EREMOTE WSAEREMOTE
367 # define EDISCON WSAEDISCON
371 typedef long SysRetLong;
372 typedef sigset_t* POSIX__SigSet;
373 typedef HV* POSIX__SigAction;
375 typedef struct termios* POSIX__Termios;
376 #else /* Define termios types to int, and call not_here for the functions.*/
377 #define POSIX__Termios int
381 #define cfgetispeed(x) not_here("cfgetispeed")
382 #define cfgetospeed(x) not_here("cfgetospeed")
383 #define tcdrain(x) not_here("tcdrain")
384 #define tcflush(x,y) not_here("tcflush")
385 #define tcsendbreak(x,y) not_here("tcsendbreak")
386 #define cfsetispeed(x,y) not_here("cfsetispeed")
387 #define cfsetospeed(x,y) not_here("cfsetospeed")
388 #define ctermid(x) (char *) not_here("ctermid")
389 #define tcflow(x,y) not_here("tcflow")
390 #define tcgetattr(x,y) not_here("tcgetattr")
391 #define tcsetattr(x,y,z) not_here("tcsetattr")
394 /* Possibly needed prototypes */
396 double strtod (const char *, char **);
397 long strtol (const char *, char **, int);
398 unsigned long strtoul (const char *, char **, int);
403 #define difftime(a,b) not_here("difftime")
406 #ifndef HAS_FPATHCONF
407 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
410 #define mktime(a) not_here("mktime")
413 #define nice(a) not_here("nice")
416 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
419 #define sysconf(n) (SysRetLong) not_here("sysconf")
422 #define readlink(a,b,c) not_here("readlink")
425 #define setpgid(a,b) not_here("setpgid")
428 #define setsid() not_here("setsid")
431 #define strcoll(s1,s2) not_here("strcoll")
434 #define strtod(s1,s2) not_here("strtod")
437 #define strtol(s1,s2,b) not_here("strtol")
440 #define strtoul(s1,s2,b) not_here("strtoul")
443 #define strxfrm(s1,s2,n) not_here("strxfrm")
445 #ifndef HAS_TCGETPGRP
446 #define tcgetpgrp(a) not_here("tcgetpgrp")
448 #ifndef HAS_TCSETPGRP
449 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
453 #define times(a) not_here("times")
457 #define uname(a) not_here("uname")
460 #define waitpid(a,b,c) not_here("waitpid")
465 #define mblen(a,b) not_here("mblen")
469 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
472 #define mbtowc(pwc, s, n) not_here("mbtowc")
475 #define wcstombs(s, pwcs, n) not_here("wcstombs")
478 #define wctomb(s, wchar) not_here("wcstombs")
480 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
481 /* If we don't have these functions, then we wouldn't have gotten a typedef
482 for wchar_t, the wide character type. Defining wchar_t allows the
483 functions referencing it to compile. Its actual type is then meaningless,
484 since without the above functions, all sections using it end up calling
485 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
491 #ifndef HAS_LOCALECONV
492 #define localeconv() not_here("localeconv")
495 #ifdef HAS_LONG_DOUBLE
496 # if LONG_DOUBLESIZE > NVSIZE
497 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
501 #ifndef HAS_LONG_DOUBLE
513 /* Background: in most systems the low byte of the wait status
514 * is the signal (the lowest 7 bits) and the coredump flag is
515 * the eight bit, and the second lowest byte is the exit status.
516 * BeOS bucks the trend and has the bytes in different order.
517 * See beos/beos.c for how the reality is bent even in BeOS
518 * to follow the traditional. However, to make the POSIX
519 * wait W*() macros to work in BeOS, we need to unbend the
520 * reality back in place. --jhi */
521 /* In actual fact the code below is to blame here. Perl has an internal
522 * representation of the exit status ($?), which it re-composes from the
523 * OS's representation using the W*() POSIX macros. The code below
524 * incorrectly uses the W*() macros on the internal representation,
525 * which fails for OSs that have a different representation (namely BeOS
526 * and Haiku). WMUNGE() is a hack that converts the internal
527 * representation into the OS specific one, so that the W*() macros work
528 * as expected. The better solution would be not to use the W*() macros
529 * in the first place, though. -- Ingo Weinhold
531 #if defined(__BEOS__) || defined(__HAIKU__)
532 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
534 # define WMUNGE(x) (x)
538 not_here(const char *s)
540 croak("POSIX::%s not implemented on this architecture", s);
544 #include "const-c.inc"
547 restore_sigmask(pTHX_ SV *osset_sv)
549 /* Fortunately, restoring the signal mask can't fail, because
550 * there's nothing we can do about it if it does -- we're not
551 * supposed to return -1 from sigaction unless the disposition
554 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
555 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
559 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
560 SV *const t = newSVrv(rv, packname);
561 void *const p = sv_grow(t, size + 1);
571 * (1) The CRT maintains its own copy of the environment, separate from
574 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
575 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
578 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
579 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
582 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
583 * calls CRT tzset(), but only the first time it is called, and in turn
584 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
585 * local copy of the environment and hence gets the original setting as
586 * perl never updates the CRT copy when assigning to $ENV{TZ}.
588 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
589 * putenv() to update the CRT copy of the environment (if it is different)
590 * whenever we're about to call tzset().
592 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
595 * (a) Each interpreter has its own copy of the environment inside the
596 * perlhost structure. That allows applications that host multiple
597 * independent Perl interpreters to isolate environment changes from
598 * each other. (This is similar to how the perlhost mechanism keeps a
599 * separate working directory for each Perl interpreter, so that calling
600 * chdir() will not affect other interpreters.)
602 * (b) Only the first Perl interpreter instantiated within a process will
603 * "write through" environment changes to the process environment.
605 * (c) Even the primary Perl interpreter won't update the CRT copy of the
606 * the environment, only the Win32API copy (it calls win32_putenv()).
608 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
609 * sense to only update the process environment when inside the main
610 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
611 * from here so we'll just have to check PL_curinterp instead.
613 * Therefore, we can simply #undef getenv() and putenv() so that those names
614 * always refer to the CRT functions, and explicitly call win32_getenv() to
615 * access perl's %ENV.
617 * We also #undef malloc() and free() to be sure we are using the CRT
618 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
619 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
620 * when the Perl interpreter is being destroyed so we'd end up with a pointer
621 * into deallocated memory in environ[] if a program embedding a Perl
622 * interpreter continues to operate even after the main Perl interpreter has
625 * Note that we don't free() the malloc()ed memory unless and until we call
626 * malloc() again ourselves because the CRT putenv() function simply puts its
627 * pointer argument into the environ[] array (it doesn't make a copy of it)
628 * so this memory must otherwise be leaked.
637 fix_win32_tzenv(void)
639 static char* oldenv = NULL;
641 const char* perl_tz_env = win32_getenv("TZ");
642 const char* crt_tz_env = getenv("TZ");
643 if (perl_tz_env == NULL)
645 if (crt_tz_env == NULL)
647 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
648 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
649 if (newenv != NULL) {
650 sprintf(newenv, "TZ=%s", perl_tz_env);
662 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
663 * This code is duplicated in the Time-Piece module, so any changes made here
664 * should be made there too.
670 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
671 if (PL_curinterp == aTHX)
678 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
681 new(packname = "POSIX::SigSet", ...)
682 const char * packname
687 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
691 for (i = 1; i < items; i++)
692 sigaddset(s, SvIV(ST(i)));
703 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
713 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
718 sigismember(sigset, sig)
722 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
725 new(packname = "POSIX::Termios", ...)
726 const char * packname
730 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
731 sizeof(struct termios), packname);
732 /* The previous implementation stored a pointer to an uninitialised
733 struct termios. Seems safer to initialise it, particularly as
734 this implementation exposes the struct to prying from perl-space.
736 memset(p, 0, 1 + sizeof(struct termios));
744 getattr(termios_ref, fd = 0)
745 POSIX::Termios termios_ref
748 RETVAL = tcgetattr(fd, termios_ref);
753 setattr(termios_ref, fd = 0, optional_actions = 0)
754 POSIX::Termios termios_ref
758 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
763 getispeed(termios_ref)
764 POSIX::Termios termios_ref
768 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
773 getiflag(termios_ref)
774 POSIX::Termios termios_ref
780 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
783 RETVAL = termios_ref->c_iflag;
786 RETVAL = termios_ref->c_oflag;
789 RETVAL = termios_ref->c_cflag;
792 RETVAL = termios_ref->c_lflag;
796 not_here(GvNAME(CvGV(cv)));
803 getcc(termios_ref, ccix)
804 POSIX::Termios termios_ref
807 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
809 croak("Bad getcc subscript");
810 RETVAL = termios_ref->c_cc[ccix];
819 setispeed(termios_ref, speed)
820 POSIX::Termios termios_ref
826 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
831 setiflag(termios_ref, flag)
832 POSIX::Termios termios_ref
839 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
842 termios_ref->c_iflag = flag;
845 termios_ref->c_oflag = flag;
848 termios_ref->c_cflag = flag;
851 termios_ref->c_lflag = flag;
855 not_here(GvNAME(CvGV(cv)));
859 setcc(termios_ref, ccix, cc)
860 POSIX::Termios termios_ref
864 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
866 croak("Bad setcc subscript");
867 termios_ref->c_cc[ccix] = cc;
873 MODULE = POSIX PACKAGE = POSIX
875 INCLUDE: const-xs.inc
882 POSIX::WIFSIGNALED = 2
883 POSIX::WIFSTOPPED = 3
887 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
888 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
889 RETVAL = 0; /* Silence compilers that notice this, but don't realise
890 that not_here() can't return. */
895 RETVAL = WEXITSTATUS(WMUNGE(status));
897 not_here("WEXITSTATUS");
902 RETVAL = WIFEXITED(WMUNGE(status));
904 not_here("WIFEXITED");
909 RETVAL = WIFSIGNALED(WMUNGE(status));
911 not_here("WIFSIGNALED");
916 RETVAL = WIFSTOPPED(WMUNGE(status));
918 not_here("WIFSTOPPED");
923 RETVAL = WSTOPSIG(WMUNGE(status));
925 not_here("WSTOPSIG");
930 RETVAL = WTERMSIG(WMUNGE(status));
932 not_here("WTERMSIG");
936 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
947 unsigned char *s = (unsigned char *) SvPV(charstring, len);
948 unsigned char *e = s + len;
949 for (RETVAL = 1; RETVAL && s < e; s++)
961 unsigned char *s = (unsigned char *) SvPV(charstring, len);
962 unsigned char *e = s + len;
963 for (RETVAL = 1; RETVAL && s < e; s++)
975 unsigned char *s = (unsigned char *) SvPV(charstring, len);
976 unsigned char *e = s + len;
977 for (RETVAL = 1; RETVAL && s < e; s++)
989 unsigned char *s = (unsigned char *) SvPV(charstring, len);
990 unsigned char *e = s + len;
991 for (RETVAL = 1; RETVAL && s < e; s++)
1003 unsigned char *s = (unsigned char *) SvPV(charstring, len);
1004 unsigned char *e = s + len;
1005 for (RETVAL = 1; RETVAL && s < e; s++)
1017 unsigned char *s = (unsigned char *) SvPV(charstring, len);
1018 unsigned char *e = s + len;
1019 for (RETVAL = 1; RETVAL && s < e; s++)
1031 unsigned char *s = (unsigned char *) SvPV(charstring, len);
1032 unsigned char *e = s + len;
1033 for (RETVAL = 1; RETVAL && s < e; s++)
1045 unsigned char *s = (unsigned char *) SvPV(charstring, len);
1046 unsigned char *e = s + len;
1047 for (RETVAL = 1; RETVAL && s < e; s++)
1059 unsigned char *s = (unsigned char *) SvPV(charstring, len);
1060 unsigned char *e = s + len;
1061 for (RETVAL = 1; RETVAL && s < e; s++)
1073 unsigned char *s = (unsigned char *) SvPV(charstring, len);
1074 unsigned char *e = s + len;
1075 for (RETVAL = 1; RETVAL && s < e; s++)
1082 isxdigit(charstring)
1087 unsigned char *s = (unsigned char *) SvPV(charstring, len);
1088 unsigned char *e = s + len;
1089 for (RETVAL = 1; RETVAL && s < e; s++)
1096 open(filename, flags = O_RDONLY, mode = 0666)
1101 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
1102 TAINT_PROPER("open");
1103 RETVAL = open(filename, flags, mode);
1111 #ifdef HAS_LOCALECONV
1112 struct lconv *lcbuf;
1114 sv_2mortal((SV*)RETVAL);
1115 if ((lcbuf = localeconv())) {
1117 if (lcbuf->decimal_point && *lcbuf->decimal_point)
1118 (void) hv_store(RETVAL, "decimal_point", 13,
1119 newSVpv(lcbuf->decimal_point, 0), 0);
1120 if (lcbuf->thousands_sep && *lcbuf->thousands_sep)
1121 (void) hv_store(RETVAL, "thousands_sep", 13,
1122 newSVpv(lcbuf->thousands_sep, 0), 0);
1123 #ifndef NO_LOCALECONV_GROUPING
1124 if (lcbuf->grouping && *lcbuf->grouping)
1125 (void) hv_store(RETVAL, "grouping", 8,
1126 newSVpv(lcbuf->grouping, 0), 0);
1128 if (lcbuf->int_curr_symbol && *lcbuf->int_curr_symbol)
1129 (void) hv_store(RETVAL, "int_curr_symbol", 15,
1130 newSVpv(lcbuf->int_curr_symbol, 0), 0);
1131 if (lcbuf->currency_symbol && *lcbuf->currency_symbol)
1132 (void) hv_store(RETVAL, "currency_symbol", 15,
1133 newSVpv(lcbuf->currency_symbol, 0), 0);
1134 if (lcbuf->mon_decimal_point && *lcbuf->mon_decimal_point)
1135 (void) hv_store(RETVAL, "mon_decimal_point", 17,
1136 newSVpv(lcbuf->mon_decimal_point, 0), 0);
1137 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
1138 if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
1139 (void) hv_store(RETVAL, "mon_thousands_sep", 17,
1140 newSVpv(lcbuf->mon_thousands_sep, 0), 0);
1142 #ifndef NO_LOCALECONV_MON_GROUPING
1143 if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
1144 (void) hv_store(RETVAL, "mon_grouping", 12,
1145 newSVpv(lcbuf->mon_grouping, 0), 0);
1147 if (lcbuf->positive_sign && *lcbuf->positive_sign)
1148 (void) hv_store(RETVAL, "positive_sign", 13,
1149 newSVpv(lcbuf->positive_sign, 0), 0);
1150 if (lcbuf->negative_sign && *lcbuf->negative_sign)
1151 (void) hv_store(RETVAL, "negative_sign", 13,
1152 newSVpv(lcbuf->negative_sign, 0), 0);
1154 if (lcbuf->int_frac_digits != CHAR_MAX)
1155 (void) hv_store(RETVAL, "int_frac_digits", 15,
1156 newSViv(lcbuf->int_frac_digits), 0);
1157 if (lcbuf->frac_digits != CHAR_MAX)
1158 (void) hv_store(RETVAL, "frac_digits", 11,
1159 newSViv(lcbuf->frac_digits), 0);
1160 if (lcbuf->p_cs_precedes != CHAR_MAX)
1161 (void) hv_store(RETVAL, "p_cs_precedes", 13,
1162 newSViv(lcbuf->p_cs_precedes), 0);
1163 if (lcbuf->p_sep_by_space != CHAR_MAX)
1164 (void) hv_store(RETVAL, "p_sep_by_space", 14,
1165 newSViv(lcbuf->p_sep_by_space), 0);
1166 if (lcbuf->n_cs_precedes != CHAR_MAX)
1167 (void) hv_store(RETVAL, "n_cs_precedes", 13,
1168 newSViv(lcbuf->n_cs_precedes), 0);
1169 if (lcbuf->n_sep_by_space != CHAR_MAX)
1170 (void) hv_store(RETVAL, "n_sep_by_space", 14,
1171 newSViv(lcbuf->n_sep_by_space), 0);
1172 if (lcbuf->p_sign_posn != CHAR_MAX)
1173 (void) hv_store(RETVAL, "p_sign_posn", 11,
1174 newSViv(lcbuf->p_sign_posn), 0);
1175 if (lcbuf->n_sign_posn != CHAR_MAX)
1176 (void) hv_store(RETVAL, "n_sign_posn", 11,
1177 newSViv(lcbuf->n_sign_posn), 0);
1180 localeconv(); /* A stub to call not_here(). */
1186 setlocale(category, locale = 0)
1192 retval = setlocale(category, locale);
1194 /* Save retval since subsequent setlocale() calls
1195 * may overwrite it. */
1196 RETVAL = savepv(retval);
1197 #ifdef USE_LOCALE_CTYPE
1198 if (category == LC_CTYPE
1200 || category == LC_ALL
1206 if (category == LC_ALL)
1207 newctype = setlocale(LC_CTYPE, NULL);
1211 new_ctype(newctype);
1213 #endif /* USE_LOCALE_CTYPE */
1214 #ifdef USE_LOCALE_COLLATE
1215 if (category == LC_COLLATE
1217 || category == LC_ALL
1223 if (category == LC_ALL)
1224 newcoll = setlocale(LC_COLLATE, NULL);
1228 new_collate(newcoll);
1230 #endif /* USE_LOCALE_COLLATE */
1231 #ifdef USE_LOCALE_NUMERIC
1232 if (category == LC_NUMERIC
1234 || category == LC_ALL
1240 if (category == LC_ALL)
1241 newnum = setlocale(LC_NUMERIC, NULL);
1245 new_numeric(newnum);
1247 #endif /* USE_LOCALE_NUMERIC */
1291 /* (We already know stack is long enough.) */
1292 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1293 PUSHs(sv_2mortal(newSViv(expvar)));
1309 /* (We already know stack is long enough.) */
1310 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1311 PUSHs(sv_2mortal(newSVnv(intvar)));
1326 sigaction(sig, optaction, oldaction = 0)
1329 POSIX::SigAction oldaction
1331 #if defined(WIN32) || defined(NETWARE)
1332 RETVAL = not_here("sigaction");
1334 # This code is really grody because we're trying to make the signal
1335 # interface look beautiful, which is hard.
1339 POSIX__SigAction action;
1340 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
1341 struct sigaction act;
1342 struct sigaction oact;
1346 POSIX__SigSet sigset;
1351 croak("Negative signals are not allowed");
1354 if (sig == 0 && SvPOK(ST(0))) {
1355 const char *s = SvPVX_const(ST(0));
1356 int i = whichsig(s);
1358 if (i < 0 && memEQ(s, "SIG", 3))
1359 i = whichsig(s + 3);
1361 if (ckWARN(WARN_SIGNAL))
1362 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1363 "No such signal: SIG%s", s);
1370 if (sig > NSIG) { /* NSIG - 1 is still okay. */
1371 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1372 "No such signal: %d", sig);
1376 sigsvp = hv_fetch(GvHVn(siggv),
1378 strlen(PL_sig_name[sig]),
1381 /* Check optaction and set action */
1382 if(SvTRUE(optaction)) {
1383 if(sv_isa(optaction, "POSIX::SigAction"))
1384 action = (HV*)SvRV(optaction);
1386 croak("action is not of type POSIX::SigAction");
1392 /* sigaction() is supposed to look atomic. In particular, any
1393 * signal handler invoked during a sigaction() call should
1394 * see either the old or the new disposition, and not something
1395 * in between. We use sigprocmask() to make it so.
1398 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1402 /* Restore signal mask no matter how we exit this block. */
1403 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
1404 SAVEFREESV( osset_sv );
1405 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1407 RETVAL=-1; /* In case both oldaction and action are 0. */
1409 /* Remember old disposition if desired. */
1411 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
1413 croak("Can't supply an oldaction without a HANDLER");
1414 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1415 sv_setsv(*svp, *sigsvp);
1418 sv_setpvs(*svp, "DEFAULT");
1420 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1425 /* Get back the mask. */
1426 svp = hv_fetchs(oldaction, "MASK", TRUE);
1427 if (sv_isa(*svp, "POSIX::SigSet")) {
1428 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
1431 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
1435 *sigset = oact.sa_mask;
1437 /* Get back the flags. */
1438 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
1439 sv_setiv(*svp, oact.sa_flags);
1441 /* Get back whether the old handler used safe signals. */
1442 svp = hv_fetchs(oldaction, "SAFE", TRUE);
1444 /* compare incompatible pointers by casting to integer */
1445 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
1449 /* Safe signals use "csighandler", which vectors through the
1450 PL_sighandlerp pointer when it's safe to do so.
1451 (BTW, "csighandler" is very different from "sighandler".) */
1452 svp = hv_fetchs(action, "SAFE", FALSE);
1456 (*svp && SvTRUE(*svp))
1457 ? PL_csighandlerp : PL_sighandlerp
1460 /* Vector new Perl handler through %SIG.
1461 (The core signal handlers read %SIG to dispatch.) */
1462 svp = hv_fetchs(action, "HANDLER", FALSE);
1464 croak("Can't supply an action without a HANDLER");
1465 sv_setsv(*sigsvp, *svp);
1467 /* This call actually calls sigaction() with almost the
1468 right settings, including appropriate interpretation
1469 of DEFAULT and IGNORE. However, why are we doing
1470 this when we're about to do it again just below? XXX */
1471 SvSETMAGIC(*sigsvp);
1473 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1475 const char *s=SvPVX_const(*svp);
1476 if(strEQ(s,"IGNORE")) {
1477 act.sa_handler = SIG_IGN;
1479 else if(strEQ(s,"DEFAULT")) {
1480 act.sa_handler = SIG_DFL;
1484 /* Set up any desired mask. */
1485 svp = hv_fetchs(action, "MASK", FALSE);
1486 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1487 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
1488 act.sa_mask = *sigset;
1491 sigemptyset(& act.sa_mask);
1493 /* Set up any desired flags. */
1494 svp = hv_fetchs(action, "FLAGS", FALSE);
1495 act.sa_flags = svp ? SvIV(*svp) : 0;
1497 /* Don't worry about cleaning up *sigsvp if this fails,
1498 * because that means we tried to disposition a
1499 * nonblockable signal, in which case *sigsvp is
1500 * essentially meaningless anyway.
1502 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1517 POSIX::SigSet sigset
1520 sigprocmask(how, sigset, oldsigset = 0)
1522 POSIX::SigSet sigset = NO_INIT
1523 POSIX::SigSet oldsigset = NO_INIT
1525 if (! SvOK(ST(1))) {
1527 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
1528 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
1530 croak("sigset is not of type POSIX::SigSet");
1533 if (items < 3 || ! SvOK(ST(2))) {
1535 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
1536 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
1538 croak("oldsigset is not of type POSIX::SigSet");
1542 sigsuspend(signal_mask)
1543 POSIX::SigSet signal_mask
1563 lseek(fd, offset, whence)
1568 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1569 RETVAL = sizeof(Off_t) > sizeof(IV)
1570 ? newSVnv((NV)pos) : newSViv((IV)pos);
1579 if ((incr = nice(incr)) != -1 || errno == 0) {
1581 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
1583 XPUSHs(sv_2mortal(newSViv(incr)));
1590 if (pipe(fds) != -1) {
1592 PUSHs(sv_2mortal(newSViv(fds[0])));
1593 PUSHs(sv_2mortal(newSViv(fds[1])));
1597 read(fd, buffer, nbytes)
1599 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1603 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1606 SvCUR_set(sv_buffer, RETVAL);
1607 SvPOK_only(sv_buffer);
1608 *SvEND(sv_buffer) = '\0';
1609 SvTAINTED_on(sv_buffer);
1625 tcsetpgrp(fd, pgrp_id)
1634 if (uname(&buf) >= 0) {
1636 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
1637 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
1638 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
1639 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
1640 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
1643 uname((char *) 0); /* A stub to call not_here(). */
1647 write(fd, buffer, nbytes)
1658 RETVAL = newSVpvn("", 0);
1659 SvGROW(RETVAL, L_tmpnam);
1660 len = strlen(tmpnam(SvPV(RETVAL, i)));
1661 SvCUR_set(RETVAL, len);
1674 mbstowcs(s, pwcs, n)
1686 wcstombs(s, pwcs, n)
1708 SET_NUMERIC_LOCAL();
1709 num = strtod(str, &unparsed);
1710 PUSHs(sv_2mortal(newSVnv(num)));
1711 if (GIMME == G_ARRAY) {
1714 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1716 PUSHs(&PL_sv_undef);
1720 strtol(str, base = 0)
1727 num = strtol(str, &unparsed, base);
1728 #if IVSIZE <= LONGSIZE
1729 if (num < IV_MIN || num > IV_MAX)
1730 PUSHs(sv_2mortal(newSVnv((double)num)));
1733 PUSHs(sv_2mortal(newSViv((IV)num)));
1734 if (GIMME == G_ARRAY) {
1737 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1739 PUSHs(&PL_sv_undef);
1743 strtoul(str, base = 0)
1750 num = strtoul(str, &unparsed, base);
1751 #if IVSIZE <= LONGSIZE
1753 PUSHs(sv_2mortal(newSVnv((double)num)));
1756 PUSHs(sv_2mortal(newSViv((IV)num)));
1757 if (GIMME == G_ARRAY) {
1760 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1762 PUSHs(&PL_sv_undef);
1772 char *p = SvPV(src,srclen);
1774 ST(0) = sv_2mortal(newSV(srclen*4+1));
1775 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1776 if (dstlen > srclen) {
1778 SvGROW(ST(0), dstlen);
1779 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1782 SvCUR_set(ST(0), dstlen);
1787 mkfifo(filename, mode)
1791 TAINT_PROPER("mkfifo");
1792 RETVAL = mkfifo(filename, mode);
1808 tcflush(fd, queue_selector)
1813 tcsendbreak(fd, duration)
1818 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1831 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1834 mytm.tm_hour = hour;
1835 mytm.tm_mday = mday;
1837 mytm.tm_year = year;
1838 mytm.tm_wday = wday;
1839 mytm.tm_yday = yday;
1840 mytm.tm_isdst = isdst;
1841 RETVAL = asctime(&mytm);
1858 realtime = times( &tms );
1860 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1861 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1862 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1863 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1864 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1867 difftime(time1, time2)
1872 mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1885 init_tm(&mytm); /* XXX workaround - see init_tm() above */
1888 mytm.tm_hour = hour;
1889 mytm.tm_mday = mday;
1891 mytm.tm_year = year;
1892 mytm.tm_wday = wday;
1893 mytm.tm_yday = yday;
1894 mytm.tm_isdst = isdst;
1895 RETVAL = (SysRetLong) mktime(&mytm);
1900 #XXX: if $xsubpp::WantOptimize is always the default
1901 # sv_setpv(TARG, ...) could be used rather than
1902 # ST(0) = sv_2mortal(newSVpv(...))
1904 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1917 char *buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
1919 SV *const sv = sv_newmortal();
1920 sv_usepvn_flags(sv, buf, strlen(buf), SV_HAS_TRAILING_NUL);
1937 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
1938 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
1941 access(filename, mode)
1949 #ifdef HAS_CTERMID_R
1950 s = (char *) safemalloc((size_t) L_ctermid);
1952 RETVAL = ctermid(s);
1956 #ifdef HAS_CTERMID_R
1965 RETVAL = cuserid(s);
1968 not_here("cuserid");
1979 pathconf(filename, name)
1993 PL_egid = getegid();
2004 PL_euid = geteuid();
2022 XSprePUSH; PUSHTARG;
2026 lchown(uid, gid, path)
2032 /* yes, the order of arguments is different,
2033 * but consistent with CORE::chown() */
2034 RETVAL = lchown(path, uid, gid);
2036 RETVAL = not_here("lchown");