#include "EXTERN.h"
#include "perl.h"
-/* Omit this -- it causes too much grief on mixed systems.
-#ifdef I_UNISTD
-#include <unistd.h>
+/* XXX Omit this -- it causes too much grief on mixed systems.
+ Next time, I should force broken systems to unset i_unistd in
+ hint files.
+*/
+#if 0
+# ifdef I_UNISTD
+# include <unistd.h>
+# endif
#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 <sys/file.h>
#endif
-#ifdef HAS_GETPGRP2
-# define getpgrp getpgrp2
-#endif
-
-#ifdef HAS_SETPGRP2
-# define setpgrp setpgrp2
-#endif
-
#if !defined(HAS_MKDIR) || !defined(HAS_RMDIR)
static int dooneliner _((char *cmd, char *filename));
#endif
}
}
}
- statusvalue = my_pclose(fp);
+ statusvalue = FIXSTATUS(my_pclose(fp));
}
else {
statusvalue = -1;
{
OP *result;
ENTER;
- SAVEINT(rschar);
- SAVEINT(rslen);
SAVESPTR(last_in_gv); /* We don't want this to be permanent. */
last_in_gv = (GV*)*stack_sp--;
- rslen = 1;
-#ifdef DOSISH
- rschar = 0;
-#else
-#ifdef CSH
- rschar = 0;
-#else
- rschar = '\n';
+ SAVESPTR(rs); /* This is not permanent, either. */
+ rs = sv_2mortal(newSVpv("", 1));
+#ifndef DOSISH
+#ifndef CSH
+ *SvPVX(rs) = '\n';
#endif /* !CSH */
#endif /* !MSDOS */
+
result = do_readline();
LEAVE;
return result;
tmps = SvPV(TOPs, na);
}
if (!tmps || !*tmps) {
- SV *error = GvSV(gv_fetchpv("@", TRUE, SVt_PV));
+ SV *error = GvSV(errgv);
(void)SvUPGRADE(error, SVt_PV);
if (SvPOK(error) && SvCUR(error))
sv_catpv(error, "\t...caught");
tmps = SvPV(TOPs, na);
}
if (!tmps || !*tmps) {
- SV *error = GvSV(gv_fetchpv("@", TRUE, SVt_PV));
+ SV *error = GvSV(errgv);
(void)SvUPGRADE(error, SVt_PV);
if (SvPOK(error) && SvCUR(error))
sv_catpv(error, "\t...propagated");
if (MAXARG > 1)
sv = POPs;
- else
+ else if (SvTYPE(TOPs) == SVt_PVGV)
sv = GvSV(TOPs);
+ else
+ DIE(no_usym, "filehandle");
gv = (GV*)POPs;
tmps = SvPV(sv, len);
- if (do_open(gv, tmps, len,Nullfp)) {
+ if (do_open(gv, tmps, len, FALSE, 0, 0, Nullfp)) {
IoLINES(GvIOp(gv)) = 0;
PUSHi( (I32)forkprocess );
}
if (!rgv || !wgv)
goto badexit;
+ if (SvTYPE(rgv) != SVt_PVGV || SvTYPE(wgv) != SVt_PVGV)
+ DIE(no_usym, "filehandle");
rstio = GvIOn(rgv);
wstio = GvIOn(wgv);
#ifdef DOSISH
#ifdef atarist
- if (!fflush(fp) && (fp->_flag |= _IOBIN))
+ if (!Fflush(fp) && (fp->_flag |= _IOBIN))
RETPUSHYES;
else
RETPUSHUNDEF;
PUTBACK;
if (op = pp_entersub())
- run();
+ runops();
SPAGAIN;
sv = TOPs;
RETSETYES;
}
+PP(pp_tied)
+{
+ dSP;
+ SV * sv ;
+ 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 ;
+ }
+ }
+
+ RETPUSHUNDEF;
+}
+
PP(pp_dbmopen)
{
dSP;
stash = gv_stashsv(sv, FALSE);
if (!stash || !(gv = gv_fetchmethod(stash, "TIEHASH")) || !GvCV(gv)) {
PUTBACK;
- perl_requirepv("AnyDBM_File.pm");
+ perl_require_pv("AnyDBM_File.pm");
SPAGAIN;
if (!(gv = gv_fetchmethod(stash, "TIEHASH")) || !GvCV(gv))
DIE("No dbm on this machine");
PUTBACK;
if (op = pp_entersub())
- run();
+ runops();
SPAGAIN;
if (!sv_isobject(TOPs)) {
PUTBACK;
if (op = pp_entersub())
- run();
+ runops();
SPAGAIN;
}
}
#if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
+#ifdef __linux__
+ growsize = sizeof(fd_set);
+#else
growsize = maxlen; /* little endians can use vecs directly */
+#endif
#else
#ifdef NFDBITS
j = SvLEN(sv);
if (j < growsize) {
Sv_Grow(sv, growsize);
- s = SvPVX(sv) + j;
- while (++j <= growsize) {
- *s++ = '\0';
- }
}
+ j = SvCUR(sv);
+ s = SvPVX(sv) + j;
+ while (++j <= growsize) {
+ *s++ = '\0';
+ }
+
#if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
s = SvPVX(sv);
New(403, fd_sets[i], growsize, char);
#endif
}
+void
+setdefout(gv)
+GV *gv;
+{
+ if (gv)
+ (void)SvREFCNT_inc(gv);
+ if (defoutgv)
+ SvREFCNT_dec(defoutgv);
+ defoutgv = gv;
+}
+
PP(pp_select)
{
dSP; dTARGET;
- GV *oldgv = defoutgv;
- if (op->op_private > 0) {
- defoutgv = (GV*)POPs;
- if (!GvIO(defoutgv))
- gv_IOadd(defoutgv);
+ GV *newdefout, *egv;
+ HV *hv;
+
+ newdefout = (op->op_private > 0) ? ((GV *) POPs) : NULL;
+
+ egv = GvEGV(defoutgv);
+ if (!egv)
+ egv = defoutgv;
+ hv = GvSTASH(egv);
+ if (! hv)
+ XPUSHs(&sv_undef);
+ else {
+ GV **gvp = hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE);
+ if (gvp && *gvp == egv)
+ gv_efullname(TARG, defoutgv);
+ else
+ sv_setsv(TARG, sv_2mortal(newRV(egv)));
+ XPUSHTARG;
+ }
+
+ if (newdefout) {
+ if (!GvIO(newdefout))
+ gv_IOadd(newdefout);
+ setdefout(newdefout);
}
- gv_efullname(TARG, oldgv);
- XPUSHTARG;
+
RETURN;
}
SAVESPTR(curpad);
curpad = AvARRAY((AV*)svp[1]);
- defoutgv = gv; /* locally select filehandle so $% et al work */
+ setdefout(gv); /* locally select filehandle so $% et al work */
return CvSTART(cv);
}
if (!cv) {
if (fgv) {
- SV *tmpstr = sv_newmortal();
- gv_efullname(tmpstr, gv);
- DIE("Undefined format \"%s\" called",SvPVX(tmpstr));
+ SV *tmpsv = sv_newmortal();
+ gv_efullname(tmpsv, gv);
+ DIE("Undefined format \"%s\" called",SvPVX(tmpsv));
}
DIE("Not a format reference");
}
+ IoFLAGS(io) &= ~IOf_DIDTOP;
return doform(cv,gv,op->op_next);
}
if (IoLINES_LEFT(io) < FmLINES(formtarget) &&
formtarget != toptarget)
{
+ GV *fgv;
+ CV *cv;
if (!IoTOP_GV(io)) {
GV *topgv;
char tmpbuf[256];
IoFMT_NAME(io) = savepv(GvNAME(gv));
sprintf(tmpbuf, "%s_TOP", IoFMT_NAME(io));
topgv = gv_fetchpv(tmpbuf,FALSE, SVt_PVFM);
- if ((topgv && GvFORM(topgv)) ||
+ if ((topgv && GvFORM(topgv)) ||
!gv_fetchpv("top",FALSE,SVt_PVFM))
IoTOP_NAME(io) = savepv(tmpbuf);
else
}
IoTOP_GV(io) = topgv;
}
+ if (IoFLAGS(io) & IOf_DIDTOP) { /* Oh dear. It still doesn't fit. */
+ I32 lines = IoLINES_LEFT(io);
+ char *s = SvPVX(formtarget);
+ if (lines <= 0) /* Yow, header didn't even fit!!! */
+ goto forget_top;
+ while (lines-- > 0) {
+ s = strchr(s, '\n');
+ if (!s)
+ break;
+ s++;
+ }
+ if (s) {
+ fwrite1(SvPVX(formtarget), s - SvPVX(formtarget), 1, ofp);
+ sv_chop(formtarget, s);
+ FmLINES(formtarget) -= IoLINES_LEFT(io);
+ }
+ }
if (IoLINES_LEFT(io) >= 0 && IoPAGE(io) > 0)
fwrite1(SvPVX(formfeed), SvCUR(formfeed), 1, ofp);
IoLINES_LEFT(io) = IoPAGE_LEN(io);
IoPAGE(io)++;
formtarget = toptarget;
- return doform(GvFORM(IoTOP_GV(io)),gv,op);
+ IoFLAGS(io) |= IOf_DIDTOP;
+ fgv = IoTOP_GV(io);
+ if (!fgv)
+ DIE("bad top format reference");
+ cv = GvFORM(fgv);
+ if (!cv) {
+ SV *tmpsv = sv_newmortal();
+ gv_efullname(tmpsv, fgv);
+ DIE("Undefined top format \"%s\" called",SvPVX(tmpsv));
+ }
+ return doform(cv,gv,op);
}
forget_top:
else {
FmLINES(formtarget) = 0;
SvCUR_set(formtarget, 0);
+ *SvEND(formtarget) = '\0';
if (IoFLAGS(io) & IOf_FLUSH)
- (void)fflush(fp);
+ (void)Fflush(fp);
PUSHs(&sv_yes);
}
}
else
gv = defoutgv;
if (!(io = GvIO(gv))) {
- if (dowarn)
- warn("Filehandle %s never opened", GvNAME(gv));
- errno = EBADF;
+ if (dowarn) {
+ gv_fullname(sv,gv);
+ warn("Filehandle %s never opened", SvPV(sv,na));
+ }
+ SETERRNO(EBADF,RMS$_IFI);
goto just_say_no;
}
else if (!(fp = IoOFP(io))) {
if (dowarn) {
+ gv_fullname(sv,gv);
if (IoIFP(io))
- warn("Filehandle %s opened only for input", GvNAME(gv));
+ warn("Filehandle %s opened only for input", SvPV(sv,na));
else
- warn("printf on closed filehandle %s", GvNAME(gv));
+ warn("printf on closed filehandle %s", SvPV(sv,na));
}
- errno = EBADF;
+ SETERRNO(EBADF,IoIFP(io)?RMS$_FAC:RMS$_IFI);
goto just_say_no;
}
else {
goto just_say_no;
if (IoFLAGS(io) & IOf_FLUSH)
- if (fflush(fp) == EOF)
+ if (Fflush(fp) == EOF)
goto just_say_no;
}
SvREFCNT_dec(sv);
RETURN;
}
+PP(pp_sysopen)
+{
+ dSP;
+ GV *gv;
+ SV *sv;
+ char *tmps;
+ STRLEN len;
+ int mode, perm;
+
+ if (MAXARG > 3)
+ perm = POPi;
+ else
+ perm = 0666;
+ mode = POPi;
+ sv = POPs;
+ gv = (GV *)POPs;
+
+ tmps = SvPV(sv, len);
+ if (do_open(gv, tmps, len, TRUE, mode, perm, Nullfp)) {
+ IoLINES(GvIOp(gv)) = 0;
+ PUSHs(&sv_yes);
+ }
+ else {
+ PUSHs(&sv_undef);
+ }
+ RETURN;
+}
+
PP(pp_sysread)
{
dSP; dMARK; dORIGMARK; dTARGET;
char *buffer;
int length;
int bufsize;
- SV *bufstr;
+ SV *bufsv;
STRLEN blen;
gv = (GV*)*++MARK;
if (!gv)
goto say_undef;
- bufstr = *++MARK;
- buffer = SvPV_force(bufstr, blen);
+ bufsv = *++MARK;
+ buffer = SvPV_force(bufsv, blen);
length = SvIVx(*++MARK);
if (length < 0)
DIE("Negative length");
- errno = 0;
+ SETERRNO(0,0);
if (MARK < SP)
offset = SvIVx(*++MARK);
else
#ifdef HAS_SOCKET
if (op->op_type == OP_RECV) {
bufsize = sizeof buf;
- buffer = SvGROW(bufstr, length+1);
+ buffer = SvGROW(bufsv, length+1);
length = recvfrom(fileno(IoIFP(io)), buffer, length, offset,
(struct sockaddr *)buf, &bufsize);
if (length < 0)
RETPUSHUNDEF;
- SvCUR_set(bufstr, length);
- *SvEND(bufstr) = '\0';
- (void)SvPOK_only(bufstr);
- SvSETMAGIC(bufstr);
+ SvCUR_set(bufsv, length);
+ *SvEND(bufsv) = '\0';
+ (void)SvPOK_only(bufsv);
+ SvSETMAGIC(bufsv);
if (tainting)
- sv_magic(bufstr, Nullsv, 't', Nullch, 0);
+ sv_magic(bufsv, Nullsv, 't', Nullch, 0);
SP = ORIGMARK;
sv_setpvn(TARG, buf, bufsize);
PUSHs(TARG);
if (op->op_type == OP_RECV)
DIE(no_sock_func, "recv");
#endif
- buffer = SvGROW(bufstr, length+offset+1);
+ buffer = SvGROW(bufsv, length+offset+1);
if (op->op_type == OP_SYSREAD) {
length = read(fileno(IoIFP(io)), buffer+offset, length);
}
length = fread(buffer+offset, 1, length, IoIFP(io));
if (length < 0)
goto say_undef;
- SvCUR_set(bufstr, length+offset);
- *SvEND(bufstr) = '\0';
- (void)SvPOK_only(bufstr);
- SvSETMAGIC(bufstr);
+ SvCUR_set(bufsv, length+offset);
+ *SvEND(bufsv) = '\0';
+ (void)SvPOK_only(bufsv);
+ SvSETMAGIC(bufsv);
if (tainting)
- sv_magic(bufstr, Nullsv, 't', Nullch, 0);
+ sv_magic(bufsv, Nullsv, 't', Nullch, 0);
SP = ORIGMARK;
PUSHi(length);
RETURN;
GV *gv;
IO *io;
int offset;
- SV *bufstr;
+ SV *bufsv;
char *buffer;
int length;
STRLEN blen;
gv = (GV*)*++MARK;
if (!gv)
goto say_undef;
- bufstr = *++MARK;
- buffer = SvPV(bufstr, blen);
+ bufsv = *++MARK;
+ buffer = SvPV(bufsv, blen);
length = SvIVx(*++MARK);
if (length < 0)
DIE("Negative length");
- errno = 0;
+ SETERRNO(0,0);
io = GvIO(gv);
if (!io || !IoIFP(io)) {
length = -1;
int result = 1;
GV *tmpgv;
- errno = 0;
-#if defined(HAS_TRUNCATE) || defined(HAS_CHSIZE)
+ SETERRNO(0,0);
+#if defined(HAS_TRUNCATE) || defined(HAS_CHSIZE) || defined(F_FREESP)
#ifdef HAS_TRUNCATE
if (op->op_flags & OPf_SPECIAL) {
tmpgv = gv_fetchpv(POPp,FALSE, SVt_PVIO);
if (result)
RETPUSHYES;
if (!errno)
- errno = EBADF;
+ SETERRNO(EBADF,RMS$_IFI);
RETPUSHUNDEF;
#else
DIE("truncate not implemented");
PP(pp_ioctl)
{
dSP; dTARGET;
- SV *argstr = POPs;
+ SV *argsv = POPs;
unsigned int func = U_I(POPn);
int optype = op->op_type;
char *s;
GV *gv = (GV*)POPs;
IO *io = GvIOn(gv);
- if (!io || !argstr || !IoIFP(io)) {
- errno = EBADF; /* well, sort of... */
+ if (!io || !argsv || !IoIFP(io)) {
+ SETERRNO(EBADF,RMS$_IFI); /* well, sort of... */
RETPUSHUNDEF;
}
- if (SvPOK(argstr) || !SvNIOK(argstr)) {
+ if (SvPOK(argsv) || !SvNIOK(argsv)) {
STRLEN len;
- s = SvPV_force(argstr, len);
+ s = SvPV_force(argsv, len);
retval = IOCPARM_LEN(func);
if (len < retval) {
- s = Sv_Grow(argstr, retval+1);
- SvCUR_set(argstr, retval);
+ s = Sv_Grow(argsv, retval+1);
+ SvCUR_set(argsv, retval);
}
- s[SvCUR(argstr)] = 17; /* a little sanity check here */
+ s[SvCUR(argsv)] = 17; /* a little sanity check here */
}
else {
- retval = SvIV(argstr);
+ retval = SvIV(argsv);
#ifdef DOSISH
s = (char*)(long)retval; /* ouch */
#else
DIE("ioctl is not implemented");
#endif
else
-#ifdef DOSISH
+#if defined(DOSISH) && !defined(OS2)
DIE("fcntl is not implemented");
#else
# ifdef HAS_FCNTL
+# if defined(OS2) && defined(__EMX__)
+ retval = fcntl(fileno(IoIFP(io)), func, (int)s);
+# else
retval = fcntl(fileno(IoIFP(io)), func, s);
+# endif
# else
DIE("fcntl is not implemented");
# endif
#endif
- if (SvPOK(argstr)) {
- if (s[SvCUR(argstr)] != 17)
+ if (SvPOK(argsv)) {
+ if (s[SvCUR(argsv)] != 17)
DIE("Possible memory corruption: %s overflowed 3rd argument",
op_name[optype]);
- s[SvCUR(argstr)] = 0; /* put our null back */
- SvSETMAGIC(argstr); /* Assume it has changed */
+ s[SvCUR(argsv)] = 0; /* put our null back */
+ SvSETMAGIC(argsv); /* Assume it has changed */
}
if (retval == -1)
int argtype;
GV *gv;
FILE *fp;
-#ifdef HAS_FLOCK
+
+#if !defined(HAS_FLOCK) && defined(HAS_LOCKF)
+# define flock lockf_emulate_flock
+#endif
+
+#if defined(HAS_FLOCK) || defined(flock)
argtype = POPi;
if (MAXARG <= 0)
gv = last_in_gv;
PUSHi(value);
RETURN;
#else
-# ifdef HAS_LOCKF
- DIE(no_func, "flock()"); /* XXX emulate flock() with lockf()? */
-# else
DIE(no_func, "flock()");
-# endif
#endif
}
gv = (GV*)POPs;
if (!gv) {
- errno = EBADF;
+ SETERRNO(EBADF,LIB$_INVARG);
RETPUSHUNDEF;
}
{
dSP;
#ifdef HAS_SOCKET
- SV *addrstr = POPs;
+ SV *addrsv = POPs;
char *addr;
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
if (!io || !IoIFP(io))
goto nuts;
- addr = SvPV(addrstr, len);
+ addr = SvPV(addrsv, len);
TAINT_PROPER("bind");
if (bind(fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
RETPUSHYES;
nuts:
if (dowarn)
warn("bind() on closed fd");
- errno = EBADF;
+ SETERRNO(EBADF,SS$_IVCHAN);
RETPUSHUNDEF;
#else
DIE(no_sock_func, "bind");
{
dSP;
#ifdef HAS_SOCKET
- SV *addrstr = POPs;
+ SV *addrsv = POPs;
char *addr;
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
if (!io || !IoIFP(io))
goto nuts;
- addr = SvPV(addrstr, len);
+ addr = SvPV(addrsv, len);
TAINT_PROPER("connect");
if (connect(fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
RETPUSHYES;
nuts:
if (dowarn)
warn("connect() on closed fd");
- errno = EBADF;
+ SETERRNO(EBADF,SS$_IVCHAN);
RETPUSHUNDEF;
#else
DIE(no_sock_func, "connect");
nuts:
if (dowarn)
warn("listen() on closed fd");
- errno = EBADF;
+ SETERRNO(EBADF,SS$_IVCHAN);
RETPUSHUNDEF;
#else
DIE(no_sock_func, "listen");
GV *ggv;
register IO *nstio;
register IO *gstio;
- int len = sizeof buf;
+ struct sockaddr saddr; /* use a struct to avoid alignment problems */
+ int len = sizeof saddr;
int fd;
ggv = (GV*)POPs;
if (IoIFP(nstio))
do_close(ngv, FALSE);
- fd = accept(fileno(IoIFP(gstio)), (struct sockaddr *)buf, &len);
+ fd = accept(fileno(IoIFP(gstio)), (struct sockaddr *)&saddr, &len);
if (fd < 0)
goto badexit;
IoIFP(nstio) = fdopen(fd, "r");
goto badexit;
}
- PUSHp(buf, len);
+ PUSHp((char *)&saddr, len);
RETURN;
nuts:
if (dowarn)
warn("accept() on closed fd");
- errno = EBADF;
+ SETERRNO(EBADF,SS$_IVCHAN);
badexit:
RETPUSHUNDEF;
nuts:
if (dowarn)
warn("shutdown() on closed fd");
- errno = EBADF;
+ SETERRNO(EBADF,SS$_IVCHAN);
RETPUSHUNDEF;
#else
DIE(no_sock_func, "shutdown");
unsigned int lvl;
GV *gv;
register IO *io;
+ int aint;
if (optype == OP_GSOCKOPT)
sv = sv_2mortal(NEWSV(22, 257));
fd = fileno(IoIFP(io));
switch (optype) {
case OP_GSOCKOPT:
- SvGROW(sv, 256);
+ SvGROW(sv, 257);
(void)SvPOK_only(sv);
- if (getsockopt(fd, lvl, optname, SvPVX(sv), (int*)&SvCUR(sv)) < 0)
+ SvCUR_set(sv,256);
+ *SvEND(sv) ='\0';
+ aint = SvCUR(sv);
+ if (getsockopt(fd, lvl, optname, SvPVX(sv), &aint) < 0)
goto nuts2;
+ SvCUR_set(sv,aint);
+ *SvEND(sv) ='\0';
PUSHs(sv);
break;
case OP_SSOCKOPT: {
- int aint;
STRLEN len = 0;
char *buf = 0;
if (SvPOKp(sv))
nuts:
if (dowarn)
warn("[gs]etsockopt() on closed fd");
- errno = EBADF;
+ SETERRNO(EBADF,SS$_IVCHAN);
nuts2:
RETPUSHUNDEF;
int fd;
GV *gv = (GV*)POPs;
register IO *io = GvIOn(gv);
+ int aint;
if (!io || !IoIFP(io))
goto nuts;
sv = sv_2mortal(NEWSV(22, 257));
- SvCUR_set(sv, 256);
- SvPOK_on(sv);
+ (void)SvPOK_only(sv);
+ SvCUR_set(sv,256);
+ *SvEND(sv) ='\0';
+ aint = SvCUR(sv);
fd = fileno(IoIFP(io));
switch (optype) {
case OP_GETSOCKNAME:
- if (getsockname(fd, (struct sockaddr *)SvPVX(sv), (int*)&SvCUR(sv)) < 0)
+ if (getsockname(fd, (struct sockaddr *)SvPVX(sv), &aint) < 0)
goto nuts2;
break;
case OP_GETPEERNAME:
- if (getpeername(fd, (struct sockaddr *)SvPVX(sv), (int*)&SvCUR(sv)) < 0)
+ if (getpeername(fd, (struct sockaddr *)SvPVX(sv), &aint) < 0)
goto nuts2;
break;
}
+ SvCUR_set(sv,aint);
+ *SvEND(sv) ='\0';
PUSHs(sv);
RETURN;
nuts:
if (dowarn)
warn("get{sock, peer}name() on closed fd");
- errno = EBADF;
+ SETERRNO(EBADF,SS$_IVCHAN);
nuts2:
RETPUSHUNDEF;
if (op->op_flags & OPf_REF) {
tmpgv = cGVOP->op_gv;
+ do_fstat:
if (tmpgv != defgv) {
laststype = OP_STAT;
statgv = tmpgv;
max = 0;
}
else {
- sv_setpv(statname, POPp);
+ SV* sv = POPs;
+ if (SvTYPE(sv) == SVt_PVGV) {
+ tmpgv = (GV*)sv;
+ goto do_fstat;
+ }
+ else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV) {
+ tmpgv = (GV*)SvRV(sv);
+ goto do_fstat;
+ }
+ sv_setpv(statname, SvPV(sv,na));
statgv = Nullgv;
#ifdef HAS_LSTAT
laststype = op->op_type;
dSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( (basetime - statcache.st_mtime) / 86400.0 );
+ PUSHn( ((I32)basetime - (I32)statcache.st_mtime) / 86400.0 );
RETURN;
}
dSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( (basetime - statcache.st_atime) / 86400.0 );
+ PUSHn( ((I32)basetime - (I32)statcache.st_atime) / 86400.0 );
RETURN;
}
dSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( (basetime - statcache.st_ctime) / 86400.0 );
+ PUSHn( ((I32)basetime - (I32)statcache.st_ctime) / 86400.0 );
RETURN;
}
RETPUSHNO;
}
-#if defined(USE_STD_STDIO) || defined(atarist) /* this will work with atariST */
-# define FBASE(f) ((f)->_base)
-# define FSIZE(f) ((f)->_cnt + ((f)->_ptr - (f)->_base))
-# define FPTR(f) ((f)->_ptr)
-# define FCOUNT(f) ((f)->_cnt)
-#else
-# if defined(USE_LINUX_STDIO)
-# define FBASE(f) ((f)->_IO_read_base)
-# define FSIZE(f) ((f)->_IO_read_end - FBASE(f))
-# define FPTR(f) ((f)->_IO_read_ptr)
-# define FCOUNT(f) ((f)->_IO_read_end - FPTR(f))
-# endif
+#if defined(atarist) /* this will work with atariST. Configure will
+ make guesses for other systems. */
+# define FILE_base(f) ((f)->_base)
+# define FILE_ptr(f) ((f)->_ptr)
+# define FILE_cnt(f) ((f)->_cnt)
+# define FILE_bufsiz(f) ((f)->_cnt + ((f)->_ptr - (f)->_base))
#endif
PP(pp_fttext)
io = GvIO(statgv);
}
if (io && IoIFP(io)) {
-#ifdef FBASE
+#ifdef FILE_base
Fstat(fileno(IoIFP(io)), &statcache);
if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */
if (op->op_type == OP_FTTEXT)
RETPUSHNO;
else
RETPUSHYES;
- if (FCOUNT(IoIFP(io)) <= 0) {
+ if (FILE_cnt(IoIFP(io)) <= 0) {
i = getc(IoIFP(io));
if (i != EOF)
(void)ungetc(i, IoIFP(io));
}
- if (FCOUNT(IoIFP(io)) <= 0) /* null file is anything */
+ if (FILE_cnt(IoIFP(io)) <= 0) /* null file is anything */
RETPUSHYES;
- len = FSIZE(IoIFP(io));
- s = FBASE(IoIFP(io));
+ len = FILE_bufsiz(IoIFP(io));
+ s = FILE_base(IoIFP(io));
#else
DIE("-T and -B not implemented on filehandles");
#endif
if (dowarn)
warn("Test on unopened file <%s>",
GvENAME(cGVOP->op_gv));
- errno = EBADF;
+ SETERRNO(EBADF,RMS$_IFI);
RETPUSHUNDEF;
}
}
}
/* now scan s to look for textiness */
+ /* XXX ASCII dependent code */
for (i = 0; i < len; i++, s++) {
if (!*s) { /* null never allowed in text */
odd++;
}
- if ((odd * 30 > len) == (op->op_type == OP_FTTEXT)) /* allow 30% odd */
+ if ((odd * 3 > len) == (op->op_type == OP_FTTEXT)) /* allow 1/3 odd */
RETPUSHNO;
else
RETPUSHYES;
}
TAINT_PROPER("chdir");
PUSHi( 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);
+#endif
RETURN;
}
char *filename;
{
char mybuf[8192];
- char *s, *tmps;
+ char *s,
+ *save_filename = filename;
int anum = 1;
FILE *myfp;
return 0;
#endif
}
- errno = 0;
+ SETERRNO(0,0);
#ifndef EACCES
#define EACCES EPERM
#endif
if (instr(mybuf, "cannot make"))
- errno = EEXIST;
+ SETERRNO(EEXIST,RMS$_FEX);
else if (instr(mybuf, "existing file"))
- errno = EEXIST;
+ SETERRNO(EEXIST,RMS$_FEX);
else if (instr(mybuf, "ile exists"))
- errno = EEXIST;
+ SETERRNO(EEXIST,RMS$_FEX);
else if (instr(mybuf, "non-exist"))
- errno = ENOENT;
+ SETERRNO(ENOENT,RMS$_FNF);
else if (instr(mybuf, "does not exist"))
- errno = ENOENT;
+ SETERRNO(ENOENT,RMS$_FNF);
else if (instr(mybuf, "not empty"))
- errno = EBUSY;
+ SETERRNO(EBUSY,SS$_DEVOFFLINE);
else if (instr(mybuf, "cannot access"))
- errno = EACCES;
+ SETERRNO(EACCES,RMS$_PRV);
else
- errno = EPERM;
+ SETERRNO(EPERM,RMS$_PRV);
return 0;
}
else { /* some mkdirs return no failure indication */
- anum = (Stat(filename, &statbuf) >= 0);
+ anum = (Stat(save_filename, &statbuf) >= 0);
if (op->op_type == OP_RMDIR)
anum = !anum;
if (anum)
- errno = 0;
+ SETERRNO(0,0);
else
- errno = EACCES; /* a guess */
+ SETERRNO(EACCES,RMS$_PRV); /* a guess */
}
return anum;
}
RETPUSHYES;
nope:
if (!errno)
- errno = EBADF;
+ SETERRNO(EBADF,RMS$_DIR);
RETPUSHUNDEF;
#else
DIE(no_dir_func, "opendir");
nope:
if (!errno)
- errno = EBADF;
+ SETERRNO(EBADF,RMS$_ISI);
if (GIMME == G_ARRAY)
RETURN;
else
RETURN;
nope:
if (!errno)
- errno = EBADF;
+ SETERRNO(EBADF,RMS$_ISI);
RETPUSHUNDEF;
#else
DIE(no_dir_func, "telldir");
RETPUSHYES;
nope:
if (!errno)
- errno = EBADF;
+ SETERRNO(EBADF,RMS$_ISI);
RETPUSHUNDEF;
#else
DIE(no_dir_func, "seekdir");
RETPUSHYES;
nope:
if (!errno)
- errno = EBADF;
+ SETERRNO(EBADF,RMS$_ISI);
RETPUSHUNDEF;
#else
DIE(no_dir_func, "rewinddir");
#ifdef VOID_CLOSEDIR
closedir(IoDIRP(io));
#else
- if (closedir(IoDIRP(io)) < 0)
+ if (closedir(IoDIRP(io)) < 0) {
+ IoDIRP(io) = 0; /* Don't try to close again--coredumps on SysV */
goto nope;
+ }
#endif
IoDIRP(io) = 0;
RETPUSHYES;
nope:
if (!errno)
- errno = EBADF;
+ SETERRNO(EBADF,RMS$_IFI);
RETPUSHUNDEF;
#else
DIE(no_dir_func, "closedir");
if (childpid > 0)
pidgone(childpid, argflags);
value = (I32)childpid;
- statusvalue = (U16)argflags;
+ statusvalue = FIXSTATUS(argflags);
PUSHi(value);
RETURN;
#else
childpid = TOPi;
childpid = wait4pid(childpid, &argflags, optype);
value = (I32)childpid;
- statusvalue = (U16)argflags;
+ statusvalue = FIXSTATUS(argflags);
SETi(value);
RETURN;
#else
Signal_t (*ihand)(); /* place to save signal during system() */
Signal_t (*qhand)(); /* place to save signal during system() */
-#if defined(HAS_FORK) && !defined(VMS)
+#if defined(HAS_FORK) && !defined(VMS) && !defined(OS2)
if (SP - MARK == 1) {
if (tainting) {
char *junk = SvPV(TOPs, na);
if (childpid > 0) {
ihand = signal(SIGINT, SIG_IGN);
qhand = signal(SIGQUIT, SIG_IGN);
- result = wait4pid(childpid, &status, 0);
+ do {
+ result = wait4pid(childpid, &status, 0);
+ } while (result == -1 && errno == EINTR);
(void)signal(SIGINT, ihand);
(void)signal(SIGQUIT, qhand);
- statusvalue = (U16)status;
+ statusvalue = FIXSTATUS(status);
if (result < 0)
value = -1;
else {
value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
}
_exit(-1);
-#else /* ! FORK or VMS */
+#else /* ! FORK or VMS or OS/2 */
if (op->op_flags & OPf_STACKED) {
SV *really = *++MARK;
value = (I32)do_aspawn(really, MARK, SP);
else {
value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), na));
}
+ statusvalue = FIXSTATUS(value);
do_execfree();
SP = ORIGMARK;
PUSHi(value);
pid = 0;
else
pid = SvIVx(POPs);
-#ifdef USE_BSDPGRP
- value = (I32)getpgrp(pid);
+#ifdef BSD_GETPGRP
+ value = (I32)BSD_GETPGRP(pid);
#else
if (pid != 0)
DIE("POSIX getpgrp can't take an argument");
}
TAINT_PROPER("setpgrp");
-#ifdef USE_BSDPGRP
- SETi( setpgrp(pid, pgrp) >= 0 );
+#ifdef BSD_SETPGRP
+ SETi( BSD_SETPGRP(pid, pgrp) >= 0 );
#else
if ((pgrp != 0) || (pid != 0)) {
DIE("POSIX setpgrp can't take an argument");
(void)times((tbuffer_t *)×buf); /* time.h uses different name for */
/* struct tms, though same data */
/* is returned. */
+#undef HZ
+#define HZ CLK_TCK
#endif
PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_utime)/HZ)));
PUSHi(value);
RETURN;
#else
- pp_semget(ARGS);
+ return pp_semget(ARGS);
#endif
}
PUSHi(value);
RETURN;
#else
- pp_semget(ARGS);
+ return pp_semget(ARGS);
#endif
}
PUSHi(value);
RETURN;
#else
- pp_semget(ARGS);
+ return pp_semget(ARGS);
#endif
}
}
RETURN;
#else
- pp_semget(ARGS);
+ return pp_semget(ARGS);
#endif
}
PUSHi(value);
RETURN;
#else
- pp_semget(ARGS);
+ return pp_semget(ARGS);
#endif
}
}
else if (which == OP_GHBYADDR) {
int addrtype = POPi;
- SV *addrstr = POPs;
+ SV *addrsv = POPs;
STRLEN addrlen;
- char *addr = SvPV(addrstr, addrlen);
+ char *addr = SvPV(addrsv, addrlen);
hent = gethostbyaddr(addr, addrlen, addrtype);
}
#ifdef HOST_NOT_FOUND
if (!hent)
- statusvalue = (U16)h_errno & 0xffff;
+ statusvalue = FIXSTATUS(h_errno);
#endif
if (GIMME != G_ARRAY) {
PUSHs(sv = sv_newmortal());
if (hent) {
if (which == OP_GHBYNAME) {
- sv_setpvn(sv, hent->h_addr, hent->h_length);
+ if (hent->h_addr)
+ sv_setpvn(sv, hent->h_addr, hent->h_length);
}
else
sv_setpv(sv, (char*)hent->h_name);
}
#else
PUSHs(sv = sv_mortalcopy(&sv_no));
- sv_setpvn(sv, hent->h_addr, len);
+ if (hent->h_addr)
+ sv_setpvn(sv, hent->h_addr, len);
#endif /* h_addr */
}
RETURN;
unsigned long a[20];
register I32 i = 0;
I32 retval = -1;
+ MAGIC *mg;
if (tainting) {
while (++MARK <= SP) {
- if (SvGMAGICAL(*MARK) && SvSMAGICAL(*MARK) && mg_find(*MARK, 't'))
+ if (SvGMAGICAL(*MARK) && SvSMAGICAL(*MARK) &&
+ (mg = mg_find(*MARK, 't')) && mg->mg_len & 1)
tainted = TRUE;
}
MARK = ORIGMARK;
while (++MARK <= SP) {
if (SvNIOK(*MARK) || !i)
a[i++] = SvIV(*MARK);
- else
- a[i++] = (unsigned long)SvPVX(*MARK);
+ else if (*MARK == &sv_undef)
+ a[i++] = 0;
+ else
+ a[i++] = (unsigned long)SvPV_force(*MARK, na);
if (i > 15)
break;
}
#endif
}
+#if !defined(HAS_FLOCK) && defined(HAS_LOCKF)
+
+/* XXX Emulate flock() with lockf(). This is just to increase
+ portability of scripts. The calls are not completely
+ interchangeable. What's really needed is a good file
+ locking module.
+*/
+
+/* We might need <unistd.h> because it sometimes defines the lockf()
+ constants. Unfortunately, <unistd.h> causes troubles on some mixed
+ (BSD/POSIX) systems, such as SunOS 4.1.3. We could just try including
+ <unistd.h> here in this part of the file, but that might
+ conflict with various other #defines and includes above, such as
+ #define vfork fork above.
+
+ Further, the lockf() constants aren't POSIX, so they might not be
+ visible if we're compiling with _POSIX_SOURCE defined. Thus, we'll
+ just stick in the SVID values and be done with it. Sigh.
+*/
+
+# ifndef F_ULOCK
+# define F_ULOCK 0 /* Unlock a previously locked region */
+# endif
+# ifndef F_LOCK
+# define F_LOCK 1 /* Lock a region for exclusive use */
+# endif
+# ifndef F_TLOCK
+# define F_TLOCK 2 /* Test and lock a region for exclusive use */
+# endif
+# ifndef F_TEST
+# define F_TEST 3 /* Test a region for other processes locks */
+# endif
+
+/* These are the flock() constants. Since this sytems doesn't have
+ flock(), the values of the constants are probably not available.
+*/
+# ifndef LOCK_SH
+# define LOCK_SH 1
+# endif
+# ifndef LOCK_EX
+# define LOCK_EX 2
+# endif
+# ifndef LOCK_NB
+# define LOCK_NB 4
+# endif
+# ifndef LOCK_UN
+# define LOCK_UN 8
+# endif
+
+int
+lockf_emulate_flock (fd, operation)
+int fd;
+int operation;
+{
+ int i;
+ switch (operation) {
+
+ /* LOCK_SH - get a shared lock */
+ case LOCK_SH:
+ /* LOCK_EX - get an exclusive lock */
+ case LOCK_EX:
+ i = lockf (fd, F_LOCK, 0);
+ break;
+
+ /* LOCK_SH|LOCK_NB - get a non-blocking shared lock */
+ case LOCK_SH|LOCK_NB:
+ /* LOCK_EX|LOCK_NB - get a non-blocking exclusive lock */
+ case LOCK_EX|LOCK_NB:
+ i = lockf (fd, F_TLOCK, 0);
+ if (i == -1)
+ if ((errno == EAGAIN) || (errno == EACCES))
+ errno = EWOULDBLOCK;
+ break;
+
+ /* LOCK_UN - unlock */
+ case LOCK_UN:
+ i = lockf (fd, F_ULOCK, 0);
+ break;
+
+ /* Default - can't decipher operation */
+ default:
+ i = -1;
+ errno = EINVAL;
+ break;
+ }
+ return (i);
+}
+#endif