/* pp_sys.c
*
- * Copyright (c) 1991-1997, Larry Wall
+ * Copyright (c) 1991-1999, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
#include "EXTERN.h"
#include "perl.h"
+#ifdef HAS_GETSPENT
+/* Shadow password support for solaris - pdo@cs.umd.edu*/
+#include <shadow.h>
+#endif
+
/* XXX If this causes problems, set i_unistd=undef in the hint file. */
#ifdef I_UNISTD
# include <unistd.h>
#endif
+#ifdef HAS_SYSCALL
+#ifdef __cplusplus
+extern "C" int syscall(unsigned long,...);
+#endif
+#endif
+
#ifdef I_SYS_WAIT
# include <sys/wait.h>
#endif
#if defined(HAS_SOCKET) && !defined(VMS) /* VMS handles sockets via vmsish.h */
# include <sys/socket.h>
-# include <netdb.h>
+# ifdef I_NETDB
+# include <netdb.h>
+# endif
# ifndef ENOTSOCK
# ifdef I_NET_ERRNO
# include <net/errno.h>
#endif
#endif
-#ifdef HOST_NOT_FOUND
+/* XXX Configure test needed.
+ h_errno might not be a simple 'int', especially for multi-threaded
+ applications, see "extern int errno in perl.h". Creating such
+ a test requires taking into account the differences between
+ compiling multithreaded and singlethreaded ($ccflags et al).
+ HOST_NOT_FOUND is typically defined in <netdb.h>.
+*/
+#if defined(HOST_NOT_FOUND) && !defined(h_errno)
extern int h_errno;
#endif
struct passwd *getpwnam _((char *));
struct passwd *getpwuid _((Uid_t));
# endif
+# ifdef HAS_GETPWENT
struct passwd *getpwent _((void));
+# endif
#endif
#ifdef HAS_GROUP
struct group *getgrnam _((char *));
struct group *getgrgid _((Gid_t));
# endif
+# ifdef HAS_GETGRENT
struct group *getgrent _((void));
+# endif
#endif
#ifdef I_UTIME
-# ifdef WIN32
+# if defined(_MSC_VER) || defined(__MINGW32__)
# include <sys/utime.h>
# else
# include <utime.h>
# ifdef my_chsize /* Probably #defined to Perl_my_chsize in embed.h */
# undef my_chsize
# endif
-# define my_chsize chsize
+# define my_chsize PerlLIO_chsize
#endif
#ifdef HAS_FLOCK
#endif /* no flock() */
-#ifndef MAXPATHLEN
-# ifdef PATH_MAX
-# define MAXPATHLEN PATH_MAX
-# else
-# define MAXPATHLEN 1024
-# endif
-#endif
-
#define ZBTLEN 10
static char zero_but_true[ZBTLEN + 1] = "0 but true";
-/* Pushy I/O. */
+#if defined(I_SYS_ACCESS) && !defined(R_OK)
+# include <sys/access.h>
+#endif
+
+#undef PERL_EFF_ACCESS_R_OK /* EFFective uid/gid ACCESS R_OK */
+#undef PERL_EFF_ACCESS_W_OK
+#undef PERL_EFF_ACCESS_X_OK
+
+/* F_OK unused: if stat() cannot find it... */
+
+#if !defined(PERL_EFF_ACCESS_R_OK) && defined(HAS_ACCESS) && defined(EFF_ONLY_OK) && !defined(NO_EFF_ONLY_OK)
+ /* Digital UNIX (when the EFF_ONLY_OK gets fixed), UnixWare */
+# define PERL_EFF_ACCESS_R_OK(p) (access((p), R_OK | EFF_ONLY_OK))
+# define PERL_EFF_ACCESS_W_OK(p) (access((p), W_OK | EFF_ONLY_OK))
+# define PERL_EFF_ACCESS_X_OK(p) (access((p), X_OK | EFF_ONLY_OK))
+#endif
+
+#if !defined(PERL_EFF_ACCESS_R_OK) && defined(HAS_EACCESS)
+# if defined(I_SYS_SECURITY)
+# include <sys/security.h>
+# endif
+ /* XXX Configure test needed for eaccess */
+# ifdef ACC_SELF
+ /* HP SecureWare */
+# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK, ACC_SELF))
+# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK, ACC_SELF))
+# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK, ACC_SELF))
+# else
+ /* SCO */
+# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK))
+# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK))
+# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK))
+# endif
+#endif
+
+#if !defined(PERL_EFF_ACCESS_R_OK) && defined(HAS_ACCESSX) && defined(ACC_SELF)
+ /* AIX */
+# define PERL_EFF_ACCESS_R_OK(p) (accessx((p), R_OK, ACC_SELF))
+# define PERL_EFF_ACCESS_W_OK(p) (accessx((p), W_OK, ACC_SELF))
+# define PERL_EFF_ACCESS_X_OK(p) (accessx((p), X_OK, ACC_SELF))
+#endif
+
+#if !defined(PERL_EFF_ACCESS_R_OK) && defined(HAS_ACCESS) \
+ && (defined(HAS_SETREUID) || defined(HAS_SETRESUID) \
+ || defined(HAS_SETREGID) || defined(HAS_SETRESGID))
+/* The Hard Way. */
+STATIC int
+emulate_eaccess (const char* path, int mode) {
+ Uid_t ruid = getuid();
+ Uid_t euid = geteuid();
+ Gid_t rgid = getgid();
+ Gid_t egid = getegid();
+ int res;
+
+ MUTEX_LOCK(&PL_cred_mutex);
+#if !defined(HAS_SETREUID) && !defined(HAS_SETRESUID)
+ croak("switching effective uid is not implemented");
+#else
+#ifdef HAS_SETREUID
+ if (setreuid(euid, ruid))
+#else
+#ifdef HAS_SETRESUID
+ if (setresuid(euid, ruid, (Uid_t)-1))
+#endif
+#endif
+ croak("entering effective uid failed");
+#endif
+
+#if !defined(HAS_SETREGID) && !defined(HAS_SETRESGID)
+ croak("switching effective gid is not implemented");
+#else
+#ifdef HAS_SETREGID
+ if (setregid(egid, rgid))
+#else
+#ifdef HAS_SETRESGID
+ if (setresgid(egid, rgid, (Gid_t)-1))
+#endif
+#endif
+ croak("entering effective gid failed");
+#endif
+
+ res = access(path, mode);
+
+#ifdef HAS_SETREUID
+ if (setreuid(ruid, euid))
+#else
+#ifdef HAS_SETRESUID
+ if (setresuid(ruid, euid, (Uid_t)-1))
+#endif
+#endif
+ croak("leaving effective uid failed");
+
+#ifdef HAS_SETREGID
+ if (setregid(rgid, egid))
+#else
+#ifdef HAS_SETRESGID
+ if (setresgid(rgid, egid, (Gid_t)-1))
+#endif
+#endif
+ croak("leaving effective gid failed");
+ MUTEX_UNLOCK(&PL_cred_mutex);
+
+ return res;
+}
+# define PERL_EFF_ACCESS_R_OK(p) (emulate_eaccess((p), R_OK))
+# define PERL_EFF_ACCESS_W_OK(p) (emulate_eaccess((p), W_OK))
+# define PERL_EFF_ACCESS_X_OK(p) (emulate_eaccess((p), X_OK))
+#endif
+
+#if !defined(PERL_EFF_ACCESS_R_OK)
+STATIC int
+emulate_eaccess (const char* path, int mode) {
+ croak("switching effective uid is not implemented");
+ /*NOTREACHED*/
+ return -1;
+}
+#endif
PP(pp_backtick)
{
- dSP; dTARGET;
+ djSP; dTARGET;
PerlIO *fp;
- char *tmps = POPp;
+ STRLEN n_a;
+ char *tmps = POPpx;
I32 gimme = GIMME_V;
TAINT_PROPER("``");
- fp = my_popen(tmps, "r");
+ fp = PerlProc_popen(tmps, "r");
if (fp) {
if (gimme == G_VOID) {
- while (PerlIO_read(fp, tokenbuf, sizeof tokenbuf) > 0)
+ char tmpbuf[256];
+ while (PerlIO_read(fp, tmpbuf, sizeof tmpbuf) > 0)
/*SUPPRESS 530*/
;
}
SV *sv;
for (;;) {
- sv = NEWSV(56, 80);
+ sv = NEWSV(56, 79);
if (sv_gets(sv, fp, 0) == Nullch) {
SvREFCNT_dec(sv);
break;
SvTAINTED_on(sv);
}
}
- STATUS_NATIVE_SET(my_pclose(fp));
+ STATUS_NATIVE_SET(PerlProc_pclose(fp));
TAINT; /* "I believe that this is not gratuitous!" */
}
else {
PP(pp_glob)
{
OP *result;
+ tryAMAGICunTARGET(iter, -1);
+
ENTER;
- SAVESPTR(last_in_gv); /* We don't want this to be permanent. */
- last_in_gv = (GV*)*stack_sp--;
+#ifndef VMS
+ if (PL_tainting) {
+ /*
+ * The external globbing program may use things we can't control,
+ * so for security reasons we must assume the worst.
+ */
+ TAINT;
+ taint_proper(PL_no_security, "glob");
+ }
+#endif /* !VMS */
- SAVESPTR(rs); /* This is not permanent, either. */
- rs = sv_2mortal(newSVpv("", 1));
+ SAVESPTR(PL_last_in_gv); /* We don't want this to be permanent. */
+ PL_last_in_gv = (GV*)*PL_stack_sp--;
+
+ SAVESPTR(PL_rs); /* This is not permanent, either. */
+ PL_rs = sv_2mortal(newSVpvn("\000", 1));
#ifndef DOSISH
#ifndef CSH
- *SvPVX(rs) = '\n';
+ *SvPVX(PL_rs) = '\n';
#endif /* !CSH */
#endif /* !DOSISH */
return result;
}
+#if 0 /* XXX never used! */
PP(pp_indread)
{
- last_in_gv = gv_fetchpv(SvPVx(GvSV((GV*)(*stack_sp--)), na), TRUE,SVt_PVIO);
+ STRLEN n_a;
+ PL_last_in_gv = gv_fetchpv(SvPVx(GvSV((GV*)(*PL_stack_sp--)), n_a), TRUE,SVt_PVIO);
return do_readline();
}
+#endif
PP(pp_rcatline)
{
- last_in_gv = cGVOP->op_gv;
+ PL_last_in_gv = cGVOP->op_gv;
return do_readline();
}
PP(pp_warn)
{
- dSP; dMARK;
+ djSP; dMARK;
+ SV *tmpsv;
char *tmps;
+ STRLEN len;
if (SP - MARK != 1) {
dTARGET;
- do_join(TARG, &sv_no, MARK, SP);
- tmps = SvPV(TARG, na);
+ do_join(TARG, &PL_sv_no, MARK, SP);
+ tmpsv = TARG;
SP = MARK + 1;
}
else {
- tmps = SvPV(TOPs, na);
+ tmpsv = TOPs;
}
- if (!tmps || !*tmps) {
- SV *error = GvSV(errgv);
+ tmps = SvPV(tmpsv, len);
+ if (!tmps || !len) {
+ SV *error = ERRSV;
(void)SvUPGRADE(error, SVt_PV);
if (SvPOK(error) && SvCUR(error))
sv_catpv(error, "\t...caught");
- tmps = SvPV(error, na);
+ tmpsv = error;
+ tmps = SvPV(tmpsv, len);
}
- if (!tmps || !*tmps)
- tmps = "Warning: something's wrong";
- warn("%s", tmps);
+ if (!tmps || !len)
+ tmpsv = sv_2mortal(newSVpvn("Warning: something's wrong", 26));
+
+ warn("%_", tmpsv);
RETSETYES;
}
PP(pp_die)
{
- dSP; dMARK;
+ djSP; dMARK;
char *tmps;
+ SV *tmpsv;
+ STRLEN len;
+ bool multiarg = 0;
if (SP - MARK != 1) {
dTARGET;
- do_join(TARG, &sv_no, MARK, SP);
- tmps = SvPV(TARG, na);
+ do_join(TARG, &PL_sv_no, MARK, SP);
+ tmpsv = TARG;
+ tmps = SvPV(tmpsv, len);
+ multiarg = 1;
SP = MARK + 1;
}
else {
- tmps = SvPV(TOPs, na);
+ tmpsv = TOPs;
+ tmps = SvROK(tmpsv) ? Nullch : SvPV(tmpsv, len);
}
- if (!tmps || !*tmps) {
- SV *error = GvSV(errgv);
+ if (!tmps || !len) {
+ SV *error = ERRSV;
(void)SvUPGRADE(error, SVt_PV);
- if (SvPOK(error) && SvCUR(error))
- sv_catpv(error, "\t...propagated");
- tmps = SvPV(error, na);
+ if (multiarg ? SvROK(error) : SvROK(tmpsv)) {
+ if (!multiarg)
+ SvSetSV(error,tmpsv);
+ else if (sv_isobject(error)) {
+ HV *stash = SvSTASH(SvRV(error));
+ GV *gv = gv_fetchmethod(stash, "PROPAGATE");
+ if (gv) {
+ SV *file = sv_2mortal(newSVsv(GvSV(PL_curcop->cop_filegv)));
+ SV *line = sv_2mortal(newSViv(PL_curcop->cop_line));
+ EXTEND(SP, 3);
+ PUSHMARK(SP);
+ PUSHs(error);
+ PUSHs(file);
+ PUSHs(line);
+ PUTBACK;
+ perl_call_sv((SV*)GvCV(gv),
+ G_SCALAR|G_EVAL|G_KEEPERR);
+ sv_setsv(error,*PL_stack_sp--);
+ }
+ }
+ DIE(Nullch);
+ }
+ else {
+ if (SvPOK(error) && SvCUR(error))
+ sv_catpv(error, "\t...propagated");
+ tmpsv = error;
+ tmps = SvPV(tmpsv, len);
+ }
}
- if (!tmps || !*tmps)
- tmps = "Died";
- DIE("%s", tmps);
+ if (!tmps || !len)
+ tmpsv = sv_2mortal(newSVpvn("Died", 4));
+
+ DIE("%_", tmpsv);
}
/* I/O. */
PP(pp_open)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *gv;
SV *sv;
char *tmps;
STRLEN len;
+ MAGIC *mg;
if (MAXARG > 1)
sv = POPs;
if (!isGV(TOPs))
- DIE(no_usym, "filehandle");
+ DIE(PL_no_usym, "filehandle");
if (MAXARG <= 1)
sv = GvSV(TOPs);
gv = (GV*)POPs;
if (!isGV(gv))
- DIE(no_usym, "filehandle");
+ DIE(PL_no_usym, "filehandle");
if (GvIOp(gv))
IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT;
+
+#if 0 /* no undef means tmpfile() yet */
+ if (sv == &PL_sv_undef) {
+#ifdef PerlIO
+ PerlIO *fp = PerlIO_tmpfile();
+#else
+ PerlIO *fp = tmpfile();
+#endif
+ if (fp != Nullfp && do_open(gv, "+>&", 3, FALSE, 0, 0, fp))
+ PUSHi( (I32)PL_forkprocess );
+ else
+ RETPUSHUNDEF;
+ RETURN;
+ }
+#endif /* no undef means tmpfile() yet */
+
+
+ if (mg = SvTIED_mg((SV*)gv, 'q')) {
+ PUSHMARK(SP);
+ XPUSHs(SvTIED_obj((SV*)gv, mg));
+ XPUSHs(sv);
+ PUTBACK;
+ ENTER;
+ perl_call_method("OPEN", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
+ }
+
tmps = SvPV(sv, len);
- if (do_open(gv, tmps, len, FALSE, 0, 0, Nullfp))
- PUSHi( (I32)forkprocess );
- else if (forkprocess == 0) /* we are a new child */
+ if (do_open(gv, tmps, len, FALSE, O_RDONLY, 0, Nullfp))
+ PUSHi( (I32)PL_forkprocess );
+ else if (PL_forkprocess == 0) /* we are a new child */
PUSHi(0);
else
RETPUSHUNDEF;
PP(pp_close)
{
- dSP;
+ djSP;
GV *gv;
+ MAGIC *mg;
if (MAXARG == 0)
- gv = defoutgv;
+ gv = PL_defoutgv;
else
gv = (GV*)POPs;
+
+ if (mg = SvTIED_mg((SV*)gv, 'q')) {
+ PUSHMARK(SP);
+ XPUSHs(SvTIED_obj((SV*)gv, mg));
+ PUTBACK;
+ ENTER;
+ perl_call_method("CLOSE", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
+ }
EXTEND(SP, 1);
PUSHs(boolSV(do_close(gv, TRUE)));
RETURN;
PP(pp_pipe_op)
{
- dSP;
+ djSP;
#ifdef HAS_PIPE
GV *rgv;
GV *wgv;
goto badexit;
if (SvTYPE(rgv) != SVt_PVGV || SvTYPE(wgv) != SVt_PVGV)
- DIE(no_usym, "filehandle");
+ DIE(PL_no_usym, "filehandle");
rstio = GvIOn(rgv);
wstio = GvIOn(wgv);
if (IoIFP(wstio))
do_close(wgv, FALSE);
- if (pipe(fd) < 0)
+ if (PerlProc_pipe(fd) < 0)
goto badexit;
IoIFP(rstio) = PerlIO_fdopen(fd[0], "r");
if (!IoIFP(rstio) || !IoOFP(wstio)) {
if (IoIFP(rstio)) PerlIO_close(IoIFP(rstio));
- else close(fd[0]);
+ else PerlLIO_close(fd[0]);
if (IoOFP(wstio)) PerlIO_close(IoOFP(wstio));
- else close(fd[1]);
+ else PerlLIO_close(fd[1]);
goto badexit;
}
-
+#if defined(HAS_FCNTL) && defined(F_SETFD)
+ fcntl(fd[0],F_SETFD,fd[0] > PL_maxsysfd); /* ensure close-on-exec */
+ fcntl(fd[1],F_SETFD,fd[1] > PL_maxsysfd); /* ensure close-on-exec */
+#endif
RETPUSHYES;
badexit:
RETPUSHUNDEF;
#else
- DIE(no_func, "pipe");
+ DIE(PL_no_func, "pipe");
#endif
}
PP(pp_fileno)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *gv;
IO *io;
PerlIO *fp;
+ MAGIC *mg;
+
if (MAXARG < 1)
RETPUSHUNDEF;
gv = (GV*)POPs;
+
+ if (gv && (mg = SvTIED_mg((SV*)gv, 'q'))) {
+ PUSHMARK(SP);
+ XPUSHs(SvTIED_obj((SV*)gv, mg));
+ PUTBACK;
+ ENTER;
+ perl_call_method("FILENO", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
+ }
+
if (!gv || !(io = GvIO(gv)) || !(fp = IoIFP(io)))
RETPUSHUNDEF;
PUSHi(PerlIO_fileno(fp));
PP(pp_umask)
{
- dSP; dTARGET;
- int anum;
+ djSP; dTARGET;
+ Mode_t anum;
#ifdef HAS_UMASK
if (MAXARG < 1) {
- anum = umask(0);
- (void)umask(anum);
+ anum = PerlLIO_umask(0);
+ (void)PerlLIO_umask(anum);
}
else
- anum = umask(POPi);
+ anum = PerlLIO_umask(POPi);
TAINT_PROPER("umask");
XPUSHi(anum);
#else
- DIE(no_func, "Unsupported function umask");
+ /* Only DIE if trying to restrict permissions on `user' (self).
+ * Otherwise it's harmless and more useful to just return undef
+ * since 'group' and 'other' concepts probably don't exist here. */
+ if (MAXARG >= 1 && (POPi & 0700))
+ DIE("umask not implemented");
+ XPUSHs(&PL_sv_undef);
#endif
RETURN;
}
PP(pp_binmode)
{
- dSP;
+ djSP;
GV *gv;
IO *io;
PerlIO *fp;
+ MAGIC *mg;
if (MAXARG < 1)
RETPUSHUNDEF;
- gv = (GV*)POPs;
+ gv = (GV*)POPs;
+
+ if (gv && (mg = SvTIED_mg((SV*)gv, 'q'))) {
+ PUSHMARK(SP);
+ XPUSHs(SvTIED_obj((SV*)gv, mg));
+ PUTBACK;
+ ENTER;
+ perl_call_method("BINMODE", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
+ }
EXTEND(SP, 1);
if (!(io = GvIO(gv)) || !(fp = IoIFP(io)))
RETPUSHUNDEF;
-#ifdef DOSISH
-#ifdef atarist
- if (!PerlIO_flush(fp) && (fp->_flag |= _IOBIN))
- RETPUSHYES;
- else
- RETPUSHUNDEF;
-#else
- if (setmode(PerlIO_fileno(fp), OP_BINARY) != -1)
+ if (do_binmode(fp,IoTYPE(io),TRUE))
RETPUSHYES;
else
RETPUSHUNDEF;
-#endif
-#else
-#if defined(USEMYBINMODE)
- if (my_binmode(fp,IoTYPE(io)) != NULL)
- RETPUSHYES;
- else
- RETPUSHUNDEF;
-#else
- RETPUSHYES;
-#endif
-#endif
-
}
+
PP(pp_tie)
{
- dSP;
+ djSP;
+ dMARK;
SV *varsv;
HV* stash;
GV *gv;
- BINOP myop;
SV *sv;
- SV **mark = stack_base + ++*markstack_ptr; /* reuse in entersub */
- I32 markoff = mark - stack_base - 1;
+ I32 markoff = MARK - PL_stack_base;
char *methname;
- bool oldcatch = CATCH_GET;
-
- varsv = mark[0];
- if (SvTYPE(varsv) == SVt_PVHV)
- methname = "TIEHASH";
- else if (SvTYPE(varsv) == SVt_PVAV)
- methname = "TIEARRAY";
- else if (SvTYPE(varsv) == SVt_PVGV)
- methname = "TIEHANDLE";
- else
- methname = "TIESCALAR";
-
- stash = gv_stashsv(mark[1], FALSE);
- if (!stash || !(gv = gv_fetchmethod(stash, methname)))
- DIE("Can't locate object method \"%s\" via package \"%s\"",
- methname, SvPV(mark[1],na));
-
- Zero(&myop, 1, BINOP);
- myop.op_last = (OP *) &myop;
- myop.op_next = Nullop;
- myop.op_flags = OPf_WANT_SCALAR | OPf_STACKED;
- CATCH_SET(TRUE);
-
- ENTER;
- SAVESPTR(op);
- op = (OP *) &myop;
- if (perldb && curstash != debstash)
- op->op_private |= OPpENTERSUB_DB;
-
- XPUSHs((SV*)GvCV(gv));
- PUTBACK;
-
- if (op = pp_entersub())
- runops();
+ int how = 'P';
+ U32 items;
+ STRLEN n_a;
+
+ varsv = *++MARK;
+ switch(SvTYPE(varsv)) {
+ case SVt_PVHV:
+ methname = "TIEHASH";
+ break;
+ case SVt_PVAV:
+ methname = "TIEARRAY";
+ break;
+ case SVt_PVGV:
+ methname = "TIEHANDLE";
+ how = 'q';
+ break;
+ default:
+ methname = "TIESCALAR";
+ how = 'q';
+ break;
+ }
+ items = SP - MARK++;
+ if (sv_isobject(*MARK)) {
+ ENTER;
+ PUSHSTACKi(PERLSI_MAGIC);
+ PUSHMARK(SP);
+ EXTEND(SP,items);
+ while (items--)
+ PUSHs(*MARK++);
+ PUTBACK;
+ perl_call_method(methname, G_SCALAR);
+ }
+ else {
+ /* Not clear why we don't call perl_call_method here too.
+ * perhaps to get different error message ?
+ */
+ stash = gv_stashsv(*MARK, FALSE);
+ if (!stash || !(gv = gv_fetchmethod(stash, methname))) {
+ DIE("Can't locate object method \"%s\" via package \"%s\"",
+ methname, SvPV(*MARK,n_a));
+ }
+ ENTER;
+ PUSHSTACKi(PERLSI_MAGIC);
+ PUSHMARK(SP);
+ EXTEND(SP,items);
+ while (items--)
+ PUSHs(*MARK++);
+ PUTBACK;
+ perl_call_sv((SV*)GvCV(gv), G_SCALAR);
+ }
SPAGAIN;
- CATCH_SET(oldcatch);
sv = TOPs;
+ POPSTACK;
if (sv_isobject(sv)) {
- if (SvTYPE(varsv) == SVt_PVHV || SvTYPE(varsv) == SVt_PVAV) {
- sv_unmagic(varsv, 'P');
- sv_magic(varsv, sv, 'P', Nullch, 0);
- }
- else {
- sv_unmagic(varsv, 'q');
- sv_magic(varsv, sv, 'q', Nullch, 0);
- }
+ sv_unmagic(varsv, how);
+ sv_magic(varsv, (SvRV(sv) == varsv ? Nullsv : sv), how, Nullch, 0);
}
LEAVE;
- SP = stack_base + markoff;
+ SP = PL_stack_base + markoff;
PUSHs(sv);
RETURN;
}
PP(pp_untie)
{
- dSP;
- SV * sv ;
+ djSP;
+ SV *sv = POPs;
+ char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV) ? 'P' : 'q';
- sv = POPs;
-
- if (dowarn) {
+ if (ckWARN(WARN_UNTIE)) {
MAGIC * mg ;
- if (SvMAGICAL(sv)) {
- if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
- mg = mg_find(sv, 'P') ;
- else
- mg = mg_find(sv, 'q') ;
-
+ if (mg = SvTIED_mg(sv, how)) {
if (mg && SvREFCNT(SvRV(mg->mg_obj)) > 1)
- warn("untie attempted while %lu inner references still exist",
- (unsigned long)SvREFCNT(SvRV(mg->mg_obj)) - 1 ) ;
+ warner(WARN_UNTIE,
+ "untie attempted while %lu inner references still exist",
+ (unsigned long)SvREFCNT(SvRV(mg->mg_obj)) - 1 ) ;
}
}
- if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
- sv_unmagic(sv, 'P');
- else
- sv_unmagic(sv, 'q');
+ sv_unmagic(sv, how);
RETPUSHYES;
}
PP(pp_tied)
{
- dSP;
- SV * sv ;
- MAGIC * mg ;
+ djSP;
+ SV *sv = POPs;
+ char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV) ? 'P' : 'q';
+ MAGIC *mg;
- sv = POPs;
- if (SvMAGICAL(sv)) {
- if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
- mg = mg_find(sv, 'P') ;
- else
- mg = mg_find(sv, 'q') ;
-
- if (mg) {
- PUSHs(sv_2mortal(newSVsv(mg->mg_obj))) ;
- RETURN ;
- }
+ if (mg = SvTIED_mg(sv, how)) {
+ SV *osv = SvTIED_obj(sv, mg);
+ if (osv == mg->mg_obj)
+ osv = sv_mortalcopy(osv);
+ PUSHs(osv);
+ RETURN;
}
-
RETPUSHUNDEF;
}
PP(pp_dbmopen)
{
- dSP;
+ djSP;
HV *hv;
dPOPPOPssrl;
HV* stash;
GV *gv;
- BINOP myop;
SV *sv;
- bool oldcatch = CATCH_GET;
hv = (HV*)POPs;
- sv = sv_mortalcopy(&sv_no);
+ sv = sv_mortalcopy(&PL_sv_no);
sv_setpv(sv, "AnyDBM_File");
stash = gv_stashsv(sv, FALSE);
if (!stash || !(gv = gv_fetchmethod(stash, "TIEHASH"))) {
DIE("No dbm on this machine");
}
- Zero(&myop, 1, BINOP);
- myop.op_last = (OP *) &myop;
- myop.op_next = Nullop;
- myop.op_flags = OPf_WANT_SCALAR | OPf_STACKED;
- CATCH_SET(TRUE);
-
ENTER;
- SAVESPTR(op);
- op = (OP *) &myop;
- if (perldb && curstash != debstash)
- op->op_private |= OPpENTERSUB_DB;
- PUTBACK;
- pp_pushmark();
+ PUSHMARK(SP);
- EXTEND(sp, 5);
+ EXTEND(SP, 5);
PUSHs(sv);
PUSHs(left);
if (SvIV(right))
else
PUSHs(sv_2mortal(newSViv(O_RDWR)));
PUSHs(right);
- PUSHs((SV*)GvCV(gv));
PUTBACK;
-
- if (op = pp_entersub())
- runops();
+ perl_call_sv((SV*)GvCV(gv), G_SCALAR);
SPAGAIN;
if (!sv_isobject(TOPs)) {
- sp--;
- op = (OP *) &myop;
- PUTBACK;
- pp_pushmark();
-
+ SP--;
+ PUSHMARK(SP);
PUSHs(sv);
PUSHs(left);
PUSHs(sv_2mortal(newSViv(O_RDONLY)));
PUSHs(right);
- PUSHs((SV*)GvCV(gv));
PUTBACK;
-
- if (op = pp_entersub())
- runops();
+ perl_call_sv((SV*)GvCV(gv), G_SCALAR);
SPAGAIN;
}
- CATCH_SET(oldcatch);
- if (sv_isobject(TOPs))
+ if (sv_isobject(TOPs)) {
+ sv_unmagic((SV *) hv, 'P');
sv_magic((SV*)hv, TOPs, 'P', Nullch, 0);
+ }
LEAVE;
RETURN;
}
PP(pp_sselect)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_SELECT
register I32 i;
register I32 j;
struct timeval *tbuf = &timebuf;
I32 growsize;
char *fd_sets[4];
+ STRLEN n_a;
#if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
I32 masksize;
I32 offset;
maxlen = j;
}
+/* little endians can use vecs directly */
#if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
-#if defined(__linux__) || defined(OS2)
+# if SELECT_MIN_BITS > 1
+ /* If SELECT_MIN_BITS is greater than one we most probably will want
+ * to align the sizes with SELECT_MIN_BITS/8 because for example
+ * in many little-endian (Intel, Alpha) systems (Linux, OS/2, Digital
+ * UNIX, Solaris, NeXT, Rhapsody) the smallest quantum select() operates
+ * on (sets/tests/clears bits) is 32 bits. */
+ growsize = maxlen + (SELECT_MIN_BITS/8 - (maxlen % (SELECT_MIN_BITS/8)));
+# else
growsize = sizeof(fd_set);
-#else
- growsize = maxlen; /* little endians can use vecs directly */
-#endif
-#else
-#ifdef NFDBITS
+# endif
+# else
+# ifdef NFDBITS
-#ifndef NBBY
-#define NBBY 8
-#endif
+# ifndef NBBY
+# define NBBY 8
+# endif
masksize = NFDBITS / NBBY;
-#else
+# else
masksize = sizeof(long); /* documented int, everyone seems to use long */
-#endif
+# endif
growsize = maxlen + (masksize - (maxlen % masksize));
Zero(&fd_sets[0], 4, char*);
#endif
continue;
}
else if (!SvPOK(sv))
- SvPV_force(sv,na); /* force string conversion */
+ SvPV_force(sv,n_a); /* force string conversion */
j = SvLEN(sv);
if (j < growsize) {
Sv_Grow(sv, growsize);
#endif
}
- nfound = select(
+ nfound = PerlSock_select(
maxlen * 8,
(Select_fd_set_t) fd_sets[1],
(Select_fd_set_t) fd_sets[2],
if (GIMME == G_ARRAY && tbuf) {
value = (double)(timebuf.tv_sec) +
(double)(timebuf.tv_usec) / 1000000.0;
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setnv(sv, value);
}
RETURN;
}
void
-setdefout(gv)
-GV *gv;
+setdefout(GV *gv)
{
+ dTHR;
if (gv)
(void)SvREFCNT_inc(gv);
- if (defoutgv)
- SvREFCNT_dec(defoutgv);
- defoutgv = gv;
+ if (PL_defoutgv)
+ SvREFCNT_dec(PL_defoutgv);
+ PL_defoutgv = gv;
}
PP(pp_select)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *newdefout, *egv;
HV *hv;
- newdefout = (op->op_private > 0) ? ((GV *) POPs) : NULL;
+ newdefout = (PL_op->op_private > 0) ? ((GV *) POPs) : (GV *) NULL;
- egv = GvEGV(defoutgv);
+ egv = GvEGV(PL_defoutgv);
if (!egv)
- egv = defoutgv;
+ egv = PL_defoutgv;
hv = GvSTASH(egv);
if (! hv)
- XPUSHs(&sv_undef);
+ XPUSHs(&PL_sv_undef);
else {
GV **gvp = (GV**)hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE);
if (gvp && *gvp == egv) {
- gv_efullname3(TARG, defoutgv, Nullch);
+ gv_efullname3(TARG, PL_defoutgv, Nullch);
XPUSHTARG;
}
else {
PP(pp_getc)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *gv;
MAGIC *mg;
if (MAXARG <= 0)
- gv = stdingv;
+ gv = PL_stdingv;
else
gv = (GV*)POPs;
if (!gv)
- gv = argvgv;
+ gv = PL_argvgv;
- if (SvMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
+ if (mg = SvTIED_mg((SV*)gv, 'q')) {
I32 gimme = GIMME_V;
PUSHMARK(SP);
- XPUSHs(mg->mg_obj);
+ XPUSHs(SvTIED_obj((SV*)gv, mg));
PUTBACK;
ENTER;
perl_call_method("GETC", gimme);
return pp_sysread(ARGS);
}
-static OP *
-doform(cv,gv,retop)
-CV *cv;
-GV *gv;
-OP *retop;
+STATIC OP *
+doform(CV *cv, GV *gv, OP *retop)
{
- register CONTEXT *cx;
+ dTHR;
+ register PERL_CONTEXT *cx;
I32 gimme = GIMME_V;
AV* padlist = CvPADLIST(cv);
SV** svp = AvARRAY(padlist);
SAVETMPS;
push_return(retop);
- PUSHBLOCK(cx, CXt_SUB, stack_sp);
+ PUSHBLOCK(cx, CXt_SUB, PL_stack_sp);
PUSHFORMAT(cx);
- SAVESPTR(curpad);
- curpad = AvARRAY((AV*)svp[1]);
+ SAVESPTR(PL_curpad);
+ PL_curpad = AvARRAY((AV*)svp[1]);
setdefout(gv); /* locally select filehandle so $% et al work */
return CvSTART(cv);
PP(pp_enterwrite)
{
- dSP;
+ djSP;
register GV *gv;
register IO *io;
GV *fgv;
CV *cv;
if (MAXARG == 0)
- gv = defoutgv;
+ gv = PL_defoutgv;
else {
gv = (GV*)POPs;
if (!gv)
- gv = defoutgv;
+ gv = PL_defoutgv;
}
EXTEND(SP, 1);
io = GvIO(gv);
cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
IoFLAGS(io) &= ~IOf_DIDTOP;
- return doform(cv,gv,op->op_next);
+ return doform(cv,gv,PL_op->op_next);
}
PP(pp_leavewrite)
{
- dSP;
+ djSP;
GV *gv = cxstack[cxstack_ix].blk_sub.gv;
register IO *io = GvIOp(gv);
PerlIO *ofp = IoOFP(io);
PerlIO *fp;
SV **newsp;
I32 gimme;
- register CONTEXT *cx;
+ register PERL_CONTEXT *cx;
DEBUG_f(PerlIO_printf(Perl_debug_log, "left=%ld, todo=%ld\n",
- (long)IoLINES_LEFT(io), (long)FmLINES(formtarget)));
- if (IoLINES_LEFT(io) < FmLINES(formtarget) &&
- formtarget != toptarget)
+ (long)IoLINES_LEFT(io), (long)FmLINES(PL_formtarget)));
+ if (IoLINES_LEFT(io) < FmLINES(PL_formtarget) &&
+ PL_formtarget != PL_toptarget)
{
GV *fgv;
CV *cv;
}
if (IoFLAGS(io) & IOf_DIDTOP) { /* Oh dear. It still doesn't fit. */
I32 lines = IoLINES_LEFT(io);
- char *s = SvPVX(formtarget);
+ char *s = SvPVX(PL_formtarget);
if (lines <= 0) /* Yow, header didn't even fit!!! */
goto forget_top;
while (lines-- > 0) {
s++;
}
if (s) {
- PerlIO_write(ofp, SvPVX(formtarget), s - SvPVX(formtarget));
- sv_chop(formtarget, s);
- FmLINES(formtarget) -= IoLINES_LEFT(io);
+ PerlIO_write(ofp, SvPVX(PL_formtarget), s - SvPVX(PL_formtarget));
+ sv_chop(PL_formtarget, s);
+ FmLINES(PL_formtarget) -= IoLINES_LEFT(io);
}
}
if (IoLINES_LEFT(io) >= 0 && IoPAGE(io) > 0)
- PerlIO_write(ofp, SvPVX(formfeed), SvCUR(formfeed));
+ PerlIO_write(ofp, SvPVX(PL_formfeed), SvCUR(PL_formfeed));
IoLINES_LEFT(io) = IoPAGE_LEN(io);
IoPAGE(io)++;
- formtarget = toptarget;
+ PL_formtarget = PL_toptarget;
IoFLAGS(io) |= IOf_DIDTOP;
fgv = IoTOP_GV(io);
if (!fgv)
}
if (CvCLONE(cv))
cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
- return doform(cv,gv,op);
+ return doform(cv,gv,PL_op);
}
forget_top:
- POPBLOCK(cx,curpm);
+ POPBLOCK(cx,PL_curpm);
POPFORMAT(cx);
LEAVE;
fp = IoOFP(io);
if (!fp) {
- if (dowarn) {
+ if (ckWARN2(WARN_CLOSED,WARN_IO)) {
if (IoIFP(io))
- warn("Filehandle only opened for input");
- else
- warn("Write on closed filehandle");
+ warner(WARN_IO, "Filehandle only opened for input");
+ else if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "Write on closed filehandle");
}
- PUSHs(&sv_no);
+ PUSHs(&PL_sv_no);
}
else {
- if ((IoLINES_LEFT(io) -= FmLINES(formtarget)) < 0) {
- if (dowarn)
- warn("page overflow");
+ if ((IoLINES_LEFT(io) -= FmLINES(PL_formtarget)) < 0) {
+ if (ckWARN(WARN_IO))
+ warner(WARN_IO, "page overflow");
}
- if (!PerlIO_write(ofp, SvPVX(formtarget), SvCUR(formtarget)) ||
+ if (!PerlIO_write(ofp, SvPVX(PL_formtarget), SvCUR(PL_formtarget)) ||
PerlIO_error(fp))
- PUSHs(&sv_no);
+ PUSHs(&PL_sv_no);
else {
- FmLINES(formtarget) = 0;
- SvCUR_set(formtarget, 0);
- *SvEND(formtarget) = '\0';
+ FmLINES(PL_formtarget) = 0;
+ SvCUR_set(PL_formtarget, 0);
+ *SvEND(PL_formtarget) = '\0';
if (IoFLAGS(io) & IOf_FLUSH)
(void)PerlIO_flush(fp);
- PUSHs(&sv_yes);
+ PUSHs(&PL_sv_yes);
}
}
- formtarget = bodytarget;
+ PL_formtarget = PL_bodytarget;
PUTBACK;
return pop_return();
}
PP(pp_prtf)
{
- dSP; dMARK; dORIGMARK;
+ djSP; dMARK; dORIGMARK;
GV *gv;
IO *io;
PerlIO *fp;
SV *sv;
MAGIC *mg;
+ STRLEN n_a;
- if (op->op_flags & OPf_STACKED)
+ if (PL_op->op_flags & OPf_STACKED)
gv = (GV*)*++MARK;
else
- gv = defoutgv;
+ gv = PL_defoutgv;
- if (SvMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
+ if (mg = SvTIED_mg((SV*)gv, 'q')) {
if (MARK == ORIGMARK) {
- EXTEND(SP, 1);
+ MEXTEND(SP, 1);
++MARK;
Move(MARK, MARK + 1, (SP - MARK) + 1, SV*);
++SP;
}
PUSHMARK(MARK - 1);
- *MARK = mg->mg_obj;
+ *MARK = SvTIED_obj((SV*)gv, mg);
PUTBACK;
ENTER;
perl_call_method("PRINTF", G_SCALAR);
sv = NEWSV(0,0);
if (!(io = GvIO(gv))) {
- if (dowarn) {
+ if (ckWARN(WARN_UNOPENED)) {
gv_fullname3(sv, gv, Nullch);
- warn("Filehandle %s never opened", SvPV(sv,na));
+ warner(WARN_UNOPENED, "Filehandle %s never opened", SvPV(sv,n_a));
}
SETERRNO(EBADF,RMS$_IFI);
goto just_say_no;
}
else if (!(fp = IoOFP(io))) {
- if (dowarn) {
+ if (ckWARN2(WARN_CLOSED,WARN_IO)) {
gv_fullname3(sv, gv, Nullch);
if (IoIFP(io))
- warn("Filehandle %s opened only for input", SvPV(sv,na));
- else
- warn("printf on closed filehandle %s", SvPV(sv,na));
+ warner(WARN_IO, "Filehandle %s opened only for input",
+ SvPV(sv,n_a));
+ else if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "printf on closed filehandle %s",
+ SvPV(sv,n_a));
}
SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI);
goto just_say_no;
}
else {
#ifdef USE_LOCALE_NUMERIC
- if (op->op_private & OPpLOCALE)
+ if (PL_op->op_private & OPpLOCALE)
SET_NUMERIC_LOCAL();
else
SET_NUMERIC_STANDARD();
}
SvREFCNT_dec(sv);
SP = ORIGMARK;
- PUSHs(&sv_yes);
+ PUSHs(&PL_sv_yes);
RETURN;
just_say_no:
SvREFCNT_dec(sv);
SP = ORIGMARK;
- PUSHs(&sv_undef);
+ PUSHs(&PL_sv_undef);
RETURN;
}
PP(pp_sysopen)
{
- dSP;
+ djSP;
GV *gv;
SV *sv;
char *tmps;
sv = POPs;
gv = (GV *)POPs;
+ /* Need TIEHANDLE method ? */
+
tmps = SvPV(sv, len);
if (do_open(gv, tmps, len, TRUE, mode, perm, Nullfp)) {
IoLINES(GvIOp(gv)) = 0;
- PUSHs(&sv_yes);
+ PUSHs(&PL_sv_yes);
}
else {
- PUSHs(&sv_undef);
+ PUSHs(&PL_sv_undef);
}
RETURN;
}
PP(pp_sysread)
{
- dSP; dMARK; dORIGMARK; dTARGET;
+ djSP; dMARK; dORIGMARK; dTARGET;
int offset;
GV *gv;
IO *io;
MAGIC *mg;
gv = (GV*)*++MARK;
- if ((op->op_type == OP_READ || op->op_type == OP_SYSREAD) &&
- SvMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q')))
+ if ((PL_op->op_type == OP_READ || PL_op->op_type == OP_SYSREAD) &&
+ (mg = SvTIED_mg((SV*)gv, 'q')))
{
SV *sv;
PUSHMARK(MARK-1);
- *MARK = mg->mg_obj;
+ *MARK = SvTIED_obj((SV*)gv, mg);
ENTER;
perl_call_method("READ", G_SCALAR);
LEAVE;
if (!io || !IoIFP(io))
goto say_undef;
#ifdef HAS_SOCKET
- if (op->op_type == OP_RECV) {
+ if (PL_op->op_type == OP_RECV) {
char namebuf[MAXPATHLEN];
+#if (defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)) || defined(MPE)
+ bufsize = sizeof (struct sockaddr_in);
+#else
bufsize = sizeof namebuf;
+#endif
buffer = SvGROW(bufsv, length+1);
/* 'offset' means 'flags' here */
- length = recvfrom(PerlIO_fileno(IoIFP(io)), buffer, length, offset,
+ length = PerlSock_recvfrom(PerlIO_fileno(IoIFP(io)), buffer, length, offset,
(struct sockaddr *)namebuf, &bufsize);
if (length < 0)
RETPUSHUNDEF;
RETURN;
}
#else
- if (op->op_type == OP_RECV)
- DIE(no_sock_func, "recv");
+ if (PL_op->op_type == OP_RECV)
+ DIE(PL_no_sock_func, "recv");
#endif
if (offset < 0) {
if (-offset > blen)
if (offset > bufsize) { /* Zero any newly allocated space */
Zero(buffer+bufsize, offset-bufsize, char);
}
- if (op->op_type == OP_SYSREAD) {
- length = read(PerlIO_fileno(IoIFP(io)), buffer+offset, length);
+ if (PL_op->op_type == OP_SYSREAD) {
+#ifdef PERL_SOCK_SYSREAD_IS_RECV
+ if (IoTYPE(io) == 's') {
+ length = PerlSock_recv(PerlIO_fileno(IoIFP(io)),
+ buffer+offset, length, 0);
+ }
+ else
+#endif
+ {
+ length = PerlLIO_read(PerlIO_fileno(IoIFP(io)),
+ buffer+offset, length);
+ }
}
else
#ifdef HAS_SOCKET__bad_code_maybe
if (IoTYPE(io) == 's') {
char namebuf[MAXPATHLEN];
+#if defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)
+ bufsize = sizeof (struct sockaddr_in);
+#else
bufsize = sizeof namebuf;
- length = recvfrom(PerlIO_fileno(IoIFP(io)), buffer+offset, length, 0,
+#endif
+ length = PerlSock_recvfrom(PerlIO_fileno(IoIFP(io)), buffer+offset, length, 0,
(struct sockaddr *)namebuf, &bufsize);
}
else
#endif
+ {
length = PerlIO_read(IoIFP(io), buffer+offset, length);
+ /* fread() returns 0 on both error and EOF */
+ if (length == 0 && PerlIO_error(IoIFP(io)))
+ length = -1;
+ }
if (length < 0)
goto say_undef;
SvCUR_set(bufsv, length+offset);
PP(pp_syswrite)
{
+ djSP;
+ int items = (SP - PL_stack_base) - TOPMARK;
+ if (items == 2) {
+ SV *sv;
+ EXTEND(SP, 1);
+ sv = sv_2mortal(newSViv(sv_len(*SP)));
+ PUSHs(sv);
+ PUTBACK;
+ }
return pp_send(ARGS);
}
PP(pp_send)
{
- dSP; dMARK; dORIGMARK; dTARGET;
+ djSP; dMARK; dORIGMARK; dTARGET;
GV *gv;
IO *io;
int offset;
char *buffer;
int length;
STRLEN blen;
+ MAGIC *mg;
gv = (GV*)*++MARK;
+ if (PL_op->op_type == OP_SYSWRITE && (mg = SvTIED_mg((SV*)gv, 'q'))) {
+ SV *sv;
+
+ PUSHMARK(MARK-1);
+ *MARK = SvTIED_obj((SV*)gv, mg);
+ ENTER;
+ perl_call_method("WRITE", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ sv = POPs;
+ SP = ORIGMARK;
+ PUSHs(sv);
+ RETURN;
+ }
if (!gv)
goto say_undef;
bufsv = *++MARK;
io = GvIO(gv);
if (!io || !IoIFP(io)) {
length = -1;
- if (dowarn) {
- if (op->op_type == OP_SYSWRITE)
- warn("Syswrite on closed filehandle");
+ if (ckWARN(WARN_CLOSED)) {
+ if (PL_op->op_type == OP_SYSWRITE)
+ warner(WARN_CLOSED, "Syswrite on closed filehandle");
else
- warn("Send on closed socket");
+ warner(WARN_CLOSED, "Send on closed socket");
}
}
- else if (op->op_type == OP_SYSWRITE) {
+ else if (PL_op->op_type == OP_SYSWRITE) {
if (MARK < SP) {
offset = SvIVx(*++MARK);
if (offset < 0) {
if (-offset > blen)
DIE("Offset outside string");
offset += blen;
- } else if (offset >= blen)
+ } else if (offset >= blen && blen > 0)
DIE("Offset outside string");
} else
offset = 0;
if (length > blen - offset)
length = blen - offset;
- length = write(PerlIO_fileno(IoIFP(io)), buffer+offset, length);
+#ifdef PERL_SOCK_SYSWRITE_IS_SEND
+ if (IoTYPE(io) == 's') {
+ length = PerlSock_send(PerlIO_fileno(IoIFP(io)),
+ buffer+offset, length, 0);
+ }
+ else
+#endif
+ {
+ length = PerlLIO_write(PerlIO_fileno(IoIFP(io)),
+ buffer+offset, length);
+ }
}
#ifdef HAS_SOCKET
else if (SP > MARK) {
char *sockbuf;
STRLEN mlen;
sockbuf = SvPVx(*++MARK, mlen);
- length = sendto(PerlIO_fileno(IoIFP(io)), buffer, blen, length,
+ length = PerlSock_sendto(PerlIO_fileno(IoIFP(io)), buffer, blen, length,
(struct sockaddr *)sockbuf, mlen);
}
else
- length = send(PerlIO_fileno(IoIFP(io)), buffer, blen, length);
+ length = PerlSock_send(PerlIO_fileno(IoIFP(io)), buffer, blen, length);
+
#else
else
- DIE(no_sock_func, "send");
+ DIE(PL_no_sock_func, "send");
#endif
if (length < 0)
goto say_undef;
PP(pp_eof)
{
- dSP;
+ djSP;
GV *gv;
+ MAGIC *mg;
if (MAXARG <= 0)
- gv = last_in_gv;
+ gv = PL_last_in_gv;
else
- gv = last_in_gv = (GV*)POPs;
+ gv = PL_last_in_gv = (GV*)POPs;
+
+ if (gv && (mg = SvTIED_mg((SV*)gv, 'q'))) {
+ PUSHMARK(SP);
+ XPUSHs(SvTIED_obj((SV*)gv, mg));
+ PUTBACK;
+ ENTER;
+ perl_call_method("EOF", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
+ }
+
PUSHs(boolSV(!gv || do_eof(gv)));
RETURN;
}
PP(pp_tell)
{
- dSP; dTARGET;
- GV *gv;
+ djSP; dTARGET;
+ GV *gv;
+ MAGIC *mg;
if (MAXARG <= 0)
- gv = last_in_gv;
+ gv = PL_last_in_gv;
else
- gv = last_in_gv = (GV*)POPs;
+ gv = PL_last_in_gv = (GV*)POPs;
+
+ if (gv && (mg = SvTIED_mg((SV*)gv, 'q'))) {
+ PUSHMARK(SP);
+ XPUSHs(SvTIED_obj((SV*)gv, mg));
+ PUTBACK;
+ ENTER;
+ perl_call_method("TELL", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
+ }
+
PUSHi( do_tell(gv) );
RETURN;
}
PP(pp_sysseek)
{
- dSP;
+ djSP;
GV *gv;
int whence = POPi;
- long offset = POPl;
+ Off_t offset = POPl;
+ MAGIC *mg;
+
+ gv = PL_last_in_gv = (GV*)POPs;
+
+ if (gv && (mg = SvTIED_mg((SV*)gv, 'q'))) {
+ PUSHMARK(SP);
+ XPUSHs(SvTIED_obj((SV*)gv, mg));
+ XPUSHs(sv_2mortal(newSViv((IV) offset)));
+ XPUSHs(sv_2mortal(newSViv((IV) whence)));
+ PUTBACK;
+ ENTER;
+ perl_call_method("SEEK", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
+ }
- gv = last_in_gv = (GV*)POPs;
- if (op->op_type == OP_SEEK)
+ if (PL_op->op_type == OP_SEEK)
PUSHs(boolSV(do_seek(gv, offset, whence)));
else {
- long n = do_sysseek(gv, offset, whence);
- PUSHs((n < 0) ? &sv_undef
+ Off_t n = do_sysseek(gv, offset, whence);
+ PUSHs((n < 0) ? &PL_sv_undef
: sv_2mortal(n ? newSViv((IV)n)
- : newSVpv(zero_but_true, ZBTLEN)));
+ : newSVpvn(zero_but_true, ZBTLEN)));
}
RETURN;
}
PP(pp_truncate)
{
- dSP;
+ djSP;
Off_t len = (Off_t)POPn;
int result = 1;
GV *tmpgv;
+ STRLEN n_a;
SETERRNO(0,0);
#if defined(HAS_TRUNCATE) || defined(HAS_CHSIZE) || defined(F_FREESP)
- if (op->op_flags & OPf_SPECIAL) {
- tmpgv = gv_fetchpv(POPp, FALSE, SVt_PVIO);
+ if (PL_op->op_flags & OPf_SPECIAL) {
+ tmpgv = gv_fetchpv(POPpx, FALSE, SVt_PVIO);
do_ftruncate:
TAINT_PROPER("truncate");
if (!GvIO(tmpgv) || !IoIFP(GvIOp(tmpgv)) ||
else {
SV *sv = POPs;
char *name;
+ STRLEN n_a;
if (SvTYPE(sv) == SVt_PVGV) {
tmpgv = (GV*)sv; /* *main::FRED for example */
goto do_ftruncate;
}
- name = SvPV(sv, na);
+ name = SvPV(sv, n_a);
TAINT_PROPER("truncate");
#ifdef HAS_TRUNCATE
if (truncate(name, len) < 0)
#else
{
int tmpfd;
- if ((tmpfd = open(name, O_RDWR)) < 0)
+ if ((tmpfd = PerlLIO_open(name, O_RDWR)) < 0)
result = 0;
else {
if (my_chsize(tmpfd, len) < 0)
result = 0;
- close(tmpfd);
+ PerlLIO_close(tmpfd);
}
}
#endif
PP(pp_ioctl)
{
- dSP; dTARGET;
+ djSP; dTARGET;
SV *argsv = POPs;
unsigned int func = U_I(POPn);
- int optype = op->op_type;
+ int optype = PL_op->op_type;
char *s;
IV retval;
GV *gv = (GV*)POPs;
if (optype == OP_IOCTL)
#ifdef HAS_IOCTL
- retval = ioctl(PerlIO_fileno(IoIFP(io)), func, s);
+ retval = PerlLIO_ioctl(PerlIO_fileno(IoIFP(io)), func, s);
#else
DIE("ioctl is not implemented");
#endif
if (SvPOK(argsv)) {
if (s[SvCUR(argsv)] != 17)
DIE("Possible memory corruption: %s overflowed 3rd argument",
- op_name[optype]);
+ PL_op_name[optype]);
s[SvCUR(argsv)] = 0; /* put our null back */
SvSETMAGIC(argsv); /* Assume it has changed */
}
PP(pp_flock)
{
- dSP; dTARGET;
+ djSP; dTARGET;
I32 value;
int argtype;
GV *gv;
#ifdef FLOCK
argtype = POPi;
if (MAXARG <= 0)
- gv = last_in_gv;
+ gv = PL_last_in_gv;
else
gv = (GV*)POPs;
if (gv && GvIO(gv))
fp = Nullfp;
if (fp) {
(void)PerlIO_flush(fp);
- value = (I32)(FLOCK(PerlIO_fileno(fp), argtype) >= 0);
+ value = (I32)(PerlLIO_flock(PerlIO_fileno(fp), argtype) >= 0);
}
else
value = 0;
PUSHi(value);
RETURN;
#else
- DIE(no_func, "flock()");
+ DIE(PL_no_func, "flock()");
#endif
}
PP(pp_socket)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
GV *gv;
register IO *io;
do_close(gv, FALSE);
TAINT_PROPER("socket");
- fd = socket(domain, type, protocol);
+ fd = PerlSock_socket(domain, type, protocol);
if (fd < 0)
RETPUSHUNDEF;
IoIFP(io) = PerlIO_fdopen(fd, "r"); /* stdio gets confused about sockets */
if (!IoIFP(io) || !IoOFP(io)) {
if (IoIFP(io)) PerlIO_close(IoIFP(io));
if (IoOFP(io)) PerlIO_close(IoOFP(io));
- if (!IoIFP(io) && !IoOFP(io)) close(fd);
+ if (!IoIFP(io) && !IoOFP(io)) PerlLIO_close(fd);
RETPUSHUNDEF;
}
RETPUSHYES;
#else
- DIE(no_sock_func, "socket");
+ DIE(PL_no_sock_func, "socket");
#endif
}
PP(pp_sockpair)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKETPAIR
GV *gv1;
GV *gv2;
do_close(gv2, FALSE);
TAINT_PROPER("socketpair");
- if (socketpair(domain, type, protocol, fd) < 0)
+ if (PerlSock_socketpair(domain, type, protocol, fd) < 0)
RETPUSHUNDEF;
IoIFP(io1) = PerlIO_fdopen(fd[0], "r");
IoOFP(io1) = PerlIO_fdopen(fd[0], "w");
if (!IoIFP(io1) || !IoOFP(io1) || !IoIFP(io2) || !IoOFP(io2)) {
if (IoIFP(io1)) PerlIO_close(IoIFP(io1));
if (IoOFP(io1)) PerlIO_close(IoOFP(io1));
- if (!IoIFP(io1) && !IoOFP(io1)) close(fd[0]);
+ if (!IoIFP(io1) && !IoOFP(io1)) PerlLIO_close(fd[0]);
if (IoIFP(io2)) PerlIO_close(IoIFP(io2));
if (IoOFP(io2)) PerlIO_close(IoOFP(io2));
- if (!IoIFP(io2) && !IoOFP(io2)) close(fd[1]);
+ if (!IoIFP(io2) && !IoOFP(io2)) PerlLIO_close(fd[1]);
RETPUSHUNDEF;
}
RETPUSHYES;
#else
- DIE(no_sock_func, "socketpair");
+ DIE(PL_no_sock_func, "socketpair");
#endif
}
PP(pp_bind)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
+#ifdef MPE /* Requires PRIV mode to bind() to ports < 1024 */
+ extern GETPRIVMODE();
+ extern GETUSERMODE();
+#endif
SV *addrsv = POPs;
char *addr;
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
STRLEN len;
+ int bind_ok = 0;
+#ifdef MPE
+ int mpeprivmode = 0;
+#endif
if (!io || !IoIFP(io))
goto nuts;
addr = SvPV(addrsv, len);
TAINT_PROPER("bind");
- if (bind(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
+#ifdef MPE /* Deal with MPE bind() peculiarities */
+ if (((struct sockaddr *)addr)->sa_family == AF_INET) {
+ /* The address *MUST* stupidly be zero. */
+ ((struct sockaddr_in *)addr)->sin_addr.s_addr = INADDR_ANY;
+ /* PRIV mode is required to bind() to ports < 1024. */
+ if (((struct sockaddr_in *)addr)->sin_port < 1024 &&
+ ((struct sockaddr_in *)addr)->sin_port > 0) {
+ GETPRIVMODE(); /* If this fails, we are aborted by MPE/iX. */
+ mpeprivmode = 1;
+ }
+ }
+#endif /* MPE */
+ if (PerlSock_bind(PerlIO_fileno(IoIFP(io)),
+ (struct sockaddr *)addr, len) >= 0)
+ bind_ok = 1;
+
+#ifdef MPE /* Switch back to USER mode */
+ if (mpeprivmode)
+ GETUSERMODE();
+#endif /* MPE */
+
+ if (bind_ok)
RETPUSHYES;
else
RETPUSHUNDEF;
nuts:
- if (dowarn)
- warn("bind() on closed fd");
+ if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "bind() on closed fd");
SETERRNO(EBADF,SS$_IVCHAN);
RETPUSHUNDEF;
#else
- DIE(no_sock_func, "bind");
+ DIE(PL_no_sock_func, "bind");
#endif
}
PP(pp_connect)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
SV *addrsv = POPs;
char *addr;
addr = SvPV(addrsv, len);
TAINT_PROPER("connect");
- if (connect(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
+ if (PerlSock_connect(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
RETPUSHYES;
else
RETPUSHUNDEF;
nuts:
- if (dowarn)
- warn("connect() on closed fd");
+ if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "connect() on closed fd");
SETERRNO(EBADF,SS$_IVCHAN);
RETPUSHUNDEF;
#else
- DIE(no_sock_func, "connect");
+ DIE(PL_no_sock_func, "connect");
#endif
}
PP(pp_listen)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
int backlog = POPi;
GV *gv = (GV*)POPs;
if (!io || !IoIFP(io))
goto nuts;
- if (listen(PerlIO_fileno(IoIFP(io)), backlog) >= 0)
+ if (PerlSock_listen(PerlIO_fileno(IoIFP(io)), backlog) >= 0)
RETPUSHYES;
else
RETPUSHUNDEF;
nuts:
- if (dowarn)
- warn("listen() on closed fd");
+ if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "listen() on closed fd");
SETERRNO(EBADF,SS$_IVCHAN);
RETPUSHUNDEF;
#else
- DIE(no_sock_func, "listen");
+ DIE(PL_no_sock_func, "listen");
#endif
}
PP(pp_accept)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_SOCKET
GV *ngv;
GV *ggv;
if (IoIFP(nstio))
do_close(ngv, FALSE);
- fd = accept(PerlIO_fileno(IoIFP(gstio)), (struct sockaddr *)&saddr, &len);
+ fd = PerlSock_accept(PerlIO_fileno(IoIFP(gstio)), (struct sockaddr *)&saddr, &len);
if (fd < 0)
goto badexit;
IoIFP(nstio) = PerlIO_fdopen(fd, "r");
if (!IoIFP(nstio) || !IoOFP(nstio)) {
if (IoIFP(nstio)) PerlIO_close(IoIFP(nstio));
if (IoOFP(nstio)) PerlIO_close(IoOFP(nstio));
- if (!IoIFP(nstio) && !IoOFP(nstio)) close(fd);
+ if (!IoIFP(nstio) && !IoOFP(nstio)) PerlLIO_close(fd);
goto badexit;
}
RETURN;
nuts:
- if (dowarn)
- warn("accept() on closed fd");
+ if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "accept() on closed fd");
SETERRNO(EBADF,SS$_IVCHAN);
badexit:
RETPUSHUNDEF;
#else
- DIE(no_sock_func, "accept");
+ DIE(PL_no_sock_func, "accept");
#endif
}
PP(pp_shutdown)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_SOCKET
int how = POPi;
GV *gv = (GV*)POPs;
if (!io || !IoIFP(io))
goto nuts;
- PUSHi( shutdown(PerlIO_fileno(IoIFP(io)), how) >= 0 );
+ PUSHi( PerlSock_shutdown(PerlIO_fileno(IoIFP(io)), how) >= 0 );
RETURN;
nuts:
- if (dowarn)
- warn("shutdown() on closed fd");
+ if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "shutdown() on closed fd");
SETERRNO(EBADF,SS$_IVCHAN);
RETPUSHUNDEF;
#else
- DIE(no_sock_func, "shutdown");
+ DIE(PL_no_sock_func, "shutdown");
#endif
}
#ifdef HAS_SOCKET
return pp_ssockopt(ARGS);
#else
- DIE(no_sock_func, "getsockopt");
+ DIE(PL_no_sock_func, "getsockopt");
#endif
}
PP(pp_ssockopt)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
- int optype = op->op_type;
+ int optype = PL_op->op_type;
SV *sv;
int fd;
unsigned int optname;
SvCUR_set(sv,256);
*SvEND(sv) ='\0';
len = SvCUR(sv);
- if (getsockopt(fd, lvl, optname, SvPVX(sv), &len) < 0)
+ if (PerlSock_getsockopt(fd, lvl, optname, SvPVX(sv), &len) < 0)
goto nuts2;
SvCUR_set(sv, len);
*SvEND(sv) ='\0';
char *buf;
int aint;
if (SvPOKp(sv)) {
- buf = SvPV(sv, na);
- len = na;
+ STRLEN l;
+ buf = SvPV(sv, l);
+ len = l;
}
- else if (SvOK(sv)) {
+ else {
aint = (int)SvIV(sv);
buf = (char*)&aint;
len = sizeof(int);
}
- if (setsockopt(fd, lvl, optname, buf, len) < 0)
+ if (PerlSock_setsockopt(fd, lvl, optname, buf, len) < 0)
goto nuts2;
- PUSHs(&sv_yes);
+ PUSHs(&PL_sv_yes);
}
break;
}
RETURN;
nuts:
- if (dowarn)
- warn("[gs]etsockopt() on closed fd");
+ if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "[gs]etsockopt() on closed fd");
SETERRNO(EBADF,SS$_IVCHAN);
nuts2:
RETPUSHUNDEF;
#else
- DIE(no_sock_func, "setsockopt");
+ DIE(PL_no_sock_func, "setsockopt");
#endif
}
#ifdef HAS_SOCKET
return pp_getpeername(ARGS);
#else
- DIE(no_sock_func, "getsockname");
+ DIE(PL_no_sock_func, "getsockname");
#endif
}
PP(pp_getpeername)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
- int optype = op->op_type;
+ int optype = PL_op->op_type;
SV *sv;
int fd;
GV *gv = (GV*)POPs;
fd = PerlIO_fileno(IoIFP(io));
switch (optype) {
case OP_GETSOCKNAME:
- if (getsockname(fd, (struct sockaddr *)SvPVX(sv), &len) < 0)
+ if (PerlSock_getsockname(fd, (struct sockaddr *)SvPVX(sv), &len) < 0)
goto nuts2;
break;
case OP_GETPEERNAME:
- if (getpeername(fd, (struct sockaddr *)SvPVX(sv), &len) < 0)
+ if (PerlSock_getpeername(fd, (struct sockaddr *)SvPVX(sv), &len) < 0)
goto nuts2;
+#if defined(VMS_DO_SOCKETS) && defined (DECCRTL_SOCKETS)
+ {
+ static const char nowhere[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+ /* If the call succeeded, make sure we don't have a zeroed port/addr */
+ if (((struct sockaddr *)SvPVX(sv))->sa_family == AF_INET &&
+ !memcmp((char *)SvPVX(sv) + sizeof(u_short), nowhere,
+ sizeof(u_short) + sizeof(struct in_addr))) {
+ goto nuts2;
+ }
+ }
+#endif
break;
}
#ifdef BOGUS_GETNAME_RETURN
RETURN;
nuts:
- if (dowarn)
- warn("get{sock, peer}name() on closed fd");
+ if (ckWARN(WARN_CLOSED))
+ warner(WARN_CLOSED, "get{sock, peer}name() on closed fd");
SETERRNO(EBADF,SS$_IVCHAN);
nuts2:
RETPUSHUNDEF;
#else
- DIE(no_sock_func, "getpeername");
+ DIE(PL_no_sock_func, "getpeername");
#endif
}
PP(pp_stat)
{
- dSP;
+ djSP;
GV *tmpgv;
I32 gimme;
I32 max = 13;
+ STRLEN n_a;
- if (op->op_flags & OPf_REF) {
+ if (PL_op->op_flags & OPf_REF) {
tmpgv = cGVOP->op_gv;
do_fstat:
- if (tmpgv != defgv) {
- laststype = OP_STAT;
- statgv = tmpgv;
- sv_setpv(statname, "");
- laststatval = (GvIO(tmpgv) && IoIFP(GvIOp(tmpgv))
- ? Fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &statcache) : -1);
+ if (tmpgv != PL_defgv) {
+ PL_laststype = OP_STAT;
+ PL_statgv = tmpgv;
+ sv_setpv(PL_statname, "");
+ PL_laststatval = (GvIO(tmpgv) && IoIFP(GvIOp(tmpgv))
+ ? PerlLIO_fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &PL_statcache) : -1);
}
- if (laststatval < 0)
+ if (PL_laststatval < 0)
max = 0;
}
else {
tmpgv = (GV*)SvRV(sv);
goto do_fstat;
}
- sv_setpv(statname, SvPV(sv,na));
- statgv = Nullgv;
+ sv_setpv(PL_statname, SvPV(sv,n_a));
+ PL_statgv = Nullgv;
#ifdef HAS_LSTAT
- laststype = op->op_type;
- if (op->op_type == OP_LSTAT)
- laststatval = lstat(SvPV(statname, na), &statcache);
+ PL_laststype = PL_op->op_type;
+ if (PL_op->op_type == OP_LSTAT)
+ PL_laststatval = PerlLIO_lstat(SvPV(PL_statname, n_a), &PL_statcache);
else
#endif
- laststatval = Stat(SvPV(statname, na), &statcache);
- if (laststatval < 0) {
- if (dowarn && strchr(SvPV(statname, na), '\n'))
- warn(warn_nl, "stat");
+ PL_laststatval = PerlLIO_stat(SvPV(PL_statname, n_a), &PL_statcache);
+ if (PL_laststatval < 0) {
+ if (ckWARN(WARN_NEWLINE) && strchr(SvPV(PL_statname, n_a), '\n'))
+ warner(WARN_NEWLINE, PL_warn_nl, "stat");
max = 0;
}
}
if (max) {
EXTEND(SP, max);
EXTEND_MORTAL(max);
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_dev)));
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_ino)));
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_mode)));
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_nlink)));
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_uid)));
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_gid)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_dev)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_ino)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_mode)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_nlink)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_uid)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_gid)));
#ifdef USE_STAT_RDEV
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_rdev)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_rdev)));
#else
- PUSHs(sv_2mortal(newSVpv("", 0)));
+ PUSHs(sv_2mortal(newSVpvn("", 0)));
#endif
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_size)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_size)));
#ifdef BIG_TIME
- PUSHs(sv_2mortal(newSVnv((U32)statcache.st_atime)));
- PUSHs(sv_2mortal(newSVnv((U32)statcache.st_mtime)));
- PUSHs(sv_2mortal(newSVnv((U32)statcache.st_ctime)));
+ PUSHs(sv_2mortal(newSVnv((U32)PL_statcache.st_atime)));
+ PUSHs(sv_2mortal(newSVnv((U32)PL_statcache.st_mtime)));
+ PUSHs(sv_2mortal(newSVnv((U32)PL_statcache.st_ctime)));
#else
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_atime)));
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_mtime)));
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_ctime)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_atime)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_mtime)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_ctime)));
#endif
#ifdef USE_STAT_BLOCKS
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_blksize)));
- PUSHs(sv_2mortal(newSViv((I32)statcache.st_blocks)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_blksize)));
+ PUSHs(sv_2mortal(newSViv((I32)PL_statcache.st_blocks)));
#else
- PUSHs(sv_2mortal(newSVpv("", 0)));
- PUSHs(sv_2mortal(newSVpv("", 0)));
+ PUSHs(sv_2mortal(newSVpvn("", 0)));
+ PUSHs(sv_2mortal(newSVpvn("", 0)));
#endif
}
RETURN;
PP(pp_ftrread)
{
- I32 result = my_stat(ARGS);
- dSP;
+ I32 result;
+ djSP;
+#if defined(HAS_ACCESS) && defined(R_OK)
+ STRLEN n_a;
+ if ((PL_hints & HINT_FILETEST_ACCESS) && SvPOK(TOPs)) {
+ result = access(TOPpx, R_OK);
+ if (result == 0)
+ RETPUSHYES;
+ if (result < 0)
+ RETPUSHUNDEF;
+ RETPUSHNO;
+ }
+ else
+ result = my_stat(ARGS);
+#else
+ result = my_stat(ARGS);
+#endif
+ SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (cando(S_IRUSR, 0, &statcache))
+ if (cando(S_IRUSR, 0, &PL_statcache))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftrwrite)
{
- I32 result = my_stat(ARGS);
- dSP;
+ I32 result;
+ djSP;
+#if defined(HAS_ACCESS) && defined(W_OK)
+ STRLEN n_a;
+ if ((PL_hints & HINT_FILETEST_ACCESS) && SvPOK(TOPs)) {
+ result = access(TOPpx, W_OK);
+ if (result == 0)
+ RETPUSHYES;
+ if (result < 0)
+ RETPUSHUNDEF;
+ RETPUSHNO;
+ }
+ else
+ result = my_stat(ARGS);
+#else
+ result = my_stat(ARGS);
+#endif
+ SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (cando(S_IWUSR, 0, &statcache))
+ if (cando(S_IWUSR, 0, &PL_statcache))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftrexec)
{
- I32 result = my_stat(ARGS);
- dSP;
+ I32 result;
+ djSP;
+#if defined(HAS_ACCESS) && defined(X_OK)
+ STRLEN n_a;
+ if ((PL_hints & HINT_FILETEST_ACCESS) && SvPOK(TOPs)) {
+ result = access(TOPpx, X_OK);
+ if (result == 0)
+ RETPUSHYES;
+ if (result < 0)
+ RETPUSHUNDEF;
+ RETPUSHNO;
+ }
+ else
+ result = my_stat(ARGS);
+#else
+ result = my_stat(ARGS);
+#endif
+ SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (cando(S_IXUSR, 0, &statcache))
+ if (cando(S_IXUSR, 0, &PL_statcache))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_fteread)
{
- I32 result = my_stat(ARGS);
- dSP;
+ I32 result;
+ djSP;
+#ifdef PERL_EFF_ACCESS_R_OK
+ STRLEN n_a;
+ if ((PL_hints & HINT_FILETEST_ACCESS) && SvPOK(TOPs)) {
+ result = PERL_EFF_ACCESS_R_OK(TOPpx);
+ if (result == 0)
+ RETPUSHYES;
+ if (result < 0)
+ RETPUSHUNDEF;
+ RETPUSHNO;
+ }
+ else
+ result = my_stat(ARGS);
+#else
+ result = my_stat(ARGS);
+#endif
+ SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (cando(S_IRUSR, 1, &statcache))
+ if (cando(S_IRUSR, 1, &PL_statcache))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftewrite)
{
- I32 result = my_stat(ARGS);
- dSP;
+ I32 result;
+ djSP;
+#ifdef PERL_EFF_ACCESS_W_OK
+ STRLEN n_a;
+ if ((PL_hints & HINT_FILETEST_ACCESS) && SvPOK(TOPs)) {
+ result = PERL_EFF_ACCESS_W_OK(TOPpx);
+ if (result == 0)
+ RETPUSHYES;
+ if (result < 0)
+ RETPUSHUNDEF;
+ RETPUSHNO;
+ }
+ else
+ result = my_stat(ARGS);
+#else
+ result = my_stat(ARGS);
+#endif
+ SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (cando(S_IWUSR, 1, &statcache))
+ if (cando(S_IWUSR, 1, &PL_statcache))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_fteexec)
{
- I32 result = my_stat(ARGS);
- dSP;
+ I32 result;
+ djSP;
+#ifdef PERL_EFF_ACCESS_X_OK
+ STRLEN n_a;
+ if ((PL_hints & HINT_FILETEST_ACCESS) && SvPOK(TOPs)) {
+ result = PERL_EFF_ACCESS_X_OK(TOPpx);
+ if (result == 0)
+ RETPUSHYES;
+ if (result < 0)
+ RETPUSHUNDEF;
+ RETPUSHNO;
+ }
+ else
+ result = my_stat(ARGS);
+#else
+ result = my_stat(ARGS);
+#endif
+ SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (cando(S_IXUSR, 1, &statcache))
+ if (cando(S_IXUSR, 1, &PL_statcache))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftis)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
RETPUSHYES;
PP(pp_ftrowned)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (statcache.st_uid == (op->op_type == OP_FTEOWNED ? euid : uid) )
+ if (PL_statcache.st_uid == (PL_op->op_type == OP_FTEOWNED ? PL_euid : PL_uid) )
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftzero)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (!statcache.st_size)
+ if (!PL_statcache.st_size)
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftsize)
{
I32 result = my_stat(ARGS);
- dSP; dTARGET;
+ djSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHi(statcache.st_size);
+ PUSHi(PL_statcache.st_size);
RETURN;
}
PP(pp_ftmtime)
{
I32 result = my_stat(ARGS);
- dSP; dTARGET;
+ djSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( ((I32)basetime - (I32)statcache.st_mtime) / 86400.0 );
+ PUSHn( ((I32)PL_basetime - (I32)PL_statcache.st_mtime) / 86400.0 );
RETURN;
}
PP(pp_ftatime)
{
I32 result = my_stat(ARGS);
- dSP; dTARGET;
+ djSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( ((I32)basetime - (I32)statcache.st_atime) / 86400.0 );
+ PUSHn( ((I32)PL_basetime - (I32)PL_statcache.st_atime) / 86400.0 );
RETURN;
}
PP(pp_ftctime)
{
I32 result = my_stat(ARGS);
- dSP; dTARGET;
+ djSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( ((I32)basetime - (I32)statcache.st_ctime) / 86400.0 );
+ PUSHn( ((I32)PL_basetime - (I32)PL_statcache.st_ctime) / 86400.0 );
RETURN;
}
PP(pp_ftsock)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (S_ISSOCK(statcache.st_mode))
+ if (S_ISSOCK(PL_statcache.st_mode))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftchr)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (S_ISCHR(statcache.st_mode))
+ if (S_ISCHR(PL_statcache.st_mode))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftblk)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (S_ISBLK(statcache.st_mode))
+ if (S_ISBLK(PL_statcache.st_mode))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftfile)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (S_ISREG(statcache.st_mode))
+ if (S_ISREG(PL_statcache.st_mode))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftdir)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (S_ISDIR(statcache.st_mode))
+ if (S_ISDIR(PL_statcache.st_mode))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftpipe)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (S_ISFIFO(statcache.st_mode))
+ if (S_ISFIFO(PL_statcache.st_mode))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftlink)
{
I32 result = my_lstat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
- if (S_ISLNK(statcache.st_mode))
+ if (S_ISLNK(PL_statcache.st_mode))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_ftsuid)
{
- dSP;
+ djSP;
#ifdef S_ISUID
I32 result = my_stat(ARGS);
SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (statcache.st_mode & S_ISUID)
+ if (PL_statcache.st_mode & S_ISUID)
RETPUSHYES;
#endif
RETPUSHNO;
PP(pp_ftsgid)
{
- dSP;
+ djSP;
#ifdef S_ISGID
I32 result = my_stat(ARGS);
SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (statcache.st_mode & S_ISGID)
+ if (PL_statcache.st_mode & S_ISGID)
RETPUSHYES;
#endif
RETPUSHNO;
PP(pp_ftsvtx)
{
- dSP;
+ djSP;
#ifdef S_ISVTX
I32 result = my_stat(ARGS);
SPAGAIN;
if (result < 0)
RETPUSHUNDEF;
- if (statcache.st_mode & S_ISVTX)
+ if (PL_statcache.st_mode & S_ISVTX)
RETPUSHYES;
#endif
RETPUSHNO;
PP(pp_fttty)
{
- dSP;
+ djSP;
int fd;
GV *gv;
- char *tmps;
- if (op->op_flags & OPf_REF) {
+ char *tmps = Nullch;
+ STRLEN n_a;
+
+ if (PL_op->op_flags & OPf_REF)
gv = cGVOP->op_gv;
- tmps = "";
- }
+ else if (isGV(TOPs))
+ gv = (GV*)POPs;
+ else if (SvROK(TOPs) && isGV(SvRV(TOPs)))
+ gv = (GV*)SvRV(POPs);
else
- gv = gv_fetchpv(tmps = POPp, FALSE, SVt_PVIO);
+ gv = gv_fetchpv(tmps = POPpx, FALSE, SVt_PVIO);
+
if (GvIO(gv) && IoIFP(GvIOp(gv)))
fd = PerlIO_fileno(IoIFP(GvIOp(gv)));
- else if (isDIGIT(*tmps))
+ else if (tmps && isDIGIT(*tmps))
fd = atoi(tmps);
else
RETPUSHUNDEF;
- if (isatty(fd))
+ if (PerlLIO_isatty(fd))
RETPUSHYES;
RETPUSHNO;
}
PP(pp_fttext)
{
- dSP;
+ djSP;
I32 i;
I32 len;
I32 odd = 0;
register IO *io;
register SV *sv;
GV *gv;
+ STRLEN n_a;
- if (op->op_flags & OPf_REF)
+ if (PL_op->op_flags & OPf_REF)
gv = cGVOP->op_gv;
else if (isGV(TOPs))
gv = (GV*)POPs;
if (gv) {
EXTEND(SP, 1);
- if (gv == defgv) {
- if (statgv)
- io = GvIO(statgv);
+ if (gv == PL_defgv) {
+ if (PL_statgv)
+ io = GvIO(PL_statgv);
else {
- sv = statname;
+ sv = PL_statname;
goto really_filename;
}
}
else {
- statgv = gv;
- laststatval = -1;
- sv_setpv(statname, "");
- io = GvIO(statgv);
+ PL_statgv = gv;
+ PL_laststatval = -1;
+ sv_setpv(PL_statname, "");
+ io = GvIO(PL_statgv);
}
if (io && IoIFP(io)) {
if (! PerlIO_has_base(IoIFP(io)))
DIE("-T and -B not implemented on filehandles");
- laststatval = Fstat(PerlIO_fileno(IoIFP(io)), &statcache);
- if (laststatval < 0)
+ PL_laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache);
+ if (PL_laststatval < 0)
RETPUSHUNDEF;
- if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */
- if (op->op_type == OP_FTTEXT)
+ if (S_ISDIR(PL_statcache.st_mode)) /* handle NFS glitch */
+ if (PL_op->op_type == OP_FTTEXT)
RETPUSHNO;
else
RETPUSHYES;
len = 512;
}
else {
- if (dowarn)
- warn("Test on unopened file <%s>",
+ if (ckWARN(WARN_UNOPENED))
+ warner(WARN_UNOPENED, "Test on unopened file <%s>",
GvENAME(cGVOP->op_gv));
SETERRNO(EBADF,RMS$_IFI);
RETPUSHUNDEF;
else {
sv = POPs;
really_filename:
- statgv = Nullgv;
- laststatval = -1;
- sv_setpv(statname, SvPV(sv, na));
+ PL_statgv = Nullgv;
+ PL_laststatval = -1;
+ sv_setpv(PL_statname, SvPV(sv, n_a));
#ifdef HAS_OPEN3
- i = open(SvPV(sv, na), O_RDONLY, 0);
+ i = PerlLIO_open3(SvPV(sv, n_a), O_RDONLY, 0);
#else
- i = open(SvPV(sv, na), 0);
+ i = PerlLIO_open(SvPV(sv, n_a), 0);
#endif
if (i < 0) {
- if (dowarn && strchr(SvPV(sv, na), '\n'))
- warn(warn_nl, "open");
+ if (ckWARN(WARN_NEWLINE) && strchr(SvPV(sv, n_a), '\n'))
+ warner(WARN_NEWLINE, PL_warn_nl, "open");
RETPUSHUNDEF;
}
- laststatval = Fstat(i, &statcache);
- if (laststatval < 0)
+ PL_laststatval = PerlLIO_fstat(i, &PL_statcache);
+ if (PL_laststatval < 0)
RETPUSHUNDEF;
- len = read(i, tbuf, 512);
- (void)close(i);
+ len = PerlLIO_read(i, tbuf, 512);
+ (void)PerlLIO_close(i);
if (len <= 0) {
- if (S_ISDIR(statcache.st_mode) && op->op_type == OP_FTTEXT)
+ if (S_ISDIR(PL_statcache.st_mode) && PL_op->op_type == OP_FTTEXT)
RETPUSHNO; /* special case NFS directories */
RETPUSHYES; /* null file is anything */
}
odd += len;
break;
}
+#ifdef EBCDIC
+ else if (!(isPRINT(*s) || isSPACE(*s)))
+ odd++;
+#else
else if (*s & 128)
odd++;
else if (*s < 32 &&
*s != '\n' && *s != '\r' && *s != '\b' &&
*s != '\t' && *s != '\f' && *s != 27)
odd++;
+#endif
}
- if ((odd * 3 > len) == (op->op_type == OP_FTTEXT)) /* allow 1/3 odd */
+ if ((odd * 3 > len) == (PL_op->op_type == OP_FTTEXT)) /* allow 1/3 odd */
RETPUSHNO;
else
RETPUSHYES;
PP(pp_chdir)
{
- dSP; dTARGET;
+ djSP; dTARGET;
char *tmps;
SV **svp;
+ STRLEN n_a;
if (MAXARG < 1)
tmps = Nullch;
else
- tmps = POPp;
+ tmps = POPpx;
if (!tmps || !*tmps) {
- svp = hv_fetch(GvHVn(envgv), "HOME", 4, FALSE);
+ svp = hv_fetch(GvHVn(PL_envgv), "HOME", 4, FALSE);
if (svp)
- tmps = SvPV(*svp, na);
+ tmps = SvPV(*svp, n_a);
}
if (!tmps || !*tmps) {
- svp = hv_fetch(GvHVn(envgv), "LOGDIR", 6, FALSE);
+ svp = hv_fetch(GvHVn(PL_envgv), "LOGDIR", 6, FALSE);
if (svp)
- tmps = SvPV(*svp, na);
+ tmps = SvPV(*svp, n_a);
}
+#ifdef VMS
+ if (!tmps || !*tmps) {
+ svp = hv_fetch(GvHVn(PL_envgv), "SYS$LOGIN", 9, FALSE);
+ if (svp)
+ tmps = SvPV(*svp, n_a);
+ }
+#endif
TAINT_PROPER("chdir");
- PUSHi( chdir(tmps) >= 0 );
+ PUSHi( PerlDir_chdir(tmps) >= 0 );
#ifdef VMS
/* Clear the DEFAULT element of ENV so we'll get the new value
* in the future. */
- hv_delete(GvHVn(envgv),"DEFAULT",7,G_DISCARD);
+ hv_delete(GvHVn(PL_envgv),"DEFAULT",7,G_DISCARD);
#endif
RETURN;
}
PP(pp_chown)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
#ifdef HAS_CHOWN
- value = (I32)apply(op->op_type, MARK, SP);
+ value = (I32)apply(PL_op->op_type, MARK, SP);
SP = MARK;
PUSHi(value);
RETURN;
#else
- DIE(no_func, "Unsupported function chown");
+ DIE(PL_no_func, "Unsupported function chown");
#endif
}
PP(pp_chroot)
{
- dSP; dTARGET;
+ djSP; dTARGET;
char *tmps;
#ifdef HAS_CHROOT
- tmps = POPp;
+ STRLEN n_a;
+ tmps = POPpx;
TAINT_PROPER("chroot");
PUSHi( chroot(tmps) >= 0 );
RETURN;
#else
- DIE(no_func, "chroot");
+ DIE(PL_no_func, "chroot");
#endif
}
PP(pp_unlink)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
- value = (I32)apply(op->op_type, MARK, SP);
+ value = (I32)apply(PL_op->op_type, MARK, SP);
SP = MARK;
PUSHi(value);
RETURN;
PP(pp_chmod)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
- value = (I32)apply(op->op_type, MARK, SP);
+ value = (I32)apply(PL_op->op_type, MARK, SP);
SP = MARK;
PUSHi(value);
RETURN;
PP(pp_utime)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
- value = (I32)apply(op->op_type, MARK, SP);
+ value = (I32)apply(PL_op->op_type, MARK, SP);
SP = MARK;
PUSHi(value);
RETURN;
PP(pp_rename)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int anum;
+ STRLEN n_a;
- char *tmps2 = POPp;
- char *tmps = SvPV(TOPs, na);
+ char *tmps2 = POPpx;
+ char *tmps = SvPV(TOPs, n_a);
TAINT_PROPER("rename");
#ifdef HAS_RENAME
- anum = rename(tmps, tmps2);
+ anum = PerlLIO_rename(tmps, tmps2);
#else
- if (!(anum = Stat(tmps, &statbuf))) {
+ if (!(anum = PerlLIO_stat(tmps, &PL_statbuf))) {
if (same_dirent(tmps2, tmps)) /* can always rename to same name */
anum = 1;
else {
- if (euid || Stat(tmps2, &statbuf) < 0 || !S_ISDIR(statbuf.st_mode))
+ if (PL_euid || PerlLIO_stat(tmps2, &PL_statbuf) < 0 || !S_ISDIR(PL_statbuf.st_mode))
(void)UNLINK(tmps2);
if (!(anum = link(tmps, tmps2)))
anum = UNLINK(tmps);
PP(pp_link)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_LINK
- char *tmps2 = POPp;
- char *tmps = SvPV(TOPs, na);
+ STRLEN n_a;
+ char *tmps2 = POPpx;
+ char *tmps = SvPV(TOPs, n_a);
TAINT_PROPER("link");
SETi( link(tmps, tmps2) >= 0 );
#else
- DIE(no_func, "Unsupported function link");
+ DIE(PL_no_func, "Unsupported function link");
#endif
RETURN;
}
PP(pp_symlink)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_SYMLINK
- char *tmps2 = POPp;
- char *tmps = SvPV(TOPs, na);
+ STRLEN n_a;
+ char *tmps2 = POPpx;
+ char *tmps = SvPV(TOPs, n_a);
TAINT_PROPER("symlink");
SETi( symlink(tmps, tmps2) >= 0 );
RETURN;
#else
- DIE(no_func, "symlink");
+ DIE(PL_no_func, "symlink");
#endif
}
PP(pp_readlink)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_SYMLINK
char *tmps;
char buf[MAXPATHLEN];
int len;
+ STRLEN n_a;
- tmps = POPp;
+#ifndef INCOMPLETE_TAINTS
+ TAINT;
+#endif
+ tmps = POPpx;
len = readlink(tmps, buf, sizeof buf);
EXTEND(SP, 1);
if (len < 0)
*s++ = *filename++;
}
strcpy(s, " 2>&1");
- myfp = my_popen(cmdline, "r");
+ myfp = PerlProc_popen(cmdline, "r");
Safefree(cmdline);
if (myfp) {
SV *tmpsv = sv_newmortal();
- /* Need to save/restore 'rs' ?? */
+ /* Need to save/restore 'PL_rs' ?? */
s = sv_gets(tmpsv, myfp, 0);
- (void)my_pclose(myfp);
+ (void)PerlProc_pclose(myfp);
if (s != Nullch) {
int e;
for (e = 1;
return 0;
}
else { /* some mkdirs return no failure indication */
- anum = (Stat(save_filename, &statbuf) >= 0);
- if (op->op_type == OP_RMDIR)
+ anum = (PerlLIO_stat(save_filename, &PL_statbuf) >= 0);
+ if (PL_op->op_type == OP_RMDIR)
anum = !anum;
if (anum)
SETERRNO(0,0);
PP(pp_mkdir)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int mode = POPi;
#ifndef HAS_MKDIR
int oldumask;
#endif
- char *tmps = SvPV(TOPs, na);
+ STRLEN n_a;
+ char *tmps = SvPV(TOPs, n_a);
TAINT_PROPER("mkdir");
#ifdef HAS_MKDIR
- SETi( Mkdir(tmps, mode) >= 0 );
+ SETi( PerlDir_mkdir(tmps, mode) >= 0 );
#else
SETi( dooneliner("mkdir", tmps) );
- oldumask = umask(0);
- umask(oldumask);
- chmod(tmps, (mode & ~oldumask) & 0777);
+ oldumask = PerlLIO_umask(0);
+ PerlLIO_umask(oldumask);
+ PerlLIO_chmod(tmps, (mode & ~oldumask) & 0777);
#endif
RETURN;
}
PP(pp_rmdir)
{
- dSP; dTARGET;
+ djSP; dTARGET;
char *tmps;
+ STRLEN n_a;
- tmps = POPp;
+ tmps = POPpx;
TAINT_PROPER("rmdir");
#ifdef HAS_RMDIR
- XPUSHi( rmdir(tmps) >= 0 );
+ XPUSHi( PerlDir_rmdir(tmps) >= 0 );
#else
XPUSHi( dooneliner("rmdir", tmps) );
#endif
PP(pp_open_dir)
{
- dSP;
+ djSP;
#if defined(Direntry_t) && defined(HAS_READDIR)
- char *dirname = POPp;
+ STRLEN n_a;
+ char *dirname = POPpx;
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
goto nope;
if (IoDIRP(io))
- closedir(IoDIRP(io));
- if (!(IoDIRP(io) = opendir(dirname)))
+ PerlDir_close(IoDIRP(io));
+ if (!(IoDIRP(io) = PerlDir_open(dirname)))
goto nope;
RETPUSHYES;
SETERRNO(EBADF,RMS$_DIR);
RETPUSHUNDEF;
#else
- DIE(no_dir_func, "opendir");
+ DIE(PL_no_dir_func, "opendir");
#endif
}
PP(pp_readdir)
{
- dSP;
+ djSP;
#if defined(Direntry_t) && defined(HAS_READDIR)
#ifndef I_DIRENT
Direntry_t *readdir _((DIR *));
register Direntry_t *dp;
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
+ SV *sv;
if (!io || !IoDIRP(io))
goto nope;
if (GIMME == G_ARRAY) {
/*SUPPRESS 560*/
- while (dp = (Direntry_t *)readdir(IoDIRP(io))) {
+ while (dp = (Direntry_t *)PerlDir_read(IoDIRP(io))) {
#ifdef DIRNAMLEN
- XPUSHs(sv_2mortal(newSVpv(dp->d_name, dp->d_namlen)));
+ sv = newSVpvn(dp->d_name, dp->d_namlen);
#else
- XPUSHs(sv_2mortal(newSVpv(dp->d_name, 0)));
+ sv = newSVpv(dp->d_name, 0);
#endif
+#ifndef INCOMPLETE_TAINTS
+ SvTAINTED_on(sv);
+#endif
+ XPUSHs(sv_2mortal(sv));
}
}
else {
- if (!(dp = (Direntry_t *)readdir(IoDIRP(io))))
+ if (!(dp = (Direntry_t *)PerlDir_read(IoDIRP(io))))
goto nope;
#ifdef DIRNAMLEN
- XPUSHs(sv_2mortal(newSVpv(dp->d_name, dp->d_namlen)));
+ sv = newSVpvn(dp->d_name, dp->d_namlen);
#else
- XPUSHs(sv_2mortal(newSVpv(dp->d_name, 0)));
+ sv = newSVpv(dp->d_name, 0);
+#endif
+#ifndef INCOMPLETE_TAINTS
+ SvTAINTED_on(sv);
#endif
+ XPUSHs(sv_2mortal(sv));
}
RETURN;
else
RETPUSHUNDEF;
#else
- DIE(no_dir_func, "readdir");
+ DIE(PL_no_dir_func, "readdir");
#endif
}
PP(pp_telldir)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#if defined(HAS_TELLDIR) || defined(telldir)
-#if !defined(telldir) && !defined(HAS_TELLDIR_PROTOTYPE)
+ /* XXX does _anyone_ need this? --AD 2/20/1998 */
+ /* XXX netbsd still seemed to.
+ XXX HAS_TELLDIR_PROTO is new style, NEED_TELLDIR_PROTO is old style.
+ --JHI 1999-Feb-02 */
+# if !defined(HAS_TELLDIR_PROTO) || defined(NEED_TELLDIR_PROTO)
long telldir _((DIR *));
-#endif
+# endif
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
if (!io || !IoDIRP(io))
goto nope;
- PUSHi( telldir(IoDIRP(io)) );
+ PUSHi( PerlDir_tell(IoDIRP(io)) );
RETURN;
nope:
if (!errno)
SETERRNO(EBADF,RMS$_ISI);
RETPUSHUNDEF;
#else
- DIE(no_dir_func, "telldir");
+ DIE(PL_no_dir_func, "telldir");
#endif
}
PP(pp_seekdir)
{
- dSP;
+ djSP;
#if defined(HAS_SEEKDIR) || defined(seekdir)
long along = POPl;
GV *gv = (GV*)POPs;
if (!io || !IoDIRP(io))
goto nope;
- (void)seekdir(IoDIRP(io), along);
+ (void)PerlDir_seek(IoDIRP(io), along);
RETPUSHYES;
nope:
SETERRNO(EBADF,RMS$_ISI);
RETPUSHUNDEF;
#else
- DIE(no_dir_func, "seekdir");
+ DIE(PL_no_dir_func, "seekdir");
#endif
}
PP(pp_rewinddir)
{
- dSP;
+ djSP;
#if defined(HAS_REWINDDIR) || defined(rewinddir)
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
if (!io || !IoDIRP(io))
goto nope;
- (void)rewinddir(IoDIRP(io));
+ (void)PerlDir_rewind(IoDIRP(io));
RETPUSHYES;
nope:
if (!errno)
SETERRNO(EBADF,RMS$_ISI);
RETPUSHUNDEF;
#else
- DIE(no_dir_func, "rewinddir");
+ DIE(PL_no_dir_func, "rewinddir");
#endif
}
PP(pp_closedir)
{
- dSP;
+ djSP;
#if defined(Direntry_t) && defined(HAS_READDIR)
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
goto nope;
#ifdef VOID_CLOSEDIR
- closedir(IoDIRP(io));
+ PerlDir_close(IoDIRP(io));
#else
- if (closedir(IoDIRP(io)) < 0) {
+ if (PerlDir_close(IoDIRP(io)) < 0) {
IoDIRP(io) = 0; /* Don't try to close again--coredumps on SysV */
goto nope;
}
SETERRNO(EBADF,RMS$_IFI);
RETPUSHUNDEF;
#else
- DIE(no_dir_func, "closedir");
+ DIE(PL_no_dir_func, "closedir");
#endif
}
PP(pp_fork)
{
#ifdef HAS_FORK
- dSP; dTARGET;
- int childpid;
+ djSP; dTARGET;
+ Pid_t childpid;
GV *tmpgv;
EXTEND(SP, 1);
+ PERL_FLUSHALL_FOR_CHILD;
childpid = fork();
if (childpid < 0)
RETSETUNDEF;
/*SUPPRESS 560*/
if (tmpgv = gv_fetchpv("$", TRUE, SVt_PV))
sv_setiv(GvSV(tmpgv), (IV)getpid());
- hv_clear(pidstatus); /* no kids, so don't wait for 'em */
+ hv_clear(PL_pidstatus); /* no kids, so don't wait for 'em */
}
PUSHi(childpid);
RETURN;
#else
- DIE(no_func, "Unsupported function fork");
+ DIE(PL_no_func, "Unsupported function fork");
#endif
}
PP(pp_wait)
{
-#if !defined(DOSISH) || defined(OS2)
- dSP; dTARGET;
- int childpid;
+#if !defined(DOSISH) || defined(OS2) || defined(WIN32) || defined(CYGWIN32)
+ djSP; dTARGET;
+ Pid_t childpid;
int argflags;
childpid = wait4pid(-1, &argflags, 0);
XPUSHi(childpid);
RETURN;
#else
- DIE(no_func, "Unsupported function wait");
+ DIE(PL_no_func, "Unsupported function wait");
#endif
}
PP(pp_waitpid)
{
-#if !defined(DOSISH) || defined(OS2)
- dSP; dTARGET;
- int childpid;
+#if !defined(DOSISH) || defined(OS2) || defined(WIN32) || defined(CYGWIN32)
+ djSP; dTARGET;
+ Pid_t childpid;
int optype;
int argflags;
SETi(childpid);
RETURN;
#else
- DIE(no_func, "Unsupported function wait");
+ DIE(PL_no_func, "Unsupported function waitpid");
#endif
}
PP(pp_system)
{
- dSP; dMARK; dORIGMARK; dTARGET;
+ djSP; dMARK; dORIGMARK; dTARGET;
I32 value;
- int childpid;
+ Pid_t childpid;
int result;
int status;
Sigsave_t ihand,qhand; /* place to save signals during system() */
+ STRLEN n_a;
if (SP - MARK == 1) {
- if (tainting) {
- char *junk = SvPV(TOPs, na);
+ if (PL_tainting) {
+ char *junk = SvPV(TOPs, n_a);
TAINT_ENV();
TAINT_PROPER("system");
}
}
+ PERL_FLUSHALL_FOR_CHILD;
#if (defined(HAS_FORK) || defined(AMIGAOS)) && !defined(VMS) && !defined(OS2)
while ((childpid = vfork()) == -1) {
if (errno != EAGAIN) {
PUSHi(STATUS_CURRENT);
RETURN;
}
- if (op->op_flags & OPf_STACKED) {
+ if (PL_op->op_flags & OPf_STACKED) {
SV *really = *++MARK;
value = (I32)do_aexec(really, MARK, SP);
}
else if (SP - MARK != 1)
value = (I32)do_aexec(Nullsv, MARK, SP);
else {
- value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
+ value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), n_a));
}
- _exit(-1);
+ PerlProc__exit(-1);
#else /* ! FORK or VMS or OS/2 */
- if (op->op_flags & OPf_STACKED) {
+ if (PL_op->op_flags & OPf_STACKED) {
SV *really = *++MARK;
- value = (I32)do_aspawn(really, MARK, SP);
+ value = (I32)do_aspawn(really, (void **)MARK, (void **)SP);
}
else if (SP - MARK != 1)
- value = (I32)do_aspawn(Nullsv, MARK, SP);
+ value = (I32)do_aspawn(Nullsv, (void **)MARK, (void **)SP);
else {
- value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), na));
+ value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), n_a));
}
STATUS_NATIVE_SET(value);
do_execfree();
PP(pp_exec)
{
- dSP; dMARK; dORIGMARK; dTARGET;
+ djSP; dMARK; dORIGMARK; dTARGET;
I32 value;
+ STRLEN n_a;
- if (op->op_flags & OPf_STACKED) {
+ PERL_FLUSHALL_FOR_CHILD;
+ if (PL_op->op_flags & OPf_STACKED) {
SV *really = *++MARK;
value = (I32)do_aexec(really, MARK, SP);
}
#ifdef VMS
value = (I32)vms_do_aexec(Nullsv, MARK, SP);
#else
+# ifdef __OPEN_VM
+ {
+ (void ) do_aspawn(Nullsv, MARK, SP);
+ value = 0;
+ }
+# else
value = (I32)do_aexec(Nullsv, MARK, SP);
+# endif
#endif
else {
- if (tainting) {
- char *junk = SvPV(*SP, na);
+ if (PL_tainting) {
+ char *junk = SvPV(*SP, n_a);
TAINT_ENV();
TAINT_PROPER("exec");
}
#ifdef VMS
- value = (I32)vms_do_exec(SvPVx(sv_mortalcopy(*SP), na));
+ value = (I32)vms_do_exec(SvPVx(sv_mortalcopy(*SP), n_a));
#else
- value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
+# ifdef __OPEN_VM
+ (void) do_spawn(SvPVx(sv_mortalcopy(*SP), n_a));
+ value = 0;
+# else
+ value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), n_a));
+# endif
#endif
}
SP = ORIGMARK;
PP(pp_kill)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
#ifdef HAS_KILL
- value = (I32)apply(op->op_type, MARK, SP);
+ value = (I32)apply(PL_op->op_type, MARK, SP);
SP = MARK;
PUSHi(value);
RETURN;
#else
- DIE(no_func, "Unsupported function kill");
+ DIE(PL_no_func, "Unsupported function kill");
#endif
}
PP(pp_getppid)
{
#ifdef HAS_GETPPID
- dSP; dTARGET;
+ djSP; dTARGET;
XPUSHi( getppid() );
RETURN;
#else
- DIE(no_func, "getppid");
+ DIE(PL_no_func, "getppid");
#endif
}
PP(pp_getpgrp)
{
#ifdef HAS_GETPGRP
- dSP; dTARGET;
+ djSP; dTARGET;
int pid;
I32 value;
XPUSHi(value);
RETURN;
#else
- DIE(no_func, "getpgrp()");
+ DIE(PL_no_func, "getpgrp()");
#endif
}
PP(pp_setpgrp)
{
#ifdef HAS_SETPGRP
- dSP; dTARGET;
+ djSP; dTARGET;
int pgrp;
int pid;
if (MAXARG < 2) {
#ifdef BSD_SETPGRP
SETi( BSD_SETPGRP(pid, pgrp) >= 0 );
#else
- if ((pgrp != 0 && pgrp != getpid())) || (pid != 0 && pid != getpid()))
+ if ((pgrp != 0 && pgrp != getpid()) || (pid != 0 && pid != getpid()))
DIE("POSIX setpgrp can't take an argument");
SETi( setpgrp() >= 0 );
#endif /* USE_BSDPGRP */
RETURN;
#else
- DIE(no_func, "setpgrp()");
+ DIE(PL_no_func, "setpgrp()");
#endif
}
PP(pp_getpriority)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int which;
int who;
#ifdef HAS_GETPRIORITY
SETi( getpriority(which, who) );
RETURN;
#else
- DIE(no_func, "getpriority()");
+ DIE(PL_no_func, "getpriority()");
#endif
}
PP(pp_setpriority)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int which;
int who;
int niceval;
SETi( setpriority(which, who, niceval) >= 0 );
RETURN;
#else
- DIE(no_func, "setpriority()");
+ DIE(PL_no_func, "setpriority()");
#endif
}
PP(pp_time)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef BIG_TIME
XPUSHn( time(Null(Time_t*)) );
#else
PP(pp_tms)
{
- dSP;
+ djSP;
#ifndef HAS_TIMES
DIE("times not implemented");
EXTEND(SP, 4);
#ifndef VMS
- (void)times(×buf);
+ (void)PerlProc_times(&PL_timesbuf);
#else
- (void)times((tbuffer_t *)×buf); /* time.h uses different name for */
- /* struct tms, though same data */
- /* is returned. */
+ (void)PerlProc_times((tbuffer_t *)&PL_timesbuf); /* time.h uses different name for */
+ /* struct tms, though same data */
+ /* is returned. */
#endif
- PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_utime)/HZ)));
+ PUSHs(sv_2mortal(newSVnv(((double)PL_timesbuf.tms_utime)/HZ)));
if (GIMME == G_ARRAY) {
- PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_stime)/HZ)));
- PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_cutime)/HZ)));
- PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_cstime)/HZ)));
+ PUSHs(sv_2mortal(newSVnv(((double)PL_timesbuf.tms_stime)/HZ)));
+ PUSHs(sv_2mortal(newSVnv(((double)PL_timesbuf.tms_cutime)/HZ)));
+ PUSHs(sv_2mortal(newSVnv(((double)PL_timesbuf.tms_cstime)/HZ)));
}
RETURN;
#endif /* HAS_TIMES */
PP(pp_gmtime)
{
- dSP;
+ djSP;
Time_t when;
struct tm *tmbuf;
static char *dayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
when = (Time_t)SvIVx(POPs);
#endif
- if (op->op_type == OP_LOCALTIME)
+ if (PL_op->op_type == OP_LOCALTIME)
tmbuf = localtime(&when);
else
tmbuf = gmtime(&when);
PP(pp_alarm)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int anum;
#ifdef HAS_ALARM
anum = POPi;
PUSHi((I32)anum);
RETURN;
#else
- DIE(no_func, "Unsupported function alarm");
+ DIE(PL_no_func, "Unsupported function alarm");
#endif
}
PP(pp_sleep)
{
- dSP; dTARGET;
+ djSP; dTARGET;
I32 duration;
Time_t lasttime;
Time_t when;
(void)time(&lasttime);
if (MAXARG < 1)
- Pause();
+ PerlProc_pause();
else {
duration = POPi;
- sleep((unsigned int)duration);
+ PerlProc_sleep((unsigned int)duration);
}
(void)time(&when);
XPUSHi(when - lasttime);
PP(pp_shmwrite)
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- dSP; dMARK; dTARGET;
- I32 value = (I32)(do_shmio(op->op_type, MARK, SP) >= 0);
+ djSP; dMARK; dTARGET;
+ I32 value = (I32)(do_shmio(PL_op->op_type, MARK, SP) >= 0);
SP = MARK;
PUSHi(value);
RETURN;
PP(pp_msgsnd)
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value = (I32)(do_msgsnd(MARK, SP) >= 0);
SP = MARK;
PUSHi(value);
PP(pp_msgrcv)
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value = (I32)(do_msgrcv(MARK, SP) >= 0);
SP = MARK;
PUSHi(value);
PP(pp_semget)
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- dSP; dMARK; dTARGET;
- int anum = do_ipcget(op->op_type, MARK, SP);
+ djSP; dMARK; dTARGET;
+ int anum = do_ipcget(PL_op->op_type, MARK, SP);
SP = MARK;
if (anum == -1)
RETPUSHUNDEF;
PP(pp_semctl)
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- dSP; dMARK; dTARGET;
- int anum = do_ipcctl(op->op_type, MARK, SP);
+ djSP; dMARK; dTARGET;
+ int anum = do_ipcctl(PL_op->op_type, MARK, SP);
SP = MARK;
if (anum == -1)
RETSETUNDEF;
PP(pp_semop)
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value = (I32)(do_semop(MARK, SP) >= 0);
SP = MARK;
PUSHi(value);
PP(pp_ghbyname)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETHOSTBYNAME
return pp_ghostent(ARGS);
#else
- DIE(no_sock_func, "gethostbyname");
+ DIE(PL_no_sock_func, "gethostbyname");
#endif
}
PP(pp_ghbyaddr)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETHOSTBYADDR
return pp_ghostent(ARGS);
#else
- DIE(no_sock_func, "gethostbyaddr");
+ DIE(PL_no_sock_func, "gethostbyaddr");
#endif
}
PP(pp_ghostent)
{
- dSP;
-#ifdef HAS_SOCKET
- I32 which = op->op_type;
+ djSP;
+#if defined(HAS_GETHOSTBYNAME) || defined(HAS_GETHOSTBYADDR) || defined(HAS_GETHOSTENT)
+ I32 which = PL_op->op_type;
register char **elem;
register SV *sv;
- struct hostent *gethostbyname();
- struct hostent *gethostbyaddr();
-#ifdef HAS_GETHOSTENT
- struct hostent *gethostent();
+#ifndef HAS_GETHOST_PROTOS /* XXX Do we need individual probes? */
+ struct hostent *PerlSock_gethostbyaddr(Netdb_host_t, Netdb_hlen_t, int);
+ struct hostent *PerlSock_gethostbyname(Netdb_name_t);
+ struct hostent *PerlSock_gethostent(void);
#endif
struct hostent *hent;
unsigned long len;
+ STRLEN n_a;
EXTEND(SP, 10);
- if (which == OP_GHBYNAME) {
- hent = gethostbyname(POPp);
- }
+ if (which == OP_GHBYNAME)
+#ifdef HAS_GETHOSTBYNAME
+ hent = PerlSock_gethostbyname(POPpx);
+#else
+ DIE(PL_no_sock_func, "gethostbyname");
+#endif
else if (which == OP_GHBYADDR) {
+#ifdef HAS_GETHOSTBYADDR
int addrtype = POPi;
SV *addrsv = POPs;
STRLEN addrlen;
- char *addr = SvPV(addrsv, addrlen);
+ Netdb_host_t addr = (Netdb_host_t) SvPV(addrsv, addrlen);
- hent = gethostbyaddr(addr, addrlen, addrtype);
+ hent = PerlSock_gethostbyaddr(addr, (Netdb_hlen_t) addrlen, addrtype);
+#else
+ DIE(PL_no_sock_func, "gethostbyaddr");
+#endif
}
else
#ifdef HAS_GETHOSTENT
- hent = gethostent();
+ hent = PerlSock_gethostent();
#else
- DIE("gethostent not implemented");
+ DIE(PL_no_sock_func, "gethostent");
#endif
#ifdef HOST_NOT_FOUND
}
if (hent) {
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, (char*)hent->h_name);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
for (elem = hent->h_aliases; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
}
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setiv(sv, (IV)hent->h_addrtype);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
len = hent->h_length;
sv_setiv(sv, (IV)len);
#ifdef h_addr
for (elem = hent->h_addr_list; elem && *elem; elem++) {
- XPUSHs(sv = sv_mortalcopy(&sv_no));
+ XPUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpvn(sv, *elem, len);
}
#else
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
if (hent->h_addr)
sv_setpvn(sv, hent->h_addr, len);
#endif /* h_addr */
}
RETURN;
#else
- DIE(no_sock_func, "gethostent");
+ DIE(PL_no_sock_func, "gethostent");
#endif
}
PP(pp_gnbyname)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETNETBYNAME
return pp_gnetent(ARGS);
#else
- DIE(no_sock_func, "getnetbyname");
+ DIE(PL_no_sock_func, "getnetbyname");
#endif
}
PP(pp_gnbyaddr)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETNETBYADDR
return pp_gnetent(ARGS);
#else
- DIE(no_sock_func, "getnetbyaddr");
+ DIE(PL_no_sock_func, "getnetbyaddr");
#endif
}
PP(pp_gnetent)
{
- dSP;
-#ifdef HAS_SOCKET
- I32 which = op->op_type;
+ djSP;
+#if defined(HAS_GETNETBYNAME) || defined(HAS_GETNETBYADDR) || defined(HAS_GETNETENT)
+ I32 which = PL_op->op_type;
register char **elem;
register SV *sv;
- struct netent *getnetbyname();
- struct netent *getnetbyaddr();
- struct netent *getnetent();
+#ifndef HAS_GETNET_PROTOS /* XXX Do we need individual probes? */
+ struct netent *PerlSock_getnetbyaddr(Netdb_net_t, int);
+ struct netent *PerlSock_getnetbyname(Netdb_name_t);
+ struct netent *PerlSock_getnetent(void);
+#endif
struct netent *nent;
+ STRLEN n_a;
if (which == OP_GNBYNAME)
- nent = getnetbyname(POPp);
+#ifdef HAS_GETNETBYNAME
+ nent = PerlSock_getnetbyname(POPpx);
+#else
+ DIE(PL_no_sock_func, "getnetbyname");
+#endif
else if (which == OP_GNBYADDR) {
+#ifdef HAS_GETNETBYADDR
int addrtype = POPi;
- unsigned long addr = U_L(POPn);
- nent = getnetbyaddr((long)addr, addrtype);
+ Netdb_net_t addr = (Netdb_net_t) U_L(POPn);
+ nent = PerlSock_getnetbyaddr(addr, addrtype);
+#else
+ DIE(PL_no_sock_func, "getnetbyaddr");
+#endif
}
else
- nent = getnetent();
+#ifdef HAS_GETNETENT
+ nent = PerlSock_getnetent();
+#else
+ DIE(PL_no_sock_func, "getnetent");
+#endif
EXTEND(SP, 4);
if (GIMME != G_ARRAY) {
}
if (nent) {
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, nent->n_name);
- PUSHs(sv = sv_mortalcopy(&sv_no));
- for (elem = nent->n_aliases; *elem; elem++) {
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+ for (elem = nent->n_aliases; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
}
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setiv(sv, (IV)nent->n_addrtype);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setiv(sv, (IV)nent->n_net);
}
RETURN;
#else
- DIE(no_sock_func, "getnetent");
+ DIE(PL_no_sock_func, "getnetent");
#endif
}
PP(pp_gpbyname)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETPROTOBYNAME
return pp_gprotoent(ARGS);
#else
- DIE(no_sock_func, "getprotobyname");
+ DIE(PL_no_sock_func, "getprotobyname");
#endif
}
PP(pp_gpbynumber)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETPROTOBYNUMBER
return pp_gprotoent(ARGS);
#else
- DIE(no_sock_func, "getprotobynumber");
+ DIE(PL_no_sock_func, "getprotobynumber");
#endif
}
PP(pp_gprotoent)
{
- dSP;
-#ifdef HAS_SOCKET
- I32 which = op->op_type;
+ djSP;
+#if defined(HAS_GETPROTOBYNAME) || defined(HAS_GETPROTOBYNUMBER) || defined(HAS_GETPROTOENT)
+ I32 which = PL_op->op_type;
register char **elem;
- register SV *sv;
- struct protoent *getprotobyname();
- struct protoent *getprotobynumber();
- struct protoent *getprotoent();
+ register SV *sv;
+#ifndef HAS_GETPROTO_PROTOS /* XXX Do we need individual probes? */
+ struct protoent *PerlSock_getprotobyname(Netdb_name_t);
+ struct protoent *PerlSock_getprotobynumber(int);
+ struct protoent *PerlSock_getprotoent(void);
+#endif
struct protoent *pent;
+ STRLEN n_a;
if (which == OP_GPBYNAME)
- pent = getprotobyname(POPp);
+#ifdef HAS_GETPROTOBYNAME
+ pent = PerlSock_getprotobyname(POPpx);
+#else
+ DIE(PL_no_sock_func, "getprotobyname");
+#endif
else if (which == OP_GPBYNUMBER)
- pent = getprotobynumber(POPi);
+#ifdef HAS_GETPROTOBYNUMBER
+ pent = PerlSock_getprotobynumber(POPi);
+#else
+ DIE(PL_no_sock_func, "getprotobynumber");
+#endif
else
- pent = getprotoent();
+#ifdef HAS_GETPROTOENT
+ pent = PerlSock_getprotoent();
+#else
+ DIE(PL_no_sock_func, "getprotoent");
+#endif
EXTEND(SP, 3);
if (GIMME != G_ARRAY) {
}
if (pent) {
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, pent->p_name);
- PUSHs(sv = sv_mortalcopy(&sv_no));
- for (elem = pent->p_aliases; *elem; elem++) {
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+ for (elem = pent->p_aliases; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
}
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setiv(sv, (IV)pent->p_proto);
}
RETURN;
#else
- DIE(no_sock_func, "getprotoent");
+ DIE(PL_no_sock_func, "getprotoent");
#endif
}
PP(pp_gsbyname)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETSERVBYNAME
return pp_gservent(ARGS);
#else
- DIE(no_sock_func, "getservbyname");
+ DIE(PL_no_sock_func, "getservbyname");
#endif
}
PP(pp_gsbyport)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETSERVBYPORT
return pp_gservent(ARGS);
#else
- DIE(no_sock_func, "getservbyport");
+ DIE(PL_no_sock_func, "getservbyport");
#endif
}
PP(pp_gservent)
{
- dSP;
-#ifdef HAS_SOCKET
- I32 which = op->op_type;
+ djSP;
+#if defined(HAS_GETSERVBYNAME) || defined(HAS_GETSERVBYPORT) || defined(HAS_GETSERVENT)
+ I32 which = PL_op->op_type;
register char **elem;
register SV *sv;
- struct servent *getservbyname();
- struct servent *getservbynumber();
- struct servent *getservent();
+#ifndef HAS_GETSERV_PROTOS /* XXX Do we need individual probes? */
+ struct servent *PerlSock_getservbyname(Netdb_name_t, Netdb_name_t);
+ struct servent *PerlSock_getservbyport(int, Netdb_name_t);
+ struct servent *PerlSock_getservent(void);
+#endif
struct servent *sent;
+ STRLEN n_a;
if (which == OP_GSBYNAME) {
- char *proto = POPp;
- char *name = POPp;
+#ifdef HAS_GETSERVBYNAME
+ char *proto = POPpx;
+ char *name = POPpx;
if (proto && !*proto)
proto = Nullch;
- sent = getservbyname(name, proto);
+ sent = PerlSock_getservbyname(name, proto);
+#else
+ DIE(PL_no_sock_func, "getservbyname");
+#endif
}
else if (which == OP_GSBYPORT) {
- char *proto = POPp;
+#ifdef HAS_GETSERVBYPORT
+ char *proto = POPpx;
unsigned short port = POPu;
#ifdef HAS_HTONS
- port = htons(port);
+ port = PerlSock_htons(port);
+#endif
+ sent = PerlSock_getservbyport(port, proto);
+#else
+ DIE(PL_no_sock_func, "getservbyport");
#endif
- sent = getservbyport(port, proto);
}
else
- sent = getservent();
+#ifdef HAS_GETSERVENT
+ sent = PerlSock_getservent();
+#else
+ DIE(PL_no_sock_func, "getservent");
+#endif
EXTEND(SP, 4);
if (GIMME != G_ARRAY) {
if (sent) {
if (which == OP_GSBYNAME) {
#ifdef HAS_NTOHS
- sv_setiv(sv, (IV)ntohs(sent->s_port));
+ sv_setiv(sv, (IV)PerlSock_ntohs(sent->s_port));
#else
sv_setiv(sv, (IV)(sent->s_port));
#endif
}
if (sent) {
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, sent->s_name);
- PUSHs(sv = sv_mortalcopy(&sv_no));
- for (elem = sent->s_aliases; *elem; elem++) {
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+ for (elem = sent->s_aliases; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
}
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
#ifdef HAS_NTOHS
- sv_setiv(sv, (IV)ntohs(sent->s_port));
+ sv_setiv(sv, (IV)PerlSock_ntohs(sent->s_port));
#else
sv_setiv(sv, (IV)(sent->s_port));
#endif
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, sent->s_proto);
}
RETURN;
#else
- DIE(no_sock_func, "getservent");
+ DIE(PL_no_sock_func, "getservent");
#endif
}
PP(pp_shostent)
{
- dSP;
-#ifdef HAS_SOCKET
- sethostent(TOPi);
+ djSP;
+#ifdef HAS_SETHOSTENT
+ PerlSock_sethostent(TOPi);
RETSETYES;
#else
- DIE(no_sock_func, "sethostent");
+ DIE(PL_no_sock_func, "sethostent");
#endif
}
PP(pp_snetent)
{
- dSP;
-#ifdef HAS_SOCKET
- setnetent(TOPi);
+ djSP;
+#ifdef HAS_SETNETENT
+ PerlSock_setnetent(TOPi);
RETSETYES;
#else
- DIE(no_sock_func, "setnetent");
+ DIE(PL_no_sock_func, "setnetent");
#endif
}
PP(pp_sprotoent)
{
- dSP;
-#ifdef HAS_SOCKET
- setprotoent(TOPi);
+ djSP;
+#ifdef HAS_SETPROTOENT
+ PerlSock_setprotoent(TOPi);
RETSETYES;
#else
- DIE(no_sock_func, "setprotoent");
+ DIE(PL_no_sock_func, "setprotoent");
#endif
}
PP(pp_sservent)
{
- dSP;
-#ifdef HAS_SOCKET
- setservent(TOPi);
+ djSP;
+#ifdef HAS_SETSERVENT
+ PerlSock_setservent(TOPi);
RETSETYES;
#else
- DIE(no_sock_func, "setservent");
+ DIE(PL_no_sock_func, "setservent");
#endif
}
PP(pp_ehostent)
{
- dSP;
-#ifdef HAS_SOCKET
- endhostent();
- EXTEND(sp,1);
+ djSP;
+#ifdef HAS_ENDHOSTENT
+ PerlSock_endhostent();
+ EXTEND(SP,1);
RETPUSHYES;
#else
- DIE(no_sock_func, "endhostent");
+ DIE(PL_no_sock_func, "endhostent");
#endif
}
PP(pp_enetent)
{
- dSP;
-#ifdef HAS_SOCKET
- endnetent();
- EXTEND(sp,1);
+ djSP;
+#ifdef HAS_ENDNETENT
+ PerlSock_endnetent();
+ EXTEND(SP,1);
RETPUSHYES;
#else
- DIE(no_sock_func, "endnetent");
+ DIE(PL_no_sock_func, "endnetent");
#endif
}
PP(pp_eprotoent)
{
- dSP;
-#ifdef HAS_SOCKET
- endprotoent();
- EXTEND(sp,1);
+ djSP;
+#ifdef HAS_ENDPROTOENT
+ PerlSock_endprotoent();
+ EXTEND(SP,1);
RETPUSHYES;
#else
- DIE(no_sock_func, "endprotoent");
+ DIE(PL_no_sock_func, "endprotoent");
#endif
}
PP(pp_eservent)
{
- dSP;
-#ifdef HAS_SOCKET
- endservent();
- EXTEND(sp,1);
+ djSP;
+#ifdef HAS_ENDSERVENT
+ PerlSock_endservent();
+ EXTEND(SP,1);
RETPUSHYES;
#else
- DIE(no_sock_func, "endservent");
+ DIE(PL_no_sock_func, "endservent");
#endif
}
#ifdef HAS_PASSWD
return pp_gpwent(ARGS);
#else
- DIE(no_func, "getpwnam");
+ DIE(PL_no_func, "getpwnam");
#endif
}
#ifdef HAS_PASSWD
return pp_gpwent(ARGS);
#else
- DIE(no_func, "getpwuid");
+ DIE(PL_no_func, "getpwuid");
#endif
}
PP(pp_gpwent)
{
- dSP;
-#ifdef HAS_PASSWD
- I32 which = op->op_type;
+ djSP;
+#if defined(HAS_PASSWD) && defined(HAS_GETPWENT)
+ I32 which = PL_op->op_type;
register SV *sv;
struct passwd *pwent;
+ STRLEN n_a;
+#ifdef HAS_GETSPENT
+ struct spwd *spwent;
+#endif
if (which == OP_GPWNAM)
- pwent = getpwnam(POPp);
+ pwent = getpwnam(POPpx);
else if (which == OP_GPWUID)
pwent = getpwuid(POPi);
else
pwent = (struct passwd *)getpwent();
+#ifdef HAS_GETSPENT
+ if (which == OP_GPWNAM)
+ spwent = getspnam(pwent->pw_name);
+ else if (which == OP_GPWUID)
+ spwent = getspnam(pwent->pw_name);
+ else
+ spwent = (struct spwd *)getspent();
+#endif
+
EXTEND(SP, 10);
if (GIMME != G_ARRAY) {
PUSHs(sv = sv_newmortal());
}
if (pwent) {
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, pwent->pw_name);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+#ifdef PWPASSWD
+#ifdef HAS_GETSPENT
+ if (spwent)
+ sv_setpv(sv, spwent->sp_pwdp);
+ else
+ sv_setpv(sv, pwent->pw_passwd);
+#else
sv_setpv(sv, pwent->pw_passwd);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+#endif
+#endif
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setiv(sv, (IV)pwent->pw_uid);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setiv(sv, (IV)pwent->pw_gid);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+
+ /* pw_change, pw_quota, and pw_age are mutually exclusive. */
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
#ifdef PWCHANGE
sv_setiv(sv, (IV)pwent->pw_change);
#else
-#ifdef PWQUOTA
+# ifdef PWQUOTA
sv_setiv(sv, (IV)pwent->pw_quota);
-#else
-#ifdef PWAGE
+# else
+# ifdef PWAGE
sv_setpv(sv, pwent->pw_age);
+# endif
+# endif
#endif
-#endif
-#endif
- PUSHs(sv = sv_mortalcopy(&sv_no));
+
+ /* pw_class and pw_comment are mutually exclusive. */
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
#ifdef PWCLASS
sv_setpv(sv, pwent->pw_class);
#else
-#ifdef PWCOMMENT
+# ifdef PWCOMMENT
sv_setpv(sv, pwent->pw_comment);
+# endif
#endif
-#endif
- PUSHs(sv = sv_mortalcopy(&sv_no));
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+#ifdef PWGECOS
sv_setpv(sv, pwent->pw_gecos);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+#endif
+#ifndef INCOMPLETE_TAINTS
+ /* pw_gecos is tainted because user himself can diddle with it. */
+ SvTAINTED_on(sv);
+#endif
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, pwent->pw_dir);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, pwent->pw_shell);
+
#ifdef PWEXPIRE
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setiv(sv, (IV)pwent->pw_expire);
#endif
}
RETURN;
#else
- DIE(no_func, "getpwent");
+ DIE(PL_no_func, "getpwent");
#endif
}
PP(pp_spwent)
{
- dSP;
-#if defined(HAS_PASSWD) && !defined(CYGWIN32)
+ djSP;
+#if defined(HAS_PASSWD) && defined(HAS_SETPWENT) && !defined(CYGWIN32)
setpwent();
+#ifdef HAS_GETSPENT
+ setspent();
+#endif
RETPUSHYES;
#else
- DIE(no_func, "setpwent");
+ DIE(PL_no_func, "setpwent");
#endif
}
PP(pp_epwent)
{
- dSP;
-#ifdef HAS_PASSWD
+ djSP;
+#if defined(HAS_PASSWD) && defined(HAS_ENDPWENT)
endpwent();
+#ifdef HAS_GETSPENT
+ endspent();
+#endif
RETPUSHYES;
#else
- DIE(no_func, "endpwent");
+ DIE(PL_no_func, "endpwent");
#endif
}
#ifdef HAS_GROUP
return pp_ggrent(ARGS);
#else
- DIE(no_func, "getgrnam");
+ DIE(PL_no_func, "getgrnam");
#endif
}
#ifdef HAS_GROUP
return pp_ggrent(ARGS);
#else
- DIE(no_func, "getgrgid");
+ DIE(PL_no_func, "getgrgid");
#endif
}
PP(pp_ggrent)
{
- dSP;
-#ifdef HAS_GROUP
- I32 which = op->op_type;
+ djSP;
+#if defined(HAS_GROUP) && defined(HAS_GETGRENT)
+ I32 which = PL_op->op_type;
register char **elem;
register SV *sv;
struct group *grent;
+ STRLEN n_a;
if (which == OP_GGRNAM)
- grent = (struct group *)getgrnam(POPp);
+ grent = (struct group *)getgrnam(POPpx);
else if (which == OP_GGRGID)
grent = (struct group *)getgrgid(POPi);
else
}
if (grent) {
- PUSHs(sv = sv_mortalcopy(&sv_no));
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setpv(sv, grent->gr_name);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+#ifdef GRPASSWD
sv_setpv(sv, grent->gr_passwd);
- PUSHs(sv = sv_mortalcopy(&sv_no));
+#endif
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
sv_setiv(sv, (IV)grent->gr_gid);
- PUSHs(sv = sv_mortalcopy(&sv_no));
- for (elem = grent->gr_mem; *elem; elem++) {
+
+ PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+ for (elem = grent->gr_mem; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
RETURN;
#else
- DIE(no_func, "getgrent");
+ DIE(PL_no_func, "getgrent");
#endif
}
PP(pp_sgrent)
{
- dSP;
-#ifdef HAS_GROUP
+ djSP;
+#if defined(HAS_GROUP) && defined(HAS_SETGRENT)
setgrent();
RETPUSHYES;
#else
- DIE(no_func, "setgrent");
+ DIE(PL_no_func, "setgrent");
#endif
}
PP(pp_egrent)
{
- dSP;
-#ifdef HAS_GROUP
+ djSP;
+#if defined(HAS_GROUP) && defined(HAS_ENDGRENT)
endgrent();
RETPUSHYES;
#else
- DIE(no_func, "endgrent");
+ DIE(PL_no_func, "endgrent");
#endif
}
PP(pp_getlogin)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_GETLOGIN
char *tmps;
EXTEND(SP, 1);
- if (!(tmps = getlogin()))
+ if (!(tmps = PerlProc_getlogin()))
RETPUSHUNDEF;
PUSHp(tmps, strlen(tmps));
RETURN;
#else
- DIE(no_func, "getlogin");
+ DIE(PL_no_func, "getlogin");
#endif
}
PP(pp_syscall)
{
#ifdef HAS_SYSCALL
- dSP; dMARK; dORIGMARK; dTARGET;
+ djSP; dMARK; dORIGMARK; dTARGET;
register I32 items = SP - MARK;
unsigned long a[20];
register I32 i = 0;
I32 retval = -1;
MAGIC *mg;
+ STRLEN n_a;
- if (tainting) {
+ if (PL_tainting) {
while (++MARK <= SP) {
if (SvTAINTED(*MARK)) {
TAINT;
while (++MARK <= SP) {
if (SvNIOK(*MARK) || !i)
a[i++] = SvIV(*MARK);
- else if (*MARK == &sv_undef)
+ else if (*MARK == &PL_sv_undef)
a[i++] = 0;
else
- a[i++] = (unsigned long)SvPV_force(*MARK, na);
+ a[i++] = (unsigned long)SvPV_force(*MARK, n_a);
if (i > 15)
break;
}
PUSHi(retval);
RETURN;
#else
- DIE(no_func, "syscall");
+ DIE(PL_no_func, "syscall");
#endif
}
*/
static int
-fcntl_emulate_flock(fd, operation)
-int fd;
-int operation;
+fcntl_emulate_flock(int fd, int operation)
{
struct flock flock;
int operation;
{
int i;
+ int save_errno;
+ Off_t pos;
+
+ /* flock locks entire file so for lockf we need to do the same */
+ save_errno = errno;
+ pos = PerlLIO_lseek(fd, (Off_t)0, SEEK_CUR); /* get pos to restore later */
+ if (pos > 0) /* is seekable and needs to be repositioned */
+ if (PerlLIO_lseek(fd, (Off_t)0, SEEK_SET) < 0)
+ pos = -1; /* seek failed, so don't seek back afterwards */
+ errno = save_errno;
+
switch (operation) {
/* LOCK_SH - get a shared lock */
errno = EINVAL;
break;
}
+
+ if (pos > 0) /* need to restore position of the handle */
+ PerlLIO_lseek(fd, pos, SEEK_SET); /* ignore error here */
+
return (i);
}