#include <signal.h>
bool
-Perl_do_open(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
- int rawmode, int rawperm, PerlIO *supplied_fp)
-{
- return do_openn(gv, name, len, as_raw, rawmode, rawperm,
- supplied_fp, (SV **) NULL, 0);
-}
-
-bool
-Perl_do_open9(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
- int rawmode, int rawperm, PerlIO *supplied_fp, SV *svs,
- I32 num_svs)
-{
- (void)num_svs;
- return do_openn(gv, name, len, as_raw, rawmode, rawperm,
- supplied_fp, &svs, 1);
-}
-
-bool
-Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
+Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw,
int rawmode, int rawperm, PerlIO *supplied_fp, SV **svp,
I32 num_svs)
{
dVAR;
- register IO *io = GvIOn(gv);
+ register IO * const io = GvIOn(gv);
PerlIO *saveifp = Nullfp;
PerlIO *saveofp = Nullfp;
int savefd = -1;
IoTYPE(io) = PerlIO_intmode2str(rawmode, &mode[ix], &writing);
- namesv = sv_2mortal(newSVpvn(name,strlen(name)));
+ namesv = sv_2mortal(newSVpvn(oname,strlen(oname)));
num_svs = 1;
svp = &namesv;
type = Nullch;
}
else {
/* Regular (non-sys) open */
- char *oname = name;
+ char *name;
STRLEN olen = len;
char *tend;
int dodup = 0;
PerlIO *that_fp = NULL;
- type = savepvn(name, len);
+ type = savepvn(oname, len);
tend = type+len;
SAVEFREEPV(type);
if (num_svs) {
/* New style explicit name, type is just mode and layer info */
#ifdef USE_STDIO
- if (SvROK(*svp) && !strchr(name,'&')) {
+ if (SvROK(*svp) && !strchr(oname,'&')) {
if (ckWARN(WARN_IO))
Perl_warner(aTHX_ packWARN(WARN_IO),
"Can't open a reference");
else
was_fdopen = TRUE;
if (!(fp = PerlIO_openn(aTHX_ type,mode,fd,0,0,NULL,num_svs,svp))) {
- if (dodup)
+ if (dodup && fd >= 0)
PerlLIO_close(fd);
}
}
}
}
if (!fp) {
- if (ckWARN(WARN_NEWLINE) && IoTYPE(io) == IoTYPE_RDONLY && strchr(name, '\n'))
+ if (IoTYPE(io) == IoTYPE_RDONLY && ckWARN(WARN_NEWLINE)
+ && strchr(oname, '\n')
+
+ )
Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "open");
goto say_false;
}
#endif
Uid_t fileuid;
Gid_t filegid;
- IO *io = GvIOp(gv);
+ IO * const io = GvIOp(gv);
if (!PL_argvoutgv)
PL_argvoutgv = gv_fetchpv("ARGVOUT",TRUE,SVt_PVIO);
STRLEN oldlen;
sv = av_shift(GvAV(gv));
SAVEFREESV(sv);
- sv_setsv(GvSV(gv),sv);
+ sv_setsv(GvSVn(gv),sv);
SvSETMAGIC(GvSV(gv));
PL_oldname = SvPVx(GvSV(gv), oldlen);
if (do_open(gv,PL_oldname,oldlen,PL_inplace!=0,O_RDONLY,0,Nullfp)) {
continue;
}
if (*PL_inplace) {
- char *star = strchr(PL_inplace, '*');
+ const char *star = strchr(PL_inplace, '*');
if (star) {
- char *begin = PL_inplace;
+ const char *begin = PL_inplace;
sv_setpvn(sv, "", 0);
do {
sv_catpvn(sv, begin, star - begin);
return Nullfp;
}
-#ifdef HAS_PIPE
-void
-Perl_do_pipe(pTHX_ SV *sv, GV *rgv, GV *wgv)
-{
- register IO *rstio;
- register IO *wstio;
- int fd[2];
-
- if (!rgv)
- goto badexit;
- if (!wgv)
- goto badexit;
-
- rstio = GvIOn(rgv);
- wstio = GvIOn(wgv);
-
- if (IoIFP(rstio))
- do_close(rgv,FALSE);
- if (IoIFP(wstio))
- do_close(wgv,FALSE);
-
- if (PerlProc_pipe(fd) < 0)
- goto badexit;
- IoIFP(rstio) = PerlIO_fdopen(fd[0], "r"PIPE_OPEN_MODE);
- IoOFP(wstio) = PerlIO_fdopen(fd[1], "w"PIPE_OPEN_MODE);
- IoOFP(rstio) = IoIFP(rstio);
- IoIFP(wstio) = IoOFP(wstio);
- IoTYPE(rstio) = IoTYPE_RDONLY;
- IoTYPE(wstio) = IoTYPE_WRONLY;
- if (!IoIFP(rstio) || !IoOFP(wstio)) {
- if (IoIFP(rstio)) PerlIO_close(IoIFP(rstio));
- else PerlLIO_close(fd[0]);
- if (IoOFP(wstio)) PerlIO_close(IoOFP(wstio));
- else PerlLIO_close(fd[1]);
- goto badexit;
- }
-
- sv_setsv(sv,&PL_sv_yes);
- return;
-
-badexit:
- sv_setsv(sv,&PL_sv_undef);
- return;
-}
-#endif
-
/* explicit renamed to avoid C++ conflict -- kja */
bool
Perl_do_close(pTHX_ GV *gv, bool not_implicit)
if (IoTYPE(io) == IoTYPE_PIPE) {
const int status = PerlProc_pclose(IoIFP(io));
if (not_implicit) {
- STATUS_NATIVE_SET(status);
+ STATUS_NATIVE_CHILD_SET(status);
retval = (STATUS_UNIX == 0);
}
else {
if (!io)
return TRUE;
- else if (ckWARN(WARN_IO) && (IoTYPE(io) == IoTYPE_WRONLY))
+ else if ((IoTYPE(io) == IoTYPE_WRONLY) && ckWARN(WARN_IO))
report_evil_fh(gv, io, OP_phoney_OUTPUT_ONLY);
while (IoIFP(io)) {
return mode;
}
-int
-Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)
-{
- /* The old body of this is now in non-LAYER part of perlio.c
- * This is a stub for any XS code which might have been calling it.
- */
- const char *name = ":raw";
-#ifdef PERLIO_USING_CRLF
- if (!(mode & O_BINARY))
- name = ":crlf";
-#endif
- return PerlIO_binmode(aTHX_ fp, iotype, mode, name);
-}
-
#if !defined(HAS_TRUNCATE) && !defined(HAS_CHSIZE)
I32
my_chsize(int fd, Off_t length)
return TRUE;
case SVt_IV:
if (SvIOK(sv)) {
- if (SvGMAGICAL(sv))
- mg_get(sv);
+ SvGETMAGIC(sv);
if (SvIsUV(sv))
PerlIO_printf(fp, "%"UVuf, (UV)SvUVX(sv));
else
return (PL_laststatval = -1);
}
}
- else if (ckWARN(WARN_IO) && PL_laststype != OP_LSTAT
- && (PL_op->op_private & OPpFT_STACKED))
+ else if (PL_laststype != OP_LSTAT
+ && (PL_op->op_private & OPpFT_STACKED) && ckWARN(WARN_IO))
Perl_croak(aTHX_ no_prev_lstat);
PL_laststype = OP_LSTAT;
return PL_laststatval;
}
-#ifndef OS2
-bool
-Perl_do_aexec(pTHX_ SV *really, register SV **mark, register SV **sp)
-{
- return do_aexec5(really, mark, sp, 0, 0);
-}
-#endif
-
bool
Perl_do_aexec5(pTHX_ SV *really, register SV **mark, register SV **sp,
int fd, int do_report)
{
dVAR;
-#if defined(MACOS_TRADITIONAL) || defined(SYMBIAN)
+#if defined(MACOS_TRADITIONAL) || defined(__SYMBIAN32__)
Perl_croak(aTHX_ "exec? I'm not *that* kind of operating system");
#else
- register char **a;
- const char *tmps = Nullch;
-
if (sp > mark) {
- New(401,PL_Argv, sp - mark + 1, char*);
+ char **a;
+ const char *tmps = Nullch;
+ Newx(PL_Argv, sp - mark + 1, char*);
a = PL_Argv;
+
while (++mark <= sp) {
if (*mark)
*a++ = (char*)SvPV_nolen_const(*mark);
void
Perl_do_execfree(pTHX)
{
- if (PL_Argv) {
- Safefree(PL_Argv);
- PL_Argv = Null(char **);
- }
- if (PL_Cmd) {
- Safefree(PL_Cmd);
- PL_Cmd = Nullch;
- }
+ Safefree(PL_Argv);
+ PL_Argv = Null(char **);
+ Safefree(PL_Cmd);
+ PL_Cmd = Nullch;
}
-#if !defined(OS2) && !defined(WIN32) && !defined(DJGPP) && !defined(EPOC) && !defined(SYMBIAN) && !defined(MACOS_TRADITIONAL)
-
-bool
-Perl_do_exec(pTHX_ char *cmd)
-{
- return do_exec3(cmd,0,0);
-}
+#ifdef PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION
bool
-Perl_do_exec3(pTHX_ char *cmd, int fd, int do_report)
+Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report)
{
dVAR;
register char **a;
register char *s;
+ char *cmd;
+ int cmdlen;
+
+ /* Make a copy so we can change it */
+ cmdlen = strlen(incmd);
+ Newx(cmd, cmdlen+1, char);
+ strncpy(cmd, incmd, cmdlen);
+ cmd[cmdlen] = 0;
while (*cmd && isSPACE(*cmd))
cmd++;
PerlProc_execl(PL_cshname,"csh", flags, ncmd, (char*)0);
PERL_FPU_POST_EXEC
*s = '\'';
+ Safefree(cmd);
return FALSE;
}
}
PERL_FPU_PRE_EXEC
PerlProc_execl(PL_sh_path, "sh", "-c", cmd, (char*)0);
PERL_FPU_POST_EXEC
+ Safefree(cmd);
return FALSE;
}
}
- New(402,PL_Argv, (s - cmd) / 2 + 2, char*);
+ Newx(PL_Argv, (s - cmd) / 2 + 2, char*);
PL_Cmd = savepvn(cmd, s-cmd);
a = PL_Argv;
for (s = PL_Cmd; *s;) {
}
}
do_execfree();
+ Safefree(cmd);
return FALSE;
}
register I32 tot = 0;
const char *what;
const char *s;
- SV **oldmark = mark;
+ SV ** const oldmark = mark;
+
+ /* Doing this ahead of the switch statement preserves the old behaviour,
+ where attempting to use kill as a taint test test would fail on
+ platforms where kill was not defined. */
+#ifndef HAS_KILL
+ if (type == OP_KILL)
+ DIE(aTHX_ PL_no_func, "kill");
+#endif
+#ifndef HAS_CHOWN
+ if (type == OP_CHOWN)
+ DIE(aTHX_ PL_no_func, "chown");
+#endif
+
#define APPLY_TAINT_PROPER() \
STMT_START { \
APPLY_TAINT_PROPER();
tot = sp - mark;
while (++mark <= sp) {
- const char *name = SvPV_nolen_const(*mark);
- APPLY_TAINT_PROPER();
- if (PerlLIO_chmod(name, val))
- tot--;
+ GV* gv;
+ if (SvTYPE(*mark) == SVt_PVGV) {
+ gv = (GV*)*mark;
+ do_fchmod:
+ if (GvIO(gv) && IoIFP(GvIOp(gv))) {
+#ifdef HAS_FCHMOD
+ APPLY_TAINT_PROPER();
+ if (fchmod(PerlIO_fileno(IoIFP(GvIOn(gv))), val))
+ tot--;
+#else
+ Perl_die(aTHX_ PL_no_func, "fchmod");
+#endif
+ }
+ else {
+ tot--;
+ }
+ }
+ else if (SvROK(*mark) && SvTYPE(SvRV(*mark)) == SVt_PVGV) {
+ gv = (GV*)SvRV(*mark);
+ goto do_fchmod;
+ }
+ else {
+ const char *name = SvPV_nolen_const(*mark);
+ APPLY_TAINT_PROPER();
+ if (PerlLIO_chmod(name, val))
+ tot--;
+ }
}
}
break;
APPLY_TAINT_PROPER();
tot = sp - mark;
while (++mark <= sp) {
- const char *name = SvPV_nolen_const(*mark);
- APPLY_TAINT_PROPER();
- if (PerlLIO_chown(name, val, val2))
- tot--;
+ GV* gv;
+ if (SvTYPE(*mark) == SVt_PVGV) {
+ gv = (GV*)*mark;
+ do_fchown:
+ if (GvIO(gv) && IoIFP(GvIOp(gv))) {
+#ifdef HAS_FCHOWN
+ APPLY_TAINT_PROPER();
+ if (fchown(PerlIO_fileno(IoIFP(GvIOn(gv))), val, val2))
+ tot--;
+#else
+ Perl_die(aTHX_ PL_no_func, "fchown");
+#endif
+ }
+ else {
+ tot--;
+ }
+ }
+ else if (SvROK(*mark) && SvTYPE(SvRV(*mark)) == SVt_PVGV) {
+ gv = (GV*)SvRV(*mark);
+ goto do_fchown;
+ }
+ else {
+ const char *name = SvPV_nolen_const(*mark);
+ APPLY_TAINT_PROPER();
+ if (PerlLIO_chown(name, val, val2))
+ tot--;
+ }
}
}
break;
}
}
break;
-#ifdef HAS_UTIME
+#if defined(HAS_UTIME) || defined(HAS_FUTIMES)
case OP_UTIME:
what = "utime";
APPLY_TAINT_PROPER();
if (sp - mark > 2) {
-#if defined(I_UTIME) || defined(VMS)
+#if defined(HAS_FUTIMES)
+ struct timeval utbuf[2];
+ void *utbufp = utbuf;
+#elif defined(I_UTIME) || defined(VMS)
struct utimbuf utbuf;
struct utimbuf *utbufp = &utbuf;
#else
utbufp = NULL;
else {
Zero(&utbuf, sizeof utbuf, char);
-#ifdef BIG_TIME
+#ifdef HAS_FUTIMES
+ utbuf[0].tv_sec = (long)SvIVx(accessed); /* time accessed */
+ utbuf[0].tv_usec = 0;
+ utbuf[1].tv_sec = (long)SvIVx(modified); /* time modified */
+ utbuf[1].tv_usec = 0;
+#elif defined(BIG_TIME)
utbuf.actime = (Time_t)SvNVx(accessed); /* time accessed */
utbuf.modtime = (Time_t)SvNVx(modified); /* time modified */
#else
APPLY_TAINT_PROPER();
tot = sp - mark;
while (++mark <= sp) {
- char *name = SvPV_nolen(*mark);
- APPLY_TAINT_PROPER();
- if (PerlLIO_utime(name, utbufp))
- tot--;
+ GV* gv;
+ if (SvTYPE(*mark) == SVt_PVGV) {
+ gv = (GV*)*mark;
+ do_futimes:
+ if (GvIO(gv) && IoIFP(GvIOp(gv))) {
+#ifdef HAS_FUTIMES
+ APPLY_TAINT_PROPER();
+ if (futimes(PerlIO_fileno(IoIFP(GvIOn(gv))), utbufp))
+ tot--;
+#else
+ Perl_die(aTHX_ PL_no_func, "futimes");
+#endif
+ }
+ else {
+ tot--;
+ }
+ }
+ else if (SvROK(*mark) && SvTYPE(SvRV(*mark)) == SVt_PVGV) {
+ gv = (GV*)SvRV(*mark);
+ goto do_futimes;
+ }
+ else {
+ const char *name = SvPV_nolen_const(*mark);
+ APPLY_TAINT_PROPER();
+#ifdef HAS_FUTIMES
+ if (utimes(name, utbufp))
+#else
+ if (PerlLIO_utime(name, utbufp))
+#endif
+ tot--;
+ }
+
}
}
else
const I32 id = SvIVx(*++mark);
const I32 n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0;
const I32 cmd = SvIVx(*++mark);
- (void)sp;
+ PERL_UNUSED_ARG(sp);
astr = *++mark;
infosize = 0;
I32 msize, flags;
STRLEN len;
const I32 id = SvIVx(*++mark);
- (void)sp;
+ PERL_UNUSED_ARG(sp);
mstr = *++mark;
flags = SvIVx(*++mark);
long mtype;
I32 msize, flags, ret;
const I32 id = SvIVx(*++mark);
- (void)sp;
+ PERL_UNUSED_ARG(sp);
mstr = *++mark;
/* suppress warning when reading into undef var --jhi */
const char *opbuf;
STRLEN opsize;
const I32 id = SvIVx(*++mark);
- (void)sp;
+ PERL_UNUSED_ARG(sp);
opstr = *++mark;
opbuf = SvPV_const(opstr, opsize);
struct sembuf *temps, *t;
I32 result;
- New (0, temps, nsops, struct sembuf);
+ Newx (temps, nsops, struct sembuf);
t = temps;
while (i--) {
t->sem_num = *o++;
I32 mpos, msize;
struct shmid_ds shmds;
const I32 id = SvIVx(*++mark);
- (void)sp;
+ PERL_UNUSED_ARG(sp);
mstr = *++mark;
mpos = SvIVx(*++mark);
Perl_start_glob (pTHX_ SV *tmpglob, IO *io)
{
dVAR;
- SV *tmpcmd = NEWSV(55, 0);
+ SV * const tmpcmd = NEWSV(55, 0);
PerlIO *fp;
ENTER;
SAVEFREESV(tmpcmd);
#include <rmsdef.h>
char rslt[NAM$C_MAXRSS+1+sizeof(unsigned short int)] = {'\0','\0'};
char vmsspec[NAM$C_MAXRSS+1];
- char *rstr = rslt + sizeof(unsigned short int), *begin, *end, *cp;
+ char * const rstr = rslt + sizeof(unsigned short int);
+ char *begin, *end, *cp;
$DESCRIPTOR(dfltdsc,"SYS$DISK:[]*.*;");
PerlIO *tmpfp;
STRLEN i;