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? */
32 #include <sys/errno2.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)
93 # define mkfifo(a,b) (not_here("mkfifo"),-1)
95 /* The POSIX notion of ttyname() is better served by getname() under VMS */
96 static char ttnambuf[64];
97 # define ttyname(fd) (isatty(fd) > 0 ? getname(fd,ttnambuf,0) : NULL)
100 #if defined (__CYGWIN__)
101 # define tzname _tzname
103 #if defined (WIN32) || defined (NETWARE)
105 # define mkfifo(a,b) not_here("mkfifo")
106 # define ttyname(a) (char*)not_here("ttyname")
107 # define sigset_t long
110 # define mode_t short
113 # define mode_t short
115 # define tzset() not_here("tzset")
117 # ifndef _POSIX_OPEN_MAX
118 # define _POSIX_OPEN_MAX FOPEN_MAX /* XXX bogus ? */
121 # define sigaction(a,b,c) not_here("sigaction")
122 # define sigpending(a) not_here("sigpending")
123 # define sigprocmask(a,b,c) not_here("sigprocmask")
124 # define sigsuspend(a) not_here("sigsuspend")
125 # define sigemptyset(a) not_here("sigemptyset")
126 # define sigaddset(a,b) not_here("sigaddset")
127 # define sigdelset(a,b) not_here("sigdelset")
128 # define sigfillset(a) not_here("sigfillset")
129 # define sigismember(a,b) not_here("sigismember")
133 # define setuid(a) not_here("setuid")
134 # define setgid(a) not_here("setgid")
140 # define mkfifo(a,b) not_here("mkfifo")
141 # else /* !( defined OS2 ) */
143 # define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
146 # endif /* !HAS_MKFIFO */
151 # include <sys/times.h>
153 # include <sys/utsname.h>
155 # include <sys/wait.h>
159 #endif /* WIN32 || NETWARE */
163 typedef long SysRetLong;
164 typedef sigset_t* POSIX__SigSet;
165 typedef HV* POSIX__SigAction;
167 typedef struct termios* POSIX__Termios;
168 #else /* Define termios types to int, and call not_here for the functions.*/
169 #define POSIX__Termios int
173 #define cfgetispeed(x) not_here("cfgetispeed")
174 #define cfgetospeed(x) not_here("cfgetospeed")
175 #define tcdrain(x) not_here("tcdrain")
176 #define tcflush(x,y) not_here("tcflush")
177 #define tcsendbreak(x,y) not_here("tcsendbreak")
178 #define cfsetispeed(x,y) not_here("cfsetispeed")
179 #define cfsetospeed(x,y) not_here("cfsetospeed")
180 #define ctermid(x) (char *) not_here("ctermid")
181 #define tcflow(x,y) not_here("tcflow")
182 #define tcgetattr(x,y) not_here("tcgetattr")
183 #define tcsetattr(x,y,z) not_here("tcsetattr")
186 /* Possibly needed prototypes */
189 double strtod (const char *, char **);
190 long strtol (const char *, char **, int);
191 unsigned long strtoul (const char *, char **, int);
197 #define difftime(a,b) not_here("difftime")
200 #ifndef HAS_FPATHCONF
201 #define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
204 #define mktime(a) not_here("mktime")
207 #define nice(a) not_here("nice")
210 #define pathconf(f,n) (SysRetLong) not_here("pathconf")
213 #define sysconf(n) (SysRetLong) not_here("sysconf")
216 #define readlink(a,b,c) not_here("readlink")
219 #define setpgid(a,b) not_here("setpgid")
222 #define setsid() not_here("setsid")
225 #define strcoll(s1,s2) not_here("strcoll")
228 #define strtod(s1,s2) not_here("strtod")
231 #define strtol(s1,s2,b) not_here("strtol")
234 #define strtoul(s1,s2,b) not_here("strtoul")
237 #define strxfrm(s1,s2,n) not_here("strxfrm")
239 #ifndef HAS_TCGETPGRP
240 #define tcgetpgrp(a) not_here("tcgetpgrp")
242 #ifndef HAS_TCSETPGRP
243 #define tcsetpgrp(a,b) not_here("tcsetpgrp")
247 #define times(a) not_here("times")
251 #define uname(a) not_here("uname")
254 #define waitpid(a,b,c) not_here("waitpid")
259 #define mblen(a,b) not_here("mblen")
263 #define mbstowcs(s, pwcs, n) not_here("mbstowcs")
266 #define mbtowc(pwc, s, n) not_here("mbtowc")
269 #define wcstombs(s, pwcs, n) not_here("wcstombs")
272 #define wctomb(s, wchar) not_here("wcstombs")
274 #if !defined(HAS_MBLEN) && !defined(HAS_MBSTOWCS) && !defined(HAS_MBTOWC) && !defined(HAS_WCSTOMBS) && !defined(HAS_WCTOMB)
275 /* If we don't have these functions, then we wouldn't have gotten a typedef
276 for wchar_t, the wide character type. Defining wchar_t allows the
277 functions referencing it to compile. Its actual type is then meaningless,
278 since without the above functions, all sections using it end up calling
279 not_here() and croak. --Kaveh Ghazi (ghazi@noc.rutgers.edu) 9/18/94. */
285 #ifdef HAS_LOCALECONV
286 struct lconv_offset {
291 const struct lconv_offset lconv_strings[] = {
292 {"decimal_point", STRUCT_OFFSET(struct lconv, decimal_point)},
293 {"thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep)},
294 #ifndef NO_LOCALECONV_GROUPING
295 {"grouping", STRUCT_OFFSET(struct lconv, grouping)},
297 {"int_curr_symbol", STRUCT_OFFSET(struct lconv, int_curr_symbol)},
298 {"currency_symbol", STRUCT_OFFSET(struct lconv, currency_symbol)},
299 {"mon_decimal_point", STRUCT_OFFSET(struct lconv, mon_decimal_point)},
300 #ifndef NO_LOCALECONV_MON_THOUSANDS_SEP
301 {"mon_thousands_sep", STRUCT_OFFSET(struct lconv, mon_thousands_sep)},
303 #ifndef NO_LOCALECONV_MON_GROUPING
304 {"mon_grouping", STRUCT_OFFSET(struct lconv, mon_grouping)},
306 {"positive_sign", STRUCT_OFFSET(struct lconv, positive_sign)},
307 {"negative_sign", STRUCT_OFFSET(struct lconv, negative_sign)},
311 const struct lconv_offset lconv_integers[] = {
312 {"int_frac_digits", STRUCT_OFFSET(struct lconv, int_frac_digits)},
313 {"frac_digits", STRUCT_OFFSET(struct lconv, frac_digits)},
314 {"p_cs_precedes", STRUCT_OFFSET(struct lconv, p_cs_precedes)},
315 {"p_sep_by_space", STRUCT_OFFSET(struct lconv, p_sep_by_space)},
316 {"n_cs_precedes", STRUCT_OFFSET(struct lconv, n_cs_precedes)},
317 {"n_sep_by_space", STRUCT_OFFSET(struct lconv, n_sep_by_space)},
318 {"p_sign_posn", STRUCT_OFFSET(struct lconv, p_sign_posn)},
319 {"n_sign_posn", STRUCT_OFFSET(struct lconv, n_sign_posn)},
324 #define localeconv() not_here("localeconv")
327 #ifdef HAS_LONG_DOUBLE
328 # if LONG_DOUBLESIZE > NVSIZE
329 # undef HAS_LONG_DOUBLE /* XXX until we figure out how to use them */
333 #ifndef HAS_LONG_DOUBLE
345 /* Background: in most systems the low byte of the wait status
346 * is the signal (the lowest 7 bits) and the coredump flag is
347 * the eight bit, and the second lowest byte is the exit status.
348 * BeOS bucks the trend and has the bytes in different order.
349 * See beos/beos.c for how the reality is bent even in BeOS
350 * to follow the traditional. However, to make the POSIX
351 * wait W*() macros to work in BeOS, we need to unbend the
352 * reality back in place. --jhi */
353 /* In actual fact the code below is to blame here. Perl has an internal
354 * representation of the exit status ($?), which it re-composes from the
355 * OS's representation using the W*() POSIX macros. The code below
356 * incorrectly uses the W*() macros on the internal representation,
357 * which fails for OSs that have a different representation (namely BeOS
358 * and Haiku). WMUNGE() is a hack that converts the internal
359 * representation into the OS specific one, so that the W*() macros work
360 * as expected. The better solution would be not to use the W*() macros
361 * in the first place, though. -- Ingo Weinhold
363 #if defined(__HAIKU__)
364 # define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
366 # define WMUNGE(x) (x)
370 not_here(const char *s)
372 croak("POSIX::%s not implemented on this architecture", s);
376 #include "const-c.inc"
379 restore_sigmask(pTHX_ SV *osset_sv)
381 /* Fortunately, restoring the signal mask can't fail, because
382 * there's nothing we can do about it if it does -- we're not
383 * supposed to return -1 from sigaction unless the disposition
386 sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
387 (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
391 allocate_struct(pTHX_ SV *rv, const STRLEN size, const char *packname) {
392 SV *const t = newSVrv(rv, packname);
393 void *const p = sv_grow(t, size + 1);
403 * (1) The CRT maintains its own copy of the environment, separate from
406 * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this
407 * copy, and then calls SetEnvironmentVariableA() to update the Win32API
410 * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and
411 * SetEnvironmentVariableA() directly, bypassing the CRT copy of the
414 * (4) The CRT strftime() "%Z" implementation calls __tzset(). That
415 * calls CRT tzset(), but only the first time it is called, and in turn
416 * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT
417 * local copy of the environment and hence gets the original setting as
418 * perl never updates the CRT copy when assigning to $ENV{TZ}.
420 * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT
421 * putenv() to update the CRT copy of the environment (if it is different)
422 * whenever we're about to call tzset().
424 * In addition to all that, when perl is built with PERL_IMPLICIT_SYS
427 * (a) Each interpreter has its own copy of the environment inside the
428 * perlhost structure. That allows applications that host multiple
429 * independent Perl interpreters to isolate environment changes from
430 * each other. (This is similar to how the perlhost mechanism keeps a
431 * separate working directory for each Perl interpreter, so that calling
432 * chdir() will not affect other interpreters.)
434 * (b) Only the first Perl interpreter instantiated within a process will
435 * "write through" environment changes to the process environment.
437 * (c) Even the primary Perl interpreter won't update the CRT copy of the
438 * the environment, only the Win32API copy (it calls win32_putenv()).
440 * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes
441 * sense to only update the process environment when inside the main
442 * interpreter, but we don't have access to CPerlHost's m_bTopLevel member
443 * from here so we'll just have to check PL_curinterp instead.
445 * Therefore, we can simply #undef getenv() and putenv() so that those names
446 * always refer to the CRT functions, and explicitly call win32_getenv() to
447 * access perl's %ENV.
449 * We also #undef malloc() and free() to be sure we are using the CRT
450 * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls
451 * into VMem::Malloc() and VMem::Free() and all allocations will be freed
452 * when the Perl interpreter is being destroyed so we'd end up with a pointer
453 * into deallocated memory in environ[] if a program embedding a Perl
454 * interpreter continues to operate even after the main Perl interpreter has
457 * Note that we don't free() the malloc()ed memory unless and until we call
458 * malloc() again ourselves because the CRT putenv() function simply puts its
459 * pointer argument into the environ[] array (it doesn't make a copy of it)
460 * so this memory must otherwise be leaked.
469 fix_win32_tzenv(void)
471 static char* oldenv = NULL;
473 const char* perl_tz_env = win32_getenv("TZ");
474 const char* crt_tz_env = getenv("TZ");
475 if (perl_tz_env == NULL)
477 if (crt_tz_env == NULL)
479 if (strcmp(perl_tz_env, crt_tz_env) != 0) {
480 newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char));
481 if (newenv != NULL) {
482 sprintf(newenv, "TZ=%s", perl_tz_env);
494 * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32.
495 * This code is duplicated in the Time-Piece module, so any changes made here
496 * should be made there too.
502 #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS)
503 if (PL_curinterp == aTHX)
510 typedef int (*isfunc_t)(int);
511 typedef void (*any_dptr_t)(void *);
513 /* This needs to be ALIASed in a custom way, hence can't easily be defined as
515 static XSPROTO(is_common); /* prototype to pass -Wmissing-prototypes */
516 static XSPROTO(is_common)
519 static PTR_TBL_t * is_common_ptr_table;
522 croak_xs_usage(cv, "charstring");
527 /*int RETVAL = 0; YYY means uncomment this to return false on an
528 * empty string input */
530 unsigned char *s = (unsigned char *) SvPV(ST(0), len);
531 unsigned char *e = s + len;
532 isfunc_t isfunc = (isfunc_t) XSANY.any_dptr;
534 if (ckWARN_d(WARN_DEPRECATED)) {
536 /* Warn exactly once for each lexical place this function is
537 * called. See thread at
538 * http://markmail.org/thread/jhqcag5njmx7jpyu */
540 if (! is_common_ptr_table) {
541 is_common_ptr_table = ptr_table_new();
543 if (! ptr_table_fetch(is_common_ptr_table, PL_op)) {
544 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
545 "Calling POSIX::%"HEKf"() is deprecated",
546 HEKfARG(GvNAME_HEK(CvGV(cv))));
547 ptr_table_store(is_common_ptr_table, PL_op, (void *) 1);
551 /*if (e > s) { YYY */
552 for (RETVAL = 1; RETVAL && s < e; s++)
562 MODULE = POSIX PACKAGE = POSIX
567 const char *file = __FILE__;
570 /* silence compiler warning about not_here() defined but not used */
573 /* Ensure we get the function, not a macro implementation. Like the C89
574 standard says we can... */
576 cv = newXS("POSIX::isalnum", is_common, file);
577 XSANY.any_dptr = (any_dptr_t) &isalnum;
579 cv = newXS("POSIX::isalpha", is_common, file);
580 XSANY.any_dptr = (any_dptr_t) &isalpha;
582 cv = newXS("POSIX::iscntrl", is_common, file);
583 XSANY.any_dptr = (any_dptr_t) &iscntrl;
585 cv = newXS("POSIX::isdigit", is_common, file);
586 XSANY.any_dptr = (any_dptr_t) &isdigit;
588 cv = newXS("POSIX::isgraph", is_common, file);
589 XSANY.any_dptr = (any_dptr_t) &isgraph;
591 cv = newXS("POSIX::islower", is_common, file);
592 XSANY.any_dptr = (any_dptr_t) &islower;
594 cv = newXS("POSIX::isprint", is_common, file);
595 XSANY.any_dptr = (any_dptr_t) &isprint;
597 cv = newXS("POSIX::ispunct", is_common, file);
598 XSANY.any_dptr = (any_dptr_t) &ispunct;
600 cv = newXS("POSIX::isspace", is_common, file);
601 XSANY.any_dptr = (any_dptr_t) &isspace;
603 cv = newXS("POSIX::isupper", is_common, file);
604 XSANY.any_dptr = (any_dptr_t) &isupper;
606 cv = newXS("POSIX::isxdigit", is_common, file);
607 XSANY.any_dptr = (any_dptr_t) &isxdigit;
610 MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
613 new(packname = "POSIX::SigSet", ...)
614 const char * packname
619 = (sigset_t *) allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
623 for (i = 1; i < items; i++)
624 sigaddset(s, SvIV(ST(i)));
635 RETVAL = ix ? sigdelset(sigset, sig) : sigaddset(sigset, sig);
645 RETVAL = ix ? sigfillset(sigset) : sigemptyset(sigset);
650 sigismember(sigset, sig)
654 MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
657 new(packname = "POSIX::Termios", ...)
658 const char * packname
662 void *const p = allocate_struct(aTHX_ (ST(0) = sv_newmortal()),
663 sizeof(struct termios), packname);
664 /* The previous implementation stored a pointer to an uninitialised
665 struct termios. Seems safer to initialise it, particularly as
666 this implementation exposes the struct to prying from perl-space.
668 memset(p, 0, 1 + sizeof(struct termios));
676 getattr(termios_ref, fd = 0)
677 POSIX::Termios termios_ref
680 RETVAL = tcgetattr(fd, termios_ref);
684 # If we define TCSANOW here then both a found and not found constant sub
685 # are created causing a Constant subroutine TCSANOW redefined warning
687 # define DEF_SETATTR_ACTION 0
689 # define DEF_SETATTR_ACTION TCSANOW
692 setattr(termios_ref, fd = 0, optional_actions = DEF_SETATTR_ACTION)
693 POSIX::Termios termios_ref
697 /* The second argument to the call is mandatory, but we'd like to give
698 it a useful default. 0 isn't valid on all operating systems - on
699 Solaris (at least) TCSANOW, TCSADRAIN and TCSAFLUSH have the same
700 values as the equivalent ioctls, TCSETS, TCSETSW and TCSETSF. */
701 RETVAL = tcsetattr(fd, optional_actions, termios_ref);
706 getispeed(termios_ref)
707 POSIX::Termios termios_ref
711 RETVAL = ix ? cfgetospeed(termios_ref) : cfgetispeed(termios_ref);
716 getiflag(termios_ref)
717 POSIX::Termios termios_ref
723 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
726 RETVAL = termios_ref->c_iflag;
729 RETVAL = termios_ref->c_oflag;
732 RETVAL = termios_ref->c_cflag;
735 RETVAL = termios_ref->c_lflag;
738 RETVAL = 0; /* silence compiler warning */
741 not_here(GvNAME(CvGV(cv)));
748 getcc(termios_ref, ccix)
749 POSIX::Termios termios_ref
752 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
754 croak("Bad getcc subscript");
755 RETVAL = termios_ref->c_cc[ccix];
764 setispeed(termios_ref, speed)
765 POSIX::Termios termios_ref
771 ? cfsetospeed(termios_ref, speed) : cfsetispeed(termios_ref, speed);
776 setiflag(termios_ref, flag)
777 POSIX::Termios termios_ref
784 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
787 termios_ref->c_iflag = flag;
790 termios_ref->c_oflag = flag;
793 termios_ref->c_cflag = flag;
796 termios_ref->c_lflag = flag;
800 not_here(GvNAME(CvGV(cv)));
804 setcc(termios_ref, ccix, cc)
805 POSIX::Termios termios_ref
809 #ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
811 croak("Bad setcc subscript");
812 termios_ref->c_cc[ccix] = cc;
818 MODULE = POSIX PACKAGE = POSIX
820 INCLUDE: const-xs.inc
827 POSIX::WIFSIGNALED = 2
828 POSIX::WIFSTOPPED = 3
832 #if !defined(WEXITSTATUS) || !defined(WIFEXITED) || !defined(WIFSIGNALED) \
833 || !defined(WIFSTOPPED) || !defined(WSTOPSIG) || !defined(WTERMSIG)
834 RETVAL = 0; /* Silence compilers that notice this, but don't realise
835 that not_here() can't return. */
840 RETVAL = WEXITSTATUS(WMUNGE(status));
842 not_here("WEXITSTATUS");
847 RETVAL = WIFEXITED(WMUNGE(status));
849 not_here("WIFEXITED");
854 RETVAL = WIFSIGNALED(WMUNGE(status));
856 not_here("WIFSIGNALED");
861 RETVAL = WIFSTOPPED(WMUNGE(status));
863 not_here("WIFSTOPPED");
868 RETVAL = WSTOPSIG(WMUNGE(status));
870 not_here("WSTOPSIG");
875 RETVAL = WTERMSIG(WMUNGE(status));
877 not_here("WTERMSIG");
881 Perl_croak(aTHX_ "Illegal alias %d for POSIX::W*", (int)ix);
887 open(filename, flags = O_RDONLY, mode = 0666)
892 if (flags & (O_APPEND|O_CREAT|O_TRUNC|O_RDWR|O_WRONLY|O_EXCL))
893 TAINT_PROPER("open");
894 RETVAL = open(filename, flags, mode);
902 #ifdef HAS_LOCALECONV
905 sv_2mortal((SV*)RETVAL);
906 if ((lcbuf = localeconv())) {
907 const struct lconv_offset *strings = lconv_strings;
908 const struct lconv_offset *integers = lconv_integers;
909 const char *ptr = (const char *) lcbuf;
912 const char *value = *((const char **)(ptr + strings->offset));
915 (void) hv_store(RETVAL, strings->name, strlen(strings->name),
916 newSVpv(value, 0), 0);
917 } while ((++strings)->name);
920 const char value = *((const char *)(ptr + integers->offset));
922 if (value != CHAR_MAX)
923 (void) hv_store(RETVAL, integers->name,
924 strlen(integers->name), newSViv(value), 0);
925 } while ((++integers)->name);
928 localeconv(); /* A stub to call not_here(). */
934 setlocale(category, locale = 0)
940 #ifdef WIN32 /* Use wrapper on Windows */
941 retval = Perl_my_setlocale(aTHX_ category, locale);
943 retval = setlocale(category, locale);
949 /* Save retval since subsequent setlocale() calls
950 * may overwrite it. */
951 RETVAL = savepv(retval);
952 #ifdef USE_LOCALE_CTYPE
953 if (category == LC_CTYPE
955 || category == LC_ALL
961 if (category == LC_ALL)
962 newctype = setlocale(LC_CTYPE, NULL);
968 #endif /* USE_LOCALE_CTYPE */
969 #ifdef USE_LOCALE_COLLATE
970 if (category == LC_COLLATE
972 || category == LC_ALL
978 if (category == LC_ALL)
979 newcoll = setlocale(LC_COLLATE, NULL);
983 new_collate(newcoll);
985 #endif /* USE_LOCALE_COLLATE */
986 #ifdef USE_LOCALE_NUMERIC
987 if (category == LC_NUMERIC
989 || category == LC_ALL
995 if (category == LC_ALL)
996 newnum = setlocale(LC_NUMERIC, NULL);
1000 new_numeric(newnum);
1002 #endif /* USE_LOCALE_NUMERIC */
1067 /* (We already know stack is long enough.) */
1068 PUSHs(sv_2mortal(newSVnv(frexp(x,&expvar))));
1069 PUSHs(sv_2mortal(newSViv(expvar)));
1081 /* (We already know stack is long enough.) */
1082 PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
1083 PUSHs(sv_2mortal(newSVnv(intvar)));
1086 sigaction(sig, optaction, oldaction = 0)
1089 POSIX::SigAction oldaction
1091 #if defined(WIN32) || defined(NETWARE)
1092 RETVAL = not_here("sigaction");
1094 # This code is really grody because we're trying to make the signal
1095 # interface look beautiful, which is hard.
1099 POSIX__SigAction action;
1100 GV *siggv = gv_fetchpvs("SIG", GV_ADD, SVt_PVHV);
1101 struct sigaction act;
1102 struct sigaction oact;
1106 POSIX__SigSet sigset;
1111 croak("Negative signals are not allowed");
1114 if (sig == 0 && SvPOK(ST(0))) {
1115 const char *s = SvPVX_const(ST(0));
1116 int i = whichsig(s);
1118 if (i < 0 && memEQ(s, "SIG", 3))
1119 i = whichsig(s + 3);
1121 if (ckWARN(WARN_SIGNAL))
1122 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1123 "No such signal: SIG%s", s);
1130 if (sig > NSIG) { /* NSIG - 1 is still okay. */
1131 Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
1132 "No such signal: %d", sig);
1136 sigsvp = hv_fetch(GvHVn(siggv),
1138 strlen(PL_sig_name[sig]),
1141 /* Check optaction and set action */
1142 if(SvTRUE(optaction)) {
1143 if(sv_isa(optaction, "POSIX::SigAction"))
1144 action = (HV*)SvRV(optaction);
1146 croak("action is not of type POSIX::SigAction");
1152 /* sigaction() is supposed to look atomic. In particular, any
1153 * signal handler invoked during a sigaction() call should
1154 * see either the old or the new disposition, and not something
1155 * in between. We use sigprocmask() to make it so.
1158 RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
1162 /* Restore signal mask no matter how we exit this block. */
1163 osset_sv = newSVpvn((char *)(&osset), sizeof(sigset_t));
1164 SAVEFREESV( osset_sv );
1165 SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
1167 RETVAL=-1; /* In case both oldaction and action are 0. */
1169 /* Remember old disposition if desired. */
1171 svp = hv_fetchs(oldaction, "HANDLER", TRUE);
1173 croak("Can't supply an oldaction without a HANDLER");
1174 if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
1175 sv_setsv(*svp, *sigsvp);
1178 sv_setpvs(*svp, "DEFAULT");
1180 RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
1185 /* Get back the mask. */
1186 svp = hv_fetchs(oldaction, "MASK", TRUE);
1187 if (sv_isa(*svp, "POSIX::SigSet")) {
1188 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
1191 sigset = (sigset_t *) allocate_struct(aTHX_ *svp,
1195 *sigset = oact.sa_mask;
1197 /* Get back the flags. */
1198 svp = hv_fetchs(oldaction, "FLAGS", TRUE);
1199 sv_setiv(*svp, oact.sa_flags);
1201 /* Get back whether the old handler used safe signals. */
1202 svp = hv_fetchs(oldaction, "SAFE", TRUE);
1204 /* compare incompatible pointers by casting to integer */
1205 PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
1209 /* Safe signals use "csighandler", which vectors through the
1210 PL_sighandlerp pointer when it's safe to do so.
1211 (BTW, "csighandler" is very different from "sighandler".) */
1212 svp = hv_fetchs(action, "SAFE", FALSE);
1216 (*svp && SvTRUE(*svp))
1217 ? PL_csighandlerp : PL_sighandlerp
1220 /* Vector new Perl handler through %SIG.
1221 (The core signal handlers read %SIG to dispatch.) */
1222 svp = hv_fetchs(action, "HANDLER", FALSE);
1224 croak("Can't supply an action without a HANDLER");
1225 sv_setsv(*sigsvp, *svp);
1227 /* This call actually calls sigaction() with almost the
1228 right settings, including appropriate interpretation
1229 of DEFAULT and IGNORE. However, why are we doing
1230 this when we're about to do it again just below? XXX */
1231 SvSETMAGIC(*sigsvp);
1233 /* And here again we duplicate -- DEFAULT/IGNORE checking. */
1235 const char *s=SvPVX_const(*svp);
1236 if(strEQ(s,"IGNORE")) {
1237 act.sa_handler = SIG_IGN;
1239 else if(strEQ(s,"DEFAULT")) {
1240 act.sa_handler = SIG_DFL;
1244 /* Set up any desired mask. */
1245 svp = hv_fetchs(action, "MASK", FALSE);
1246 if (svp && sv_isa(*svp, "POSIX::SigSet")) {
1247 sigset = (sigset_t *) SvPV_nolen(SvRV(*svp));
1248 act.sa_mask = *sigset;
1251 sigemptyset(& act.sa_mask);
1253 /* Set up any desired flags. */
1254 svp = hv_fetchs(action, "FLAGS", FALSE);
1255 act.sa_flags = svp ? SvIV(*svp) : 0;
1257 /* Don't worry about cleaning up *sigsvp if this fails,
1258 * because that means we tried to disposition a
1259 * nonblockable signal, in which case *sigsvp is
1260 * essentially meaningless anyway.
1262 RETVAL = sigaction(sig, & act, (struct sigaction *)0);
1277 POSIX::SigSet sigset
1281 RETVAL = ix ? sigsuspend(sigset) : sigpending(sigset);
1288 sigprocmask(how, sigset, oldsigset = 0)
1290 POSIX::SigSet sigset = NO_INIT
1291 POSIX::SigSet oldsigset = NO_INIT
1293 if (! SvOK(ST(1))) {
1295 } else if (sv_isa(ST(1), "POSIX::SigSet")) {
1296 sigset = (sigset_t *) SvPV_nolen(SvRV(ST(1)));
1298 croak("sigset is not of type POSIX::SigSet");
1301 if (items < 3 || ! SvOK(ST(2))) {
1303 } else if (sv_isa(ST(2), "POSIX::SigSet")) {
1304 oldsigset = (sigset_t *) SvPV_nolen(SvRV(ST(2)));
1306 croak("oldsigset is not of type POSIX::SigSet");
1319 /* RT #98912 - More Microsoft muppetry - failing to actually implemented
1320 the well known documented POSIX behaviour for a POSIX API.
1321 http://msdn.microsoft.com/en-us/library/8syseb29.aspx */
1322 RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2;
1324 RETVAL = dup2(fd1, fd2);
1330 lseek(fd, offset, whence)
1335 Off_t pos = PerlLIO_lseek(fd, offset, whence);
1336 RETVAL = sizeof(Off_t) > sizeof(IV)
1337 ? newSVnv((NV)pos) : newSViv((IV)pos);
1346 if ((incr = nice(incr)) != -1 || errno == 0) {
1348 XPUSHs(newSVpvs_flags("0 but true", SVs_TEMP));
1350 XPUSHs(sv_2mortal(newSViv(incr)));
1357 if (pipe(fds) != -1) {
1359 PUSHs(sv_2mortal(newSViv(fds[0])));
1360 PUSHs(sv_2mortal(newSViv(fds[1])));
1364 read(fd, buffer, nbytes)
1366 SV *sv_buffer = SvROK(ST(1)) ? SvRV(ST(1)) : ST(1);
1370 char * buffer = sv_grow( sv_buffer, nbytes+1 );
1373 SvCUR_set(sv_buffer, RETVAL);
1374 SvPOK_only(sv_buffer);
1375 *SvEND(sv_buffer) = '\0';
1376 SvTAINTED_on(sv_buffer);
1392 tcsetpgrp(fd, pgrp_id)
1401 if (uname(&buf) >= 0) {
1403 PUSHs(newSVpvn_flags(buf.sysname, strlen(buf.sysname), SVs_TEMP));
1404 PUSHs(newSVpvn_flags(buf.nodename, strlen(buf.nodename), SVs_TEMP));
1405 PUSHs(newSVpvn_flags(buf.release, strlen(buf.release), SVs_TEMP));
1406 PUSHs(newSVpvn_flags(buf.version, strlen(buf.version), SVs_TEMP));
1407 PUSHs(newSVpvn_flags(buf.machine, strlen(buf.machine), SVs_TEMP));
1410 uname((char *) 0); /* A stub to call not_here(). */
1414 write(fd, buffer, nbytes)
1425 RETVAL = newSVpvn("", 0);
1426 SvGROW(RETVAL, L_tmpnam);
1427 /* Yes, we know tmpnam() is bad. So bad that some compilers
1428 * and linkers warn against using it. But it is here for
1429 * completeness. POSIX.pod warns against using it.
1431 * Then again, maybe this should be removed at some point.
1432 * No point in enabling dangerous interfaces. */
1433 len = strlen(tmpnam(SvPV(RETVAL, i)));
1434 SvCUR_set(RETVAL, len);
1447 mbstowcs(s, pwcs, n)
1459 wcstombs(s, pwcs, n)
1481 STORE_NUMERIC_STANDARD_FORCE_LOCAL();
1482 num = strtod(str, &unparsed);
1483 PUSHs(sv_2mortal(newSVnv(num)));
1484 if (GIMME == G_ARRAY) {
1487 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1489 PUSHs(&PL_sv_undef);
1491 RESTORE_NUMERIC_STANDARD();
1494 strtol(str, base = 0)
1501 num = strtol(str, &unparsed, base);
1502 #if IVSIZE <= LONGSIZE
1503 if (num < IV_MIN || num > IV_MAX)
1504 PUSHs(sv_2mortal(newSVnv((double)num)));
1507 PUSHs(sv_2mortal(newSViv((IV)num)));
1508 if (GIMME == G_ARRAY) {
1511 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1513 PUSHs(&PL_sv_undef);
1517 strtoul(str, base = 0)
1524 num = strtoul(str, &unparsed, base);
1525 #if IVSIZE <= LONGSIZE
1527 PUSHs(sv_2mortal(newSVnv((double)num)));
1530 PUSHs(sv_2mortal(newSViv((IV)num)));
1531 if (GIMME == G_ARRAY) {
1534 PUSHs(sv_2mortal(newSViv(strlen(unparsed))));
1536 PUSHs(&PL_sv_undef);
1546 char *p = SvPV(src,srclen);
1548 ST(0) = sv_2mortal(newSV(srclen*4+1));
1549 dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
1550 if (dstlen > srclen) {
1552 SvGROW(ST(0), dstlen);
1553 strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
1556 SvCUR_set(ST(0), dstlen);
1561 mkfifo(filename, mode)
1568 RETVAL = access(filename, mode);
1570 TAINT_PROPER("mkfifo");
1571 RETVAL = mkfifo(filename, mode);
1583 RETVAL = ix == 1 ? close(fd)
1584 : (ix < 1 ? tcdrain(fd) : dup(fd));
1597 RETVAL = ix == 1 ? tcflush(fd, action)
1598 : (ix < 1 ? tcflow(fd, action) : tcsendbreak(fd, action));
1603 asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
1619 init_tm(&mytm); /* XXX workaround - see init_tm() in core util.c */
1622 mytm.tm_hour = hour;
1623 mytm.tm_mday = mday;
1625 mytm.tm_year = year;
1626 mytm.tm_wday = wday;
1627 mytm.tm_yday = yday;
1628 mytm.tm_isdst = isdst;
1630 const time_t result = mktime(&mytm);
1631 if (result == (time_t)-1)
1633 else if (result == 0)
1634 sv_setpvn(TARG, "0 but true", 10);
1636 sv_setiv(TARG, (IV)result);
1638 sv_setpv(TARG, asctime(&mytm));
1656 realtime = times( &tms );
1658 PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) );
1659 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) );
1660 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) );
1661 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) );
1662 PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
1665 difftime(time1, time2)
1669 #XXX: if $xsubpp::WantOptimize is always the default
1670 # sv_setpv(TARG, ...) could be used rather than
1671 # ST(0) = sv_2mortal(newSVpv(...))
1673 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
1688 /* allowing user-supplied (rather than literal) formats
1689 * is normally frowned upon as a potential security risk;
1690 * but this is part of the API so we have to allow it */
1691 GCC_DIAG_IGNORE(-Wformat-nonliteral);
1692 buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
1695 SV *const sv = sv_newmortal();
1696 sv_usepvn_flags(sv, buf, strlen(buf), SV_HAS_TRAILING_NUL);
1713 PUSHs(newSVpvn_flags(tzname[0], strlen(tzname[0]), SVs_TEMP));
1714 PUSHs(newSVpvn_flags(tzname[1], strlen(tzname[1]), SVs_TEMP));
1720 #ifdef HAS_CTERMID_R
1721 s = (char *) safemalloc((size_t) L_ctermid);
1723 RETVAL = ctermid(s);
1727 #ifdef HAS_CTERMID_R
1736 RETVAL = cuserid(s);
1739 not_here("cuserid");
1750 pathconf(filename, name)
1761 unsigned int seconds
1763 RETVAL = PerlProc_sleep(seconds);
1789 XSprePUSH; PUSHTARG;
1793 lchown(uid, gid, path)
1799 /* yes, the order of arguments is different,
1800 * but consistent with CORE::chown() */
1801 RETVAL = lchown(path, uid, gid);
1803 RETVAL = not_here("lchown");