# 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
# include <sys/resource.h>
#endif
-/* Put this after #includes because fork and vfork prototypes may
- conflict.
-*/
-#ifndef HAS_VFORK
-# define vfork fork
-#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. HOST_NOT_FOUND is typically defined in <netdb.h>.
+*/
+#if defined(HOST_NOT_FOUND) && !defined(h_errno)
extern int h_errno;
#endif
#endif
#ifdef I_UTIME
-#include <utime.h>
+# if defined(_MSC_VER) || defined(__MINGW32__)
+# include <sys/utime.h>
+# else
+# include <utime.h>
+# endif
#endif
#ifdef I_FCNTL
#include <fcntl.h>
#include <sys/file.h>
#endif
+/* Put this after #includes because fork and vfork prototypes may conflict. */
+#ifndef HAS_VFORK
+# define vfork fork
+#endif
+
+/* Put this after #includes because <unistd.h> defines _XOPEN_*. */
+#ifndef Sock_size_t
+# if _XOPEN_VERSION >= 5 || defined(_XOPEN_SOURCE_EXTENDED) || defined(__GLIBC__)
+# define Sock_size_t Size_t
+# else
+# define Sock_size_t int
+# endif
+#endif
+
#if !defined(HAS_MKDIR) || !defined(HAS_RMDIR)
static int dooneliner _((char *cmd, char *filename));
#endif
# 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. */
PP(pp_backtick)
{
- dSP; dTARGET;
+ djSP; dTARGET;
PerlIO *fp;
char *tmps = POPp;
+ I32 gimme = GIMME_V;
+
TAINT_PROPER("``");
- fp = my_popen(tmps, "r");
+ fp = PerlProc_popen(tmps, "r");
if (fp) {
- if (GIMME == G_SCALAR) {
+ if (gimme == G_VOID) {
+ char tmpbuf[256];
+ while (PerlIO_read(fp, tmpbuf, sizeof tmpbuf) > 0)
+ /*SUPPRESS 530*/
+ ;
+ }
+ else if (gimme == G_SCALAR) {
sv_setpv(TARG, ""); /* note that this preserves previous buffer */
while (sv_gets(TARG, fp, SvCUR(TARG)) != Nullch)
/*SUPPRESS 530*/
SvTAINTED_on(sv);
}
}
- STATUS_NATIVE_SET(my_pclose(fp));
+ STATUS_NATIVE_SET(PerlProc_pclose(fp));
TAINT; /* "I believe that this is not gratuitous!" */
}
else {
STATUS_NATIVE_SET(-1);
- if (GIMME == G_SCALAR)
+ if (gimme == G_SCALAR)
RETPUSHUNDEF;
}
OP *result;
ENTER;
+#ifndef VMS
+ if (tainting) {
+ /*
+ * The external globbing program may use things we can't control,
+ * so for security reasons we must assume the worst.
+ */
+ TAINT;
+ taint_proper(no_security, "glob");
+ }
+#endif /* !VMS */
+
SAVESPTR(last_in_gv); /* We don't want this to be permanent. */
last_in_gv = (GV*)*stack_sp--;
PP(pp_warn)
{
- dSP; dMARK;
+ djSP; dMARK;
char *tmps;
if (SP - MARK != 1) {
dTARGET;
tmps = SvPV(TOPs, na);
}
if (!tmps || !*tmps) {
- SV *error = GvSV(errgv);
- (void)SvUPGRADE(error, SVt_PV);
- if (SvPOK(error) && SvCUR(error))
- sv_catpv(error, "\t...caught");
- tmps = SvPV(error, na);
+ (void)SvUPGRADE(ERRSV, SVt_PV);
+ if (SvPOK(ERRSV) && SvCUR(ERRSV))
+ sv_catpv(ERRSV, "\t...caught");
+ tmps = SvPV(ERRSV, na);
}
if (!tmps || !*tmps)
tmps = "Warning: something's wrong";
PP(pp_die)
{
- dSP; dMARK;
+ djSP; dMARK;
char *tmps;
if (SP - MARK != 1) {
dTARGET;
tmps = SvPV(TOPs, na);
}
if (!tmps || !*tmps) {
- SV *error = GvSV(errgv);
- (void)SvUPGRADE(error, SVt_PV);
- if (SvPOK(error) && SvCUR(error))
- sv_catpv(error, "\t...propagated");
- tmps = SvPV(error, na);
+ (void)SvUPGRADE(ERRSV, SVt_PV);
+ if (SvPOK(ERRSV) && SvCUR(ERRSV))
+ sv_catpv(ERRSV, "\t...propagated");
+ tmps = SvPV(ERRSV, na);
}
if (!tmps || !*tmps)
tmps = "Died";
PP(pp_open)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *gv;
SV *sv;
char *tmps;
PP(pp_close)
{
- dSP;
+ djSP;
GV *gv;
+ MAGIC *mg;
if (MAXARG == 0)
gv = defoutgv;
else
gv = (GV*)POPs;
+
+ if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
+ PUSHMARK(SP);
+ XPUSHs(mg->mg_obj);
+ PUTBACK;
+ ENTER;
+ perl_call_method("CLOSE", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ RETURN;
+ }
EXTEND(SP, 1);
- PUSHs( do_close(gv, TRUE) ? &sv_yes : &sv_no );
+ PUSHs(boolSV(do_close(gv, TRUE)));
RETURN;
}
PP(pp_pipe_op)
{
- dSP;
+ djSP;
#ifdef HAS_PIPE
GV *rgv;
GV *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;
}
PP(pp_fileno)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *gv;
IO *io;
PerlIO *fp;
PP(pp_umask)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int 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
PP(pp_binmode)
{
- dSP;
+ djSP;
GV *gv;
IO *io;
PerlIO *fp;
else
RETPUSHUNDEF;
#else
- if (setmode(PerlIO_fileno(fp), OP_BINARY) != -1)
+ if (PerlLIO_setmode(PerlIO_fileno(fp), OP_BINARY) != -1) {
+#if defined(WIN32) && defined(__BORLANDC__)
+ /* The translation mode of the stream is maintained independent
+ * of the translation mode of the fd in the Borland RTL (heavy
+ * digging through their runtime sources reveal). User has to
+ * set the mode explicitly for the stream (though they don't
+ * document this anywhere). GSAR 97-5-24
+ */
+ PerlIO_seek(fp,0L,0);
+ fp->flags |= _F_BIN;
+#endif
RETPUSHYES;
+ }
else
RETPUSHUNDEF;
#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 - stack_base;
char *methname;
- bool oldmustcatch = mustcatch;
-
- 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";
+ int how = 'P';
+ U32 items;
- 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_KNOW|OPf_STACKED;
- mustcatch = 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();
+ 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;
+ PUSHSTACK(SI_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,na));
+ }
+ ENTER;
+ PUSHSTACK(SI_MAGIC);
+ PUSHMARK(SP);
+ EXTEND(SP,items);
+ while (items--)
+ PUSHs(*MARK++);
+ PUTBACK;
+ perl_call_sv((SV*)GvCV(gv), G_SCALAR);
+ }
SPAGAIN;
- mustcatch = oldmustcatch;
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, sv, how, Nullch, 0);
}
LEAVE;
SP = stack_base + markoff;
PP(pp_untie)
{
- dSP;
+ djSP;
SV * sv ;
-
- sv = POPs;
+ sv = POPs;
if (dowarn) {
MAGIC * mg ;
PP(pp_tied)
{
- dSP;
+ djSP;
SV * sv ;
MAGIC * mg ;
RETURN ;
}
}
-
RETPUSHUNDEF;
}
PP(pp_dbmopen)
{
- dSP;
+ djSP;
HV *hv;
dPOPPOPssrl;
HV* stash;
GV *gv;
- BINOP myop;
SV *sv;
- bool oldmustcatch = mustcatch;
hv = (HV*)POPs;
DIE("No dbm on this machine");
}
- Zero(&myop, 1, BINOP);
- myop.op_last = (OP *) &myop;
- myop.op_next = Nullop;
- myop.op_flags = OPf_KNOW|OPf_STACKED;
- mustcatch = 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;
}
- mustcatch = oldmustcatch;
- 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;
#endif
}
- nfound = select(
+ nfound = PerlSock_select(
maxlen * 8,
(Select_fd_set_t) fd_sets[1],
(Select_fd_set_t) fd_sets[2],
}
void
-setdefout(gv)
-GV *gv;
+setdefout(GV *gv)
{
+ dTHR;
if (gv)
(void)SvREFCNT_inc(gv);
if (defoutgv)
PP(pp_select)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *newdefout, *egv;
HV *hv;
- newdefout = (op->op_private > 0) ? ((GV *) POPs) : NULL;
+ newdefout = (op->op_private > 0) ? ((GV *) POPs) : (GV *) NULL;
egv = GvEGV(defoutgv);
if (!egv)
PP(pp_getc)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *gv;
+ MAGIC *mg;
if (MAXARG <= 0)
gv = stdingv;
gv = (GV*)POPs;
if (!gv)
gv = argvgv;
+
+ if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
+ I32 gimme = GIMME_V;
+ PUSHMARK(SP);
+ XPUSHs(mg->mg_obj);
+ PUTBACK;
+ ENTER;
+ perl_call_method("GETC", gimme);
+ LEAVE;
+ SPAGAIN;
+ if (gimme == G_SCALAR)
+ SvSetMagicSV_nosteal(TARG, TOPs);
+ RETURN;
+ }
if (!gv || do_eof(gv)) /* make sure we have fp with something */
RETPUSHUNDEF;
TAINT;
}
static OP *
-doform(cv,gv,retop)
-CV *cv;
-GV *gv;
-OP *retop;
+doform(CV *cv, GV *gv, OP *retop)
{
- register CONTEXT *cx;
- I32 gimme = GIMME;
+ dTHR;
+ register PERL_CONTEXT *cx;
+ I32 gimme = GIMME_V;
AV* padlist = CvPADLIST(cv);
SV** svp = AvARRAY(padlist);
PP(pp_enterwrite)
{
- dSP;
+ djSP;
register GV *gv;
register IO *io;
GV *fgv;
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)));
CV *cv;
if (!IoTOP_GV(io)) {
GV *topgv;
- char tmpbuf[256];
+ SV *topname;
if (!IoTOP_NAME(io)) {
if (!IoFMT_NAME(io))
IoFMT_NAME(io) = savepv(GvNAME(gv));
- sprintf(tmpbuf, "%s_TOP", IoFMT_NAME(io));
- topgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVFM);
+ topname = sv_2mortal(newSVpvf("%s_TOP", IoFMT_NAME(io)));
+ topgv = gv_fetchpv(SvPVX(topname), FALSE, SVt_PVFM);
if ((topgv && GvFORM(topgv)) ||
!gv_fetchpv("top",FALSE,SVt_PVFM))
- IoTOP_NAME(io) = savepv(tmpbuf);
+ IoTOP_NAME(io) = savepv(SvPVX(topname));
else
IoTOP_NAME(io) = savepv("top");
}
PP(pp_prtf)
{
- dSP; dMARK; dORIGMARK;
+ djSP; dMARK; dORIGMARK;
GV *gv;
IO *io;
PerlIO *fp;
- SV *sv = NEWSV(0,0);
+ SV *sv;
+ MAGIC *mg;
if (op->op_flags & OPf_STACKED)
gv = (GV*)*++MARK;
else
gv = defoutgv;
+
+ if (SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q'))) {
+ if (MARK == ORIGMARK) {
+ MEXTEND(SP, 1);
+ ++MARK;
+ Move(MARK, MARK + 1, (SP - MARK) + 1, SV*);
+ ++SP;
+ }
+ PUSHMARK(MARK - 1);
+ *MARK = mg->mg_obj;
+ PUTBACK;
+ ENTER;
+ perl_call_method("PRINTF", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ MARK = ORIGMARK + 1;
+ *MARK = *SP;
+ SP = MARK;
+ RETURN;
+ }
+
+ sv = NEWSV(0,0);
if (!(io = GvIO(gv))) {
if (dowarn) {
gv_fullname3(sv, gv, Nullch);
PP(pp_sysopen)
{
- dSP;
+ djSP;
GV *gv;
SV *sv;
char *tmps;
PP(pp_sysread)
{
- dSP; dMARK; dORIGMARK; dTARGET;
+ djSP; dMARK; dORIGMARK; dTARGET;
int offset;
GV *gv;
IO *io;
char *buffer;
- int length;
+ SSize_t length;
Sock_size_t bufsize;
SV *bufsv;
STRLEN blen;
+ MAGIC *mg;
gv = (GV*)*++MARK;
+ if ((op->op_type == OP_READ || op->op_type == OP_SYSREAD) &&
+ SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q')))
+ {
+ SV *sv;
+
+ PUSHMARK(MARK-1);
+ *MARK = mg->mg_obj;
+ ENTER;
+ perl_call_method("READ", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ sv = POPs;
+ SP = ORIGMARK;
+ PUSHs(sv);
+ RETURN;
+ }
+
if (!gv)
goto say_undef;
bufsv = *++MARK;
goto say_undef;
#ifdef HAS_SOCKET
if (op->op_type == OP_RECV) {
- bufsize = sizeof buf;
+ char namebuf[MAXPATHLEN];
+#if defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)
+ 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,
- (struct sockaddr *)buf, &bufsize);
+ length = PerlSock_recvfrom(PerlIO_fileno(IoIFP(io)), buffer, length, offset,
+ (struct sockaddr *)namebuf, &bufsize);
if (length < 0)
RETPUSHUNDEF;
SvCUR_set(bufsv, length);
if (!(IoFLAGS(io) & IOf_UNTAINT))
SvTAINTED_on(bufsv);
SP = ORIGMARK;
- sv_setpvn(TARG, buf, bufsize);
+ sv_setpvn(TARG, namebuf, bufsize);
PUSHs(TARG);
RETURN;
}
Zero(buffer+bufsize, offset-bufsize, char);
}
if (op->op_type == OP_SYSREAD) {
- length = read(PerlIO_fileno(IoIFP(io)), buffer+offset, length);
+ length = PerlLIO_read(PerlIO_fileno(IoIFP(io)), buffer+offset, length);
}
else
#ifdef HAS_SOCKET__bad_code_maybe
if (IoTYPE(io) == 's') {
- bufsize = sizeof buf;
- length = recvfrom(PerlIO_fileno(IoIFP(io)), buffer+offset, length, 0,
- (struct sockaddr *)buf, &bufsize);
+ char namebuf[MAXPATHLEN];
+#if defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)
+ bufsize = sizeof (struct sockaddr_in);
+#else
+ bufsize = sizeof namebuf;
+#endif
+ length = PerlSock_recvfrom(PerlIO_fileno(IoIFP(io)), buffer+offset, length, 0,
+ (struct sockaddr *)namebuf, &bufsize);
}
else
#endif
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 (op->op_type == OP_SYSWRITE &&
+ SvRMAGICAL(gv) && (mg = mg_find((SV*)gv, 'q')))
+ {
+ SV *sv;
+
+ PUSHMARK(MARK-1);
+ *MARK = mg->mg_obj;
+ ENTER;
+ perl_call_method("WRITE", G_SCALAR);
+ LEAVE;
+ SPAGAIN;
+ sv = POPs;
+ SP = ORIGMARK;
+ PUSHs(sv);
+ RETURN;
+ }
if (!gv)
goto say_undef;
bufsv = *++MARK;
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);
+ 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");
PP(pp_eof)
{
- dSP;
+ djSP;
GV *gv;
if (MAXARG <= 0)
gv = last_in_gv;
else
gv = last_in_gv = (GV*)POPs;
- PUSHs(!gv || do_eof(gv) ? &sv_yes : &sv_no);
+ PUSHs(boolSV(!gv || do_eof(gv)));
RETURN;
}
PP(pp_tell)
{
- dSP; dTARGET;
+ djSP; dTARGET;
GV *gv;
if (MAXARG <= 0)
PP(pp_seek)
{
- dSP;
+ return pp_sysseek(ARGS);
+}
+
+PP(pp_sysseek)
+{
+ djSP;
GV *gv;
int whence = POPi;
long offset = POPl;
gv = last_in_gv = (GV*)POPs;
- PUSHs( do_seek(gv, offset, whence) ? &sv_yes : &sv_no );
+ if (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
+ : sv_2mortal(n ? newSViv((IV)n)
+ : newSVpv(zero_but_true, ZBTLEN)));
+ }
RETURN;
}
PP(pp_truncate)
{
- dSP;
+ djSP;
Off_t len = (Off_t)POPn;
int result = 1;
GV *tmpgv;
#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;
char *s;
- int retval;
+ IV retval;
GV *gv = (GV*)POPs;
IO *io = GvIOn(gv);
if (SvPOK(argsv) || !SvNIOK(argsv)) {
STRLEN len;
+ STRLEN need;
s = SvPV_force(argsv, len);
- retval = IOCPARM_LEN(func);
- if (len < retval) {
- s = Sv_Grow(argsv, retval+1);
- SvCUR_set(argsv, retval);
+ need = IOCPARM_LEN(func);
+ if (len < need) {
+ s = Sv_Grow(argsv, need + 1);
+ SvCUR_set(argsv, need);
}
s[SvCUR(argsv)] = 17; /* a little sanity check here */
}
else {
retval = SvIV(argsv);
-#ifdef DOSISH
- s = (char*)(long)retval; /* ouch */
-#else
s = (char*)retval; /* ouch */
-#endif
}
TAINT_PROPER(optype == OP_IOCTL ? "ioctl" : "fcntl");
PUSHi(retval);
}
else {
- PUSHp("0 but true", 10);
+ PUSHp(zero_but_true, ZBTLEN);
}
RETURN;
}
PP(pp_flock)
{
- dSP; dTARGET;
+ djSP; dTARGET;
I32 value;
int argtype;
GV *gv;
else
fp = Nullfp;
if (fp) {
+ (void)PerlIO_flush(fp);
value = (I32)(FLOCK(PerlIO_fileno(fp), argtype) >= 0);
}
else
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;
}
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;
}
PP(pp_bind)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
SV *addrsv = POPs;
char *addr;
addr = SvPV(addrsv, len);
TAINT_PROPER("bind");
- if (bind(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
+ if (PerlSock_bind(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
RETPUSHYES;
else
RETPUSHUNDEF;
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;
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;
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;
}
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:
PP(pp_ssockopt)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
int optype = op->op_type;
SV *sv;
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';
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);
}
PP(pp_getpeername)
{
- dSP;
+ djSP;
#ifdef HAS_SOCKET
int optype = op->op_type;
SV *sv;
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
PP(pp_stat)
{
- dSP;
+ djSP;
GV *tmpgv;
+ I32 gimme;
I32 max = 13;
if (op->op_flags & OPf_REF) {
statgv = tmpgv;
sv_setpv(statname, "");
laststatval = (GvIO(tmpgv) && IoIFP(GvIOp(tmpgv))
- ? Fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &statcache) : -1);
+ ? PerlLIO_fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &statcache) : -1);
}
if (laststatval < 0)
max = 0;
#ifdef HAS_LSTAT
laststype = op->op_type;
if (op->op_type == OP_LSTAT)
- laststatval = lstat(SvPV(statname, na), &statcache);
+ laststatval = PerlLIO_lstat(SvPV(statname, na), &statcache);
else
#endif
- laststatval = Stat(SvPV(statname, na), &statcache);
+ laststatval = PerlLIO_stat(SvPV(statname, na), &statcache);
if (laststatval < 0) {
if (dowarn && strchr(SvPV(statname, na), '\n'))
warn(warn_nl, "stat");
}
}
- if (GIMME != G_ARRAY) {
- EXTEND(SP, 1);
- if (max)
- RETPUSHYES;
- else
- RETPUSHUNDEF;
+ gimme = GIMME_V;
+ if (gimme != G_ARRAY) {
+ if (gimme != G_VOID)
+ XPUSHs(boolSV(max));
+ RETURN;
}
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)));
PP(pp_ftrread)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (cando(S_IRUSR, 0, &statcache))
PP(pp_ftrwrite)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (cando(S_IWUSR, 0, &statcache))
PP(pp_ftrexec)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (cando(S_IXUSR, 0, &statcache))
PP(pp_fteread)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (cando(S_IRUSR, 1, &statcache))
PP(pp_ftewrite)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (cando(S_IWUSR, 1, &statcache))
PP(pp_fteexec)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (cando(S_IXUSR, 1, &statcache))
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) )
PP(pp_ftzero)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (!statcache.st_size)
PP(pp_ftsize)
{
I32 result = my_stat(ARGS);
- dSP; dTARGET;
+ djSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
PUSHi(statcache.st_size);
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 );
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 );
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 );
PP(pp_ftsock)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (S_ISSOCK(statcache.st_mode))
PP(pp_ftchr)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (S_ISCHR(statcache.st_mode))
PP(pp_ftblk)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (S_ISBLK(statcache.st_mode))
PP(pp_ftfile)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (S_ISREG(statcache.st_mode))
PP(pp_ftdir)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (S_ISDIR(statcache.st_mode))
PP(pp_ftpipe)
{
I32 result = my_stat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (S_ISFIFO(statcache.st_mode))
PP(pp_ftlink)
{
I32 result = my_lstat(ARGS);
- dSP;
+ djSP;
if (result < 0)
RETPUSHUNDEF;
if (S_ISLNK(statcache.st_mode))
PP(pp_ftsuid)
{
- dSP;
+ djSP;
#ifdef S_ISUID
I32 result = my_stat(ARGS);
SPAGAIN;
PP(pp_ftsgid)
{
- dSP;
+ djSP;
#ifdef S_ISGID
I32 result = my_stat(ARGS);
SPAGAIN;
PP(pp_ftsvtx)
{
- dSP;
+ djSP;
#ifdef S_ISVTX
I32 result = my_stat(ARGS);
SPAGAIN;
PP(pp_fttty)
{
- dSP;
+ djSP;
int fd;
GV *gv;
- char *tmps;
- if (op->op_flags & OPf_REF) {
+ char *tmps = Nullch;
+
+ if (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);
+
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;
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);
+ laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &statcache);
if (laststatval < 0)
RETPUSHUNDEF;
if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */
laststatval = -1;
sv_setpv(statname, SvPV(sv, na));
#ifdef HAS_OPEN3
- i = open(SvPV(sv, na), O_RDONLY, 0);
+ i = PerlLIO_open3(SvPV(sv, na), O_RDONLY, 0);
#else
- i = open(SvPV(sv, na), 0);
+ i = PerlLIO_open(SvPV(sv, na), 0);
#endif
if (i < 0) {
if (dowarn && strchr(SvPV(sv, na), '\n'))
warn(warn_nl, "open");
RETPUSHUNDEF;
}
- laststatval = Fstat(i, &statcache);
+ laststatval = PerlLIO_fstat(i, &statcache);
if (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)
RETPUSHNO; /* special case NFS directories */
PP(pp_chdir)
{
- dSP; dTARGET;
+ djSP; dTARGET;
char *tmps;
SV **svp;
tmps = SvPV(*svp, na);
}
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. */
PP(pp_chown)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
#ifdef HAS_CHOWN
value = (I32)apply(op->op_type, MARK, SP);
PP(pp_chroot)
{
- dSP; dTARGET;
+ djSP; dTARGET;
char *tmps;
#ifdef HAS_CHROOT
tmps = POPp;
PP(pp_unlink)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
value = (I32)apply(op->op_type, MARK, SP);
SP = MARK;
PP(pp_chmod)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
value = (I32)apply(op->op_type, MARK, SP);
SP = MARK;
PP(pp_utime)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
value = (I32)apply(op->op_type, MARK, SP);
SP = MARK;
PP(pp_rename)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int anum;
char *tmps2 = POPp;
#ifdef HAS_RENAME
anum = rename(tmps, tmps2);
#else
- if (!(anum = Stat(tmps, &statbuf))) {
+ if (!(anum = PerlLIO_stat(tmps, &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 (euid || PerlLIO_stat(tmps2, &statbuf) < 0 || !S_ISDIR(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);
PP(pp_symlink)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_SYMLINK
char *tmps2 = POPp;
char *tmps = SvPV(TOPs, na);
PP(pp_readlink)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_SYMLINK
char *tmps;
+ char buf[MAXPATHLEN];
int len;
+
+#ifndef INCOMPLETE_TAINTS
+ TAINT;
+#endif
tmps = POPp;
len = readlink(tmps, buf, sizeof buf);
EXTEND(SP, 1);
*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' ?? */
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);
+ anum = (PerlLIO_stat(save_filename, &statbuf) >= 0);
if (op->op_type == OP_RMDIR)
anum = !anum;
if (anum)
PP(pp_mkdir)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int mode = POPi;
#ifndef HAS_MKDIR
int oldumask;
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;
tmps = POPp;
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;
GV *gv = (GV*)POPs;
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;
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 = newSVpv(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 = newSVpv(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;
PP(pp_telldir)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#if defined(HAS_TELLDIR) || defined(telldir)
-#if !defined(telldir) && !defined(HAS_TELLDIR_PROTOTYPE)
+# ifdef NEED_TELLDIR_PROTO /* XXX does _anyone_ need this? --AD 2/20/1998 */
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)
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:
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)
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;
}
PP(pp_fork)
{
#ifdef HAS_FORK
- dSP; dTARGET;
+ djSP; dTARGET;
int childpid;
GV *tmpgv;
PP(pp_wait)
{
-#if !defined(DOSISH) || defined(OS2)
- dSP; dTARGET;
+#if !defined(DOSISH) || defined(OS2) || defined(WIN32)
+ djSP; dTARGET;
int childpid;
int argflags;
PP(pp_waitpid)
{
-#if !defined(DOSISH) || defined(OS2)
- dSP; dTARGET;
+#if !defined(DOSISH) || defined(OS2) || defined(WIN32)
+ djSP; dTARGET;
int childpid;
int optype;
int argflags;
SETi(childpid);
RETURN;
#else
- DIE(no_func, "Unsupported function wait");
+ DIE(no_func, "Unsupported function waitpid");
#endif
}
PP(pp_system)
{
- dSP; dMARK; dORIGMARK; dTARGET;
+ djSP; dMARK; dORIGMARK; dTARGET;
I32 value;
int childpid;
int result;
else {
value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
}
- _exit(-1);
+ PerlProc__exit(-1);
#else /* ! FORK or VMS or OS/2 */
if (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));
}
PP(pp_exec)
{
- dSP; dMARK; dORIGMARK; dTARGET;
+ djSP; dMARK; dORIGMARK; dTARGET;
I32 value;
if (op->op_flags & OPf_STACKED) {
PP(pp_kill)
{
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value;
#ifdef HAS_KILL
value = (I32)apply(op->op_type, MARK, SP);
PP(pp_getppid)
{
#ifdef HAS_GETPPID
- dSP; dTARGET;
+ djSP; dTARGET;
XPUSHi( getppid() );
RETURN;
#else
PP(pp_getpgrp)
{
#ifdef HAS_GETPGRP
- dSP; dTARGET;
+ djSP; dTARGET;
int pid;
I32 value;
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 */
PP(pp_getpriority)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int which;
int who;
#ifdef HAS_GETPRIORITY
PP(pp_setpriority)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int which;
int who;
int niceval;
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");
PP(pp_gmtime)
{
- dSP;
+ djSP;
Time_t when;
struct tm *tmbuf;
static char *dayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
EXTEND_MORTAL(9);
if (GIMME != G_ARRAY) {
dTARGET;
- char mybuf[30];
+ SV *tsv;
if (!tmbuf)
RETPUSHUNDEF;
- sprintf(mybuf, "%s %s %2d %02d:%02d:%02d %d",
- dayname[tmbuf->tm_wday],
- monname[tmbuf->tm_mon],
- tmbuf->tm_mday,
- tmbuf->tm_hour,
- tmbuf->tm_min,
- tmbuf->tm_sec,
- tmbuf->tm_year + 1900);
- PUSHp(mybuf, strlen(mybuf));
+ tsv = newSVpvf("%s %s %2d %02d:%02d:%02d %d",
+ dayname[tmbuf->tm_wday],
+ monname[tmbuf->tm_mon],
+ tmbuf->tm_mday,
+ tmbuf->tm_hour,
+ tmbuf->tm_min,
+ tmbuf->tm_sec,
+ tmbuf->tm_year + 1900);
+ PUSHs(sv_2mortal(tsv));
}
else if (tmbuf) {
PUSHs(sv_2mortal(newSViv((I32)tmbuf->tm_sec)));
PP(pp_alarm)
{
- dSP; dTARGET;
+ djSP; dTARGET;
int anum;
#ifdef HAS_ALARM
anum = POPi;
PP(pp_sleep)
{
- dSP; dTARGET;
+ djSP; dTARGET;
I32 duration;
Time_t lasttime;
Time_t when;
PP(pp_shmwrite)
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
I32 value = (I32)(do_shmio(op->op_type, MARK, SP) >= 0);
SP = MARK;
PUSHi(value);
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;
+ djSP; dMARK; dTARGET;
int anum = do_ipcget(op->op_type, MARK, SP);
SP = MARK;
if (anum == -1)
PP(pp_semctl)
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
- dSP; dMARK; dTARGET;
+ djSP; dMARK; dTARGET;
int anum = do_ipcctl(op->op_type, MARK, SP);
SP = MARK;
if (anum == -1)
PUSHi(anum);
}
else {
- PUSHp("0 but true",10);
+ PUSHp(zero_but_true, ZBTLEN);
}
RETURN;
#else
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");
PP(pp_ghbyaddr)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETHOSTBYADDR
return pp_ghostent(ARGS);
#else
DIE(no_sock_func, "gethostbyaddr");
PP(pp_ghostent)
{
- dSP;
-#ifdef HAS_SOCKET
+ djSP;
+#if defined(HAS_GETHOSTBYNAME) || defined(HAS_GETHOSTBYADDR) || defined(HAS_GETHOSTENT)
I32 which = 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;
EXTEND(SP, 10);
- if (which == OP_GHBYNAME) {
- hent = gethostbyname(POPp);
- }
+ if (which == OP_GHBYNAME)
+#ifdef HAS_GETHOSTBYNAME
+ hent = PerlSock_gethostbyname(POPp);
+#else
+ DIE(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(no_sock_func, "gethostbyaddr");
+#endif
}
else
#ifdef HAS_GETHOSTENT
- hent = gethostent();
+ hent = PerlSock_gethostent();
#else
- DIE("gethostent not implemented");
+ DIE(no_sock_func, "gethostent");
#endif
#ifdef HOST_NOT_FOUND
PP(pp_gnbyname)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETNETBYNAME
return pp_gnetent(ARGS);
#else
DIE(no_sock_func, "getnetbyname");
PP(pp_gnbyaddr)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETNETBYADDR
return pp_gnetent(ARGS);
#else
DIE(no_sock_func, "getnetbyaddr");
PP(pp_gnetent)
{
- dSP;
-#ifdef HAS_SOCKET
+ djSP;
+#if defined(HAS_GETNETBYNAME) || defined(HAS_GETNETBYADDR) || defined(HAS_GETNETENT)
I32 which = 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;
if (which == OP_GNBYNAME)
- nent = getnetbyname(POPp);
+#ifdef HAS_GETNETBYNAME
+ nent = PerlSock_getnetbyname(POPp);
+#else
+ DIE(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(no_sock_func, "getnetbyaddr");
+#endif
}
else
- nent = getnetent();
+#ifdef HAS_GETNETENT
+ nent = PerlSock_getnetent();
+#else
+ DIE(no_sock_func, "getnetent");
+#endif
EXTEND(SP, 4);
if (GIMME != G_ARRAY) {
PUSHs(sv = sv_mortalcopy(&sv_no));
sv_setpv(sv, nent->n_name);
PUSHs(sv = sv_mortalcopy(&sv_no));
- for (elem = nent->n_aliases; *elem; elem++) {
+ for (elem = nent->n_aliases; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
PP(pp_gpbyname)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETPROTOBYNAME
return pp_gprotoent(ARGS);
#else
DIE(no_sock_func, "getprotobyname");
PP(pp_gpbynumber)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETPROTOBYNUMBER
return pp_gprotoent(ARGS);
#else
DIE(no_sock_func, "getprotobynumber");
PP(pp_gprotoent)
{
- dSP;
-#ifdef HAS_SOCKET
+ djSP;
+#if defined(HAS_GETPROTOBYNAME) || defined(HAS_GETPROTOBYNUMBER) || defined(HAS_GETPROTOENT)
I32 which = 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;
if (which == OP_GPBYNAME)
- pent = getprotobyname(POPp);
+#ifdef HAS_GETPROTOBYNAME
+ pent = PerlSock_getprotobyname(POPp);
+#else
+ DIE(no_sock_func, "getprotobyname");
+#endif
else if (which == OP_GPBYNUMBER)
- pent = getprotobynumber(POPi);
+#ifdef HAS_GETPROTOBYNUMBER
+ pent = PerlSock_getprotobynumber(POPi);
+#else
+ DIE(no_sock_func, "getprotobynumber");
+#endif
else
- pent = getprotoent();
+#ifdef HAS_GETPROTOENT
+ pent = PerlSock_getprotoent();
+#else
+ DIE(no_sock_func, "getprotoent");
+#endif
EXTEND(SP, 3);
if (GIMME != G_ARRAY) {
PUSHs(sv = sv_mortalcopy(&sv_no));
sv_setpv(sv, pent->p_name);
PUSHs(sv = sv_mortalcopy(&sv_no));
- for (elem = pent->p_aliases; *elem; elem++) {
+ for (elem = pent->p_aliases; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
PP(pp_gsbyname)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETSERVBYNAME
return pp_gservent(ARGS);
#else
DIE(no_sock_func, "getservbyname");
PP(pp_gsbyport)
{
-#ifdef HAS_SOCKET
+#ifdef HAS_GETSERVBYPORT
return pp_gservent(ARGS);
#else
DIE(no_sock_func, "getservbyport");
PP(pp_gservent)
{
- dSP;
-#ifdef HAS_SOCKET
+ djSP;
+#if defined(HAS_GETSERVBYNAME) || defined(HAS_GETSERVBYPORT) || defined(HAS_GETSERVENT)
I32 which = 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;
if (which == OP_GSBYNAME) {
+#ifdef HAS_GETSERVBYNAME
char *proto = POPp;
char *name = POPp;
if (proto && !*proto)
proto = Nullch;
- sent = getservbyname(name, proto);
+ sent = PerlSock_getservbyname(name, proto);
+#else
+ DIE(no_sock_func, "getservbyname");
+#endif
}
else if (which == OP_GSBYPORT) {
+#ifdef HAS_GETSERVBYPORT
char *proto = POPp;
unsigned short port = POPu;
#ifdef HAS_HTONS
- port = htons(port);
+ port = PerlSock_htons(port);
+#endif
+ sent = PerlSock_getservbyport(port, proto);
+#else
+ DIE(no_sock_func, "getservbyport");
#endif
- sent = getservbyport(port, proto);
}
else
- sent = getservent();
+#ifdef HAS_GETSERVENT
+ sent = PerlSock_getservent();
+#else
+ DIE(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
PUSHs(sv = sv_mortalcopy(&sv_no));
sv_setpv(sv, sent->s_name);
PUSHs(sv = sv_mortalcopy(&sv_no));
- for (elem = sent->s_aliases; *elem; elem++) {
+ for (elem = sent->s_aliases; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
PP(pp_shostent)
{
- dSP;
-#ifdef HAS_SOCKET
+ djSP;
+#ifdef HAS_SETHOSTENT
sethostent(TOPi);
RETSETYES;
#else
PP(pp_snetent)
{
- dSP;
-#ifdef HAS_SOCKET
+ djSP;
+#ifdef HAS_SETNETENT
setnetent(TOPi);
RETSETYES;
#else
PP(pp_sprotoent)
{
- dSP;
-#ifdef HAS_SOCKET
+ djSP;
+#ifdef HAS_SETPROTOENT
setprotoent(TOPi);
RETSETYES;
#else
PP(pp_sservent)
{
- dSP;
-#ifdef HAS_SOCKET
+ djSP;
+#ifdef HAS_SETSERVENT
setservent(TOPi);
RETSETYES;
#else
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");
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");
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");
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");
PP(pp_gpwent)
{
- dSP;
+ djSP;
#ifdef HAS_PASSWD
I32 which = op->op_type;
register SV *sv;
#endif
PUSHs(sv = sv_mortalcopy(&sv_no));
sv_setpv(sv, pwent->pw_gecos);
+#ifndef INCOMPLETE_TAINTS
+ SvTAINTED_on(sv);
+#endif
PUSHs(sv = sv_mortalcopy(&sv_no));
sv_setpv(sv, pwent->pw_dir);
PUSHs(sv = sv_mortalcopy(&sv_no));
PP(pp_spwent)
{
- dSP;
-#ifdef HAS_PASSWD
+ djSP;
+#if defined(HAS_PASSWD) && !defined(CYGWIN32)
setpwent();
RETPUSHYES;
#else
PP(pp_epwent)
{
- dSP;
+ djSP;
#ifdef HAS_PASSWD
endpwent();
RETPUSHYES;
PP(pp_ggrent)
{
- dSP;
+ djSP;
#ifdef HAS_GROUP
I32 which = op->op_type;
register char **elem;
PUSHs(sv = sv_mortalcopy(&sv_no));
sv_setiv(sv, (IV)grent->gr_gid);
PUSHs(sv = sv_mortalcopy(&sv_no));
- for (elem = grent->gr_mem; *elem; elem++) {
+ for (elem = grent->gr_mem; elem && *elem; elem++) {
sv_catpv(sv, *elem);
if (elem[1])
sv_catpvn(sv, " ", 1);
PP(pp_sgrent)
{
- dSP;
+ djSP;
#ifdef HAS_GROUP
setgrent();
RETPUSHYES;
PP(pp_egrent)
{
- dSP;
+ djSP;
#ifdef HAS_GROUP
endgrent();
RETPUSHYES;
PP(pp_getlogin)
{
- dSP; dTARGET;
+ djSP; dTARGET;
#ifdef HAS_GETLOGIN
char *tmps;
EXTEND(SP, 1);
PP(pp_syscall)
{
-#ifdef HAS_SYSCALL
- dSP; dMARK; dORIGMARK; dTARGET;
+#ifdef HAS_SYSCALL
+ djSP; dMARK; dORIGMARK; dTARGET;
register I32 items = SP - MARK;
unsigned long a[20];
register I32 i = 0;
*/
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);
}
#endif /* LOCKF_EMULATE_FLOCK */
+