-#ifdef WIN32
-#define _POSIX_
-#endif
+#define PERL_EXT_POSIX
#ifdef NETWARE
#define _POSIX_
- //Ideally this should be somewhere down in the includes
- //but putting it in other places is giving compiler errors.
- //Also here I am unable to check for HAS_UNAME since it wouldn't have yet
- //come into the file at this stage - sgp 18th Oct 2000
+ /*
+ * Ideally this should be somewhere down in the includes
+ * but putting it in other places is giving compiler errors.
+ * Also here I am unable to check for HAS_UNAME since it wouldn't have
+ * yet come into the file at this stage - sgp 18th Oct 2000
+ */
#include <sys/utsname.h>
#endif /* NETWARE */
#define PERLIO_NOT_STDIO 1
#include "perl.h"
#include "XSUB.h"
-#if defined(PERL_OBJECT) || defined(PERL_CAPI) || defined(PERL_IMPLICIT_SYS)
+#if defined(PERL_IMPLICIT_SYS)
# undef signal
# undef open
# undef setmode
#include <unistd.h>
#endif
-/* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
+/* XXX This comment is just to make I_TERMIO and I_SGTTY visible to
metaconfig for future extension writers. We don't use them in POSIX.
(This is really sneaky :-) --AD
*/
#ifdef I_STDLIB
#include <stdlib.h>
#endif
+#ifndef __ultrix__
#include <string.h>
+#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <fcntl.h>
#ifdef HAS_TZNAME
-# if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE)
+# if !defined(WIN32) && !defined(__CYGWIN__) && !defined(NETWARE) && !defined(__UWIN__)
extern char *tzname[];
# endif
#else
-#if !defined(WIN32) || (defined(__MINGW32__) && !defined(tzname))
+#if !defined(WIN32) && !defined(__UWIN__) || (defined(__MINGW32__) && !defined(tzname))
char *tzname[] = { "" , "" };
#endif
#endif
+#ifndef PERL_UNUSED_DECL
+# ifdef HASATTRIBUTE
+# if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
+# define PERL_UNUSED_DECL
+# else
+# define PERL_UNUSED_DECL __attribute__((unused))
+# endif
+# else
+# define PERL_UNUSED_DECL
+# endif
+#endif
+
+#ifndef dNOOP
+#define dNOOP extern int Perl___notused PERL_UNUSED_DECL
+#endif
+
+#ifndef dVAR
+#define dVAR dNOOP
+#endif
+
#if defined(__VMS) && !defined(__POSIX_SOURCE)
# include <libdef.h> /* LIB$_INVARG constant */
# include <lib$routines.h> /* prototype for lib$ediv() */
# define sigfillset(a) not_here("sigfillset")
# define sigismember(a,b) not_here("sigismember")
#ifndef NETWARE
+# undef setuid
+# undef setgid
# define setuid(a) not_here("setuid")
# define setgid(a) not_here("setgid")
#endif /* NETWARE */
# ifndef HAS_MKFIFO
# if defined(OS2) || defined(MACOS_TRADITIONAL)
# define mkfifo(a,b) not_here("mkfifo")
-# else /* !( defined OS2 ) */
+# else /* !( defined OS2 ) */
# ifndef mkfifo
# define mkfifo(path, mode) (mknod((path), (mode) | S_IFIFO, 0))
# endif
# define ttyname(a) (char*)not_here("ttyname")
# define tzset() not_here("tzset")
# else
-# include <grp.h>
+# ifdef I_GRP
+# include <grp.h>
+# endif
# include <sys/times.h>
# ifdef HAS_UNAME
# include <sys/utsname.h>
/* Possibly needed prototypes */
char *cuserid (char *);
+#ifndef WIN32
double strtod (const char *, char **);
long strtol (const char *, char **, int);
unsigned long strtoul (const char *, char **, int);
+#endif
#ifndef HAS_CUSERID
#define cuserid(a) (char *) not_here("cuserid")
#endif
#endif
#ifndef HAS_FPATHCONF
-#define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
+#define fpathconf(f,n) (SysRetLong) not_here("fpathconf")
#endif
#ifndef HAS_MKTIME
#define mktime(a) not_here("mktime")
#define nice(a) not_here("nice")
#endif
#ifndef HAS_PATHCONF
-#define pathconf(f,n) (SysRetLong) not_here("pathconf")
+#define pathconf(f,n) (SysRetLong) not_here("pathconf")
#endif
#ifndef HAS_SYSCONF
-#define sysconf(n) (SysRetLong) not_here("sysconf")
+#define sysconf(n) (SysRetLong) not_here("sysconf")
#endif
#ifndef HAS_READLINK
#define readlink(a,b,c) not_here("readlink")
#endif
#endif
+/* Background: in most systems the low byte of the wait status
+ * is the signal (the lowest 7 bits) and the coredump flag is
+ * the eight bit, and the second lowest byte is the exit status.
+ * BeOS bucks the trend and has the bytes in different order.
+ * See beos/beos.c for how the reality is bent even in BeOS
+ * to follow the traditional. However, to make the POSIX
+ * wait W*() macros to work in BeOS, we need to unbend the
+ * reality back in place. --jhi */
+#ifdef __BEOS__
+# define WMUNGE(x) (((x) & 0xFF00) >> 8 | ((x) & 0x00FF) << 8)
+#else
+# define WMUNGE(x) (x)
+#endif
+
static int
not_here(char *s)
{
return -1;
}
-#include "constants.c"
+#include "const-c.inc"
/* These were implemented in the old "constant" subroutine. They are actually
macros that take an integer argument and return an integer result. */
}
print "#### XS Section:\n";
print XS_constant ("POSIX", $types);
-__END__
*/
switch (len) {
if (memEQ(name, "WSTOPSIG", 8)) {
/* ^ */
#ifdef WSTOPSIG
- *arg_result = WSTOPSIG(*arg_result);
+ int i = *arg_result;
+ *arg_result = WSTOPSIG(WMUNGE(i));
return PERL_constant_ISIV;
#else
return PERL_constant_NOTDEF;
if (memEQ(name, "WTERMSIG", 8)) {
/* ^ */
#ifdef WTERMSIG
- *arg_result = WTERMSIG(*arg_result);
+ int i = *arg_result;
+ *arg_result = WTERMSIG(WMUNGE(i));
return PERL_constant_ISIV;
#else
return PERL_constant_NOTDEF;
case 9:
if (memEQ(name, "WIFEXITED", 9)) {
#ifdef WIFEXITED
- *arg_result = WIFEXITED(*arg_result);
+ int i = *arg_result;
+ *arg_result = WIFEXITED(WMUNGE(i));
return PERL_constant_ISIV;
#else
return PERL_constant_NOTDEF;
case 10:
if (memEQ(name, "WIFSTOPPED", 10)) {
#ifdef WIFSTOPPED
- *arg_result = WIFSTOPPED(*arg_result);
+ int i = *arg_result;
+ *arg_result = WIFSTOPPED(WMUNGE(i));
return PERL_constant_ISIV;
#else
return PERL_constant_NOTDEF;
if (memEQ(name, "WEXITSTATUS", 11)) {
/* ^ */
#ifdef WEXITSTATUS
- *arg_result = WEXITSTATUS(*arg_result);
+ int i = *arg_result;
+ *arg_result = WEXITSTATUS(WMUNGE(i));
return PERL_constant_ISIV;
#else
return PERL_constant_NOTDEF;
if (memEQ(name, "WIFSIGNALED", 11)) {
/* ^ */
#ifdef WIFSIGNALED
- *arg_result = WIFSIGNALED(*arg_result);
+ int i = *arg_result;
+ *arg_result = WIFSIGNALED(WMUNGE(i));
return PERL_constant_ISIV;
#else
return PERL_constant_NOTDEF;
}
static void
-restore_sigmask(sigset_t *ossetp)
+restore_sigmask(pTHX_ SV *osset_sv)
{
- /* Fortunately, restoring the signal mask can't fail, because
- * there's nothing we can do about it if it does -- we're not
- * supposed to return -1 from sigaction unless the disposition
- * was unaffected.
- */
- (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
+ /* Fortunately, restoring the signal mask can't fail, because
+ * there's nothing we can do about it if it does -- we're not
+ * supposed to return -1 from sigaction unless the disposition
+ * was unaffected.
+ */
+ sigset_t *ossetp = (sigset_t *) SvPV_nolen( osset_sv );
+ (void)sigprocmask(SIG_SETMASK, ossetp, (sigset_t *)0);
}
MODULE = SigSet PACKAGE = POSIX::SigSet PREFIX = sig
CODE:
{
int i;
- New(0, RETVAL, 1, sigset_t);
+ Newx(RETVAL, 1, sigset_t);
sigemptyset(RETVAL);
for (i = 1; i < items; i++)
sigaddset(RETVAL, SvIV(ST(i)));
POSIX::SigSet sigset
int sig
-
MODULE = Termios PACKAGE = POSIX::Termios PREFIX = cf
POSIX::Termios
CODE:
{
#ifdef I_TERMIOS
- New(0, RETVAL, 1, struct termios);
+ Newx(RETVAL, 1, struct termios);
#else
not_here("termios");
RETVAL = 0;
cc_t
getcc(termios_ref, ccix)
POSIX::Termios termios_ref
- int ccix
+ unsigned int ccix
CODE:
#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
if (ccix >= NCCS)
void
setcc(termios_ref, ccix, cc)
POSIX::Termios termios_ref
- int ccix
+ unsigned int ccix
cc_t cc
CODE:
#ifdef I_TERMIOS /* References a termios structure member so ifdef it out. */
MODULE = POSIX PACKAGE = POSIX
-INCLUDE: constants.xs
+INCLUDE: const-xs.inc
void
int_macro_int(sv, iv)
int
isalnum(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!isalnum(*s))
RETVAL = 0;
int
isalpha(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!isalpha(*s))
RETVAL = 0;
int
iscntrl(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!iscntrl(*s))
RETVAL = 0;
int
isdigit(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!isdigit(*s))
RETVAL = 0;
int
isgraph(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!isgraph(*s))
RETVAL = 0;
int
islower(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!islower(*s))
RETVAL = 0;
int
isprint(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!isprint(*s))
RETVAL = 0;
int
ispunct(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!ispunct(*s))
RETVAL = 0;
int
isspace(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!isspace(*s))
RETVAL = 0;
int
isupper(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!isupper(*s))
RETVAL = 0;
int
isxdigit(charstring)
- unsigned char * charstring
+ SV * charstring
+ PREINIT:
+ STRLEN len;
CODE:
- unsigned char *s = charstring;
- unsigned char *e = s + PL_na; /* "PL_na" set by typemap side effect */
+ unsigned char *s = (unsigned char *) SvPV(charstring, len);
+ unsigned char *e = s + len;
for (RETVAL = 1; RETVAL && s < e; s++)
if (!isxdigit(*s))
RETVAL = 0;
#ifdef HAS_LOCALECONV
struct lconv *lcbuf;
RETVAL = newHV();
+ sv_2mortal((SV*)RETVAL);
if ((lcbuf = localeconv())) {
/* the strings */
if (lcbuf->decimal_point && *lcbuf->decimal_point)
if (lcbuf->mon_thousands_sep && *lcbuf->mon_thousands_sep)
hv_store(RETVAL, "mon_thousands_sep", 17,
newSVpv(lcbuf->mon_thousands_sep, 0), 0);
-#endif
+#endif
#ifndef NO_LOCALECONV_MON_GROUPING
if (lcbuf->mon_grouping && *lcbuf->mon_grouping)
hv_store(RETVAL, "mon_grouping", 12,
setlocale(category, locale = 0)
int category
char * locale
+ PREINIT:
+ char * retval;
CODE:
- RETVAL = setlocale(category, locale);
- if (RETVAL) {
+ retval = setlocale(category, locale);
+ if (retval) {
+ /* Save retval since subsequent setlocale() calls
+ * may overwrite it. */
+ RETVAL = savepv(retval);
#ifdef USE_LOCALE_CTYPE
if (category == LC_CTYPE
#ifdef LC_ALL
}
#endif /* USE_LOCALE_NUMERIC */
}
+ else
+ RETVAL = NULL;
OUTPUT:
RETVAL
-
+ CLEANUP:
+ if (RETVAL)
+ Safefree(RETVAL);
NV
acos(x)
# interface look beautiful, which is hard.
{
+ dVAR;
POSIX__SigAction action;
GV *siggv = gv_fetchpv("SIG", TRUE, SVt_PVHV);
struct sigaction act;
struct sigaction oact;
sigset_t sset;
+ SV *osset_sv;
sigset_t osset;
POSIX__SigSet sigset;
SV** svp;
- SV** sigsvp = hv_fetch(GvHVn(siggv),
- PL_sig_name[sig],
- strlen(PL_sig_name[sig]),
- TRUE);
+ SV** sigsvp;
+
+ if (sig < 0) {
+ croak("Negative signals are not allowed");
+ }
+
+ if (sig == 0 && SvPOK(ST(0))) {
+ const char *s = SvPVX_const(ST(0));
+ int i = whichsig(s);
+
+ if (i < 0 && memEQ(s, "SIG", 3))
+ i = whichsig(s + 3);
+ if (i < 0) {
+ if (ckWARN(WARN_SIGNAL))
+ Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
+ "No such signal: SIG%s", s);
+ XSRETURN_UNDEF;
+ }
+ else
+ sig = i;
+ }
+#ifdef NSIG
+ if (sig > NSIG) { /* NSIG - 1 is still okay. */
+ Perl_warner(aTHX_ packWARN(WARN_SIGNAL),
+ "No such signal: %d", sig);
+ XSRETURN_UNDEF;
+ }
+#endif
+ sigsvp = hv_fetch(GvHVn(siggv),
+ PL_sig_name[sig],
+ strlen(PL_sig_name[sig]),
+ TRUE);
/* Check optaction and set action */
if(SvTRUE(optaction)) {
sigfillset(&sset);
RETVAL=sigprocmask(SIG_BLOCK, &sset, &osset);
if(RETVAL == -1)
- XSRETURN(1);
+ XSRETURN_UNDEF;
ENTER;
/* Restore signal mask no matter how we exit this block. */
- SAVEDESTRUCTOR(restore_sigmask, &osset);
+ osset_sv = newSVpv((char *)(&osset), sizeof(sigset_t));
+ SAVEFREESV( osset_sv );
+ SAVEDESTRUCTOR_X(restore_sigmask, osset_sv);
RETVAL=-1; /* In case both oldaction and action are 0. */
/* Remember old disposition if desired. */
if (oldaction) {
- svp = hv_fetch(oldaction, "HANDLER", 7, TRUE);
+ svp = hv_fetchs(oldaction, "HANDLER", TRUE);
if(!svp)
croak("Can't supply an oldaction without a HANDLER");
if(SvTRUE(*sigsvp)) { /* TBD: what if "0"? */
}
RETVAL = sigaction(sig, (struct sigaction *)0, & oact);
if(RETVAL == -1)
- XSRETURN(1);
+ XSRETURN_UNDEF;
/* Get back the mask. */
- svp = hv_fetch(oldaction, "MASK", 4, TRUE);
+ svp = hv_fetchs(oldaction, "MASK", TRUE);
if (sv_isa(*svp, "POSIX::SigSet")) {
IV tmp = SvIV((SV*)SvRV(*svp));
sigset = INT2PTR(sigset_t*, tmp);
}
else {
- New(0, sigset, 1, sigset_t);
+ Newx(sigset, 1, sigset_t);
sv_setptrobj(*svp, sigset, "POSIX::SigSet");
}
*sigset = oact.sa_mask;
/* Get back the flags. */
- svp = hv_fetch(oldaction, "FLAGS", 5, TRUE);
+ svp = hv_fetchs(oldaction, "FLAGS", TRUE);
sv_setiv(*svp, oact.sa_flags);
+
+ /* Get back whether the old handler used safe signals. */
+ svp = hv_fetchs(oldaction, "SAFE", TRUE);
+ sv_setiv(*svp,
+ /* compare incompatible pointers by casting to integer */
+ PTR2nat(oact.sa_handler) == PTR2nat(PL_csighandlerp));
}
if (action) {
- /* Vector new handler through %SIG. (We always use sighandler
- for the C signal handler, which reads %SIG to dispatch.) */
- svp = hv_fetch(action, "HANDLER", 7, FALSE);
+ /* Safe signals use "csighandler", which vectors through the
+ PL_sighandlerp pointer when it's safe to do so.
+ (BTW, "csighandler" is very different from "sighandler".) */
+ svp = hv_fetchs(action, "SAFE", FALSE);
+ act.sa_handler =
+ DPTR2FPTR(
+ void (*)(int),
+ (*svp && SvTRUE(*svp))
+ ? PL_csighandlerp : PL_sighandlerp
+ );
+
+ /* Vector new Perl handler through %SIG.
+ (The core signal handlers read %SIG to dispatch.) */
+ svp = hv_fetchs(action, "HANDLER", FALSE);
if (!svp)
croak("Can't supply an action without a HANDLER");
sv_setsv(*sigsvp, *svp);
- mg_set(*sigsvp); /* handles DEFAULT and IGNORE */
+
+ /* This call actually calls sigaction() with almost the
+ right settings, including appropriate interpretation
+ of DEFAULT and IGNORE. However, why are we doing
+ this when we're about to do it again just below? XXX */
+ mg_set(*sigsvp);
+
+ /* And here again we duplicate -- DEFAULT/IGNORE checking. */
if(SvPOK(*svp)) {
- char *s=SvPVX(*svp);
+ const char *s=SvPVX_const(*svp);
if(strEQ(s,"IGNORE")) {
act.sa_handler = SIG_IGN;
}
else if(strEQ(s,"DEFAULT")) {
act.sa_handler = SIG_DFL;
}
- else {
- act.sa_handler = PL_sighandlerp;
- }
- }
- else {
- act.sa_handler = PL_sighandlerp;
}
/* Set up any desired mask. */
- svp = hv_fetch(action, "MASK", 4, FALSE);
+ svp = hv_fetchs(action, "MASK", FALSE);
if (svp && sv_isa(*svp, "POSIX::SigSet")) {
IV tmp = SvIV((SV*)SvRV(*svp));
sigset = INT2PTR(sigset_t*, tmp);
sigemptyset(& act.sa_mask);
/* Set up any desired flags. */
- svp = hv_fetch(action, "FLAGS", 5, FALSE);
+ svp = hv_fetchs(action, "FLAGS", FALSE);
act.sa_flags = svp ? SvIV(*svp) : 0;
/* Don't worry about cleaning up *sigsvp if this fails,
* essentially meaningless anyway.
*/
RETVAL = sigaction(sig, & act, (struct sigaction *)0);
+ if(RETVAL == -1)
+ XSRETURN_UNDEF;
}
LEAVE;
SysRet
sigprocmask(how, sigset, oldsigset = 0)
int how
- POSIX::SigSet sigset
+ POSIX::SigSet sigset = NO_INIT
POSIX::SigSet oldsigset = NO_INIT
INIT:
- if ( items < 3 ) {
- oldsigset = 0;
+ if (! SvOK(ST(1))) {
+ sigset = NULL;
+ } else if (sv_isa(ST(1), "POSIX::SigSet")) {
+ IV tmp = SvIV((SV*)SvRV(ST(1)));
+ sigset = INT2PTR(POSIX__SigSet,tmp);
+ } else {
+ croak("sigset is not of type POSIX::SigSet");
}
- else if (sv_derived_from(ST(2), "POSIX::SigSet")) {
+
+ if (items < 3 || ! SvOK(ST(2))) {
+ oldsigset = NULL;
+ } else if (sv_isa(ST(2), "POSIX::SigSet")) {
IV tmp = SvIV((SV*)SvRV(ST(2)));
oldsigset = INT2PTR(POSIX__SigSet,tmp);
- }
- else {
- New(0, oldsigset, 1, sigset_t);
- sigemptyset(oldsigset);
- sv_setref_pv(ST(2), "POSIX::SigSet", (void*)oldsigset);
+ } else {
+ croak("oldsigset is not of type POSIX::SigSet");
}
SysRet
int fd1
int fd2
-SysRetLong
+SV *
lseek(fd, offset, whence)
int fd
Off_t offset
int whence
+ CODE:
+ Off_t pos = PerlLIO_lseek(fd, offset, whence);
+ RETVAL = sizeof(Off_t) > sizeof(IV)
+ ? newSVnv((NV)pos) : newSViv((IV)pos);
+ OUTPUT:
+ RETVAL
-SysRet
+void
nice(incr)
int incr
+ PPCODE:
+ errno = 0;
+ if ((incr = nice(incr)) != -1 || errno == 0) {
+ if (incr == 0)
+ XPUSHs(sv_2mortal(newSVpvn("0 but true", 10)));
+ else
+ XPUSHs(sv_2mortal(newSViv(incr)));
+ }
void
pipe()
char * buffer = sv_grow( sv_buffer, nbytes+1 );
CLEANUP:
if (RETVAL >= 0) {
- SvCUR(sv_buffer) = RETVAL;
+ SvCUR_set(sv_buffer, RETVAL);
SvPOK_only(sv_buffer);
*SvEND(sv_buffer) = '\0';
SvTAINTED_on(sv_buffer);
char *unparsed;
PPCODE:
num = strtoul(str, &unparsed, base);
- if (num <= IV_MAX)
- PUSHs(sv_2mortal(newSViv((IV)num)));
- else
+#if IVSIZE <= LONGSIZE
+ if (num > IV_MAX)
PUSHs(sv_2mortal(newSVnv((double)num)));
+ else
+#endif
+ PUSHs(sv_2mortal(newSViv((IV)num)));
if (GIMME == G_ARRAY) {
EXTEND(SP, 1);
if (unparsed)
STRLEN dstlen;
char *p = SvPV(src,srclen);
srclen++;
- ST(0) = sv_2mortal(NEWSV(800,srclen));
+ ST(0) = sv_2mortal(newSV(srclen*4+1));
dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
if (dstlen > srclen) {
dstlen++;
strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);
dstlen--;
}
- SvCUR(ST(0)) = dstlen;
+ SvCUR_set(ST(0), dstlen);
SvPOK_only(ST(0));
}
int duration
char *
-asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
+asctime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
int sec
int min
int hour
Time_t time2
SysRetLong
-mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)
+mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = -1)
int sec
int min
int hour
mytm.tm_wday = wday;
mytm.tm_yday = yday;
mytm.tm_isdst = isdst;
- RETVAL = mktime(&mytm);
+ RETVAL = (SysRetLong) mktime(&mytm);
}
OUTPUT:
RETVAL
char *
ctermid(s = 0)
- char * s = 0;
+ char * s = 0;
+ CODE:
+#ifdef HAS_CTERMID_R
+ s = (char *) safemalloc((size_t) L_ctermid);
+#endif
+ RETVAL = ctermid(s);
+ OUTPUT:
+ RETVAL
+ CLEANUP:
+#ifdef HAS_CTERMID_R
+ Safefree(s);
+#endif
char *
cuserid(s = 0)
SysRet
setgid(gid)
Gid_t gid
+ CLEANUP:
+#ifndef WIN32
+ if (RETVAL >= 0) {
+ PL_gid = getgid();
+ PL_egid = getegid();
+ }
+#endif
SysRet
setuid(uid)
Uid_t uid
+ CLEANUP:
+#ifndef WIN32
+ if (RETVAL >= 0) {
+ PL_uid = getuid();
+ PL_euid = geteuid();
+ }
+#endif
SysRetLong
sysconf(name)
ttyname(fd)
int fd
-#XXX: use sv_getcwd()
void
getcwd()
- PPCODE:
-#ifdef HAS_GETCWD
- char * buf;
- int buflen = 128;
-
- New(0, buf, buflen, char);
- /* Many getcwd()s know how to automatically allocate memory
- * for the directory if the buffer argument is NULL but...
- * (1) we cannot assume all getcwd()s do that
- * (2) this may interfere with Perl's malloc
- * So let's not. --jhi */
- while ((getcwd(buf, buflen) == NULL) && errno == ERANGE) {
- buflen += 128;
- if (buflen > MAXPATHLEN) {
- Safefree(buf);
- buf = NULL;
- break;
- }
- Renew(buf, buflen, char);
- }
- if (buf) {
- PUSHs(sv_2mortal(newSVpv(buf, 0)));
- Safefree(buf);
- }
- else
- PUSHs(&PL_sv_undef);
+ PPCODE:
+ {
+ dXSTARG;
+ getcwd_sv(TARG);
+ XSprePUSH; PUSHTARG;
+ }
+
+SysRet
+lchown(uid, gid, path)
+ Uid_t uid
+ Gid_t gid
+ char * path
+ CODE:
+#ifdef HAS_LCHOWN
+ /* yes, the order of arguments is different,
+ * but consistent with CORE::chown() */
+ RETVAL = lchown(path, uid, gid);
#else
- require_pv("Cwd.pm");
- /* Module require may have grown the stack */
- SPAGAIN;
- PUSHMARK(sp);
- PUTBACK;
- XSRETURN(call_pv("Cwd::cwd", GIMME_V));
+ RETVAL = not_here("lchown");
#endif
+ OUTPUT:
+ RETVAL