mode = "rt";
fp = PerlProc_popen(tmps, mode);
if (fp) {
- const char *type = NULL;
- if (PL_curcop->cop_io) {
- type = SvPV_nolen_const(PL_curcop->cop_io);
- }
+ const char * const type = PL_curcop->cop_io ? SvPV_nolen_const(PL_curcop->cop_io) : NULL;
if (type && *type)
PerlIO_apply_layers(aTHX_ fp,mode,type);
tmps = SvROK(tmpsv) ? Nullch : SvPV_const(tmpsv, len);
}
if (!tmps || !len) {
- SV *error = ERRSV;
+ SV * const error = ERRSV;
SvUPGRADE(error, SVt_PV);
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");
+ HV * const stash = SvSTASH(SvRV(error));
+ GV * const gv = gv_fetchmethod(stash, "PROPAGATE");
if (gv) {
- SV *file = sv_2mortal(newSVpv(CopFILE(PL_curcop),0));
- SV *line = sv_2mortal(newSVuv(CopLINE(PL_curcop)));
+ SV * const file = sv_2mortal(newSVpv(CopFILE(PL_curcop),0));
+ SV * const line = sv_2mortal(newSVuv(CopLINE(PL_curcop)));
EXTEND(SP, 3);
PUSHMARK(SP);
PUSHs(error);
PP(pp_select)
{
dSP; dTARGET;
- GV *egv;
HV *hv;
-
GV * const newdefout = (PL_op->op_private > 0) ? ((GV *) POPs) : (GV *) NULL;
+ GV * egv = GvEGV(PL_defoutgv);
- egv = GvEGV(PL_defoutgv);
if (!egv)
egv = PL_defoutgv;
hv = GvSTASH(egv);
PP(pp_send)
{
dVAR; dSP; dMARK; dORIGMARK; dTARGET;
- GV *gv;
IO *io;
SV *bufsv;
const char *buffer;
MAGIC *mg;
const int op_type = PL_op->op_type;
- gv = (GV*)*++MARK;
+ GV *const gv = (GV*)*++MARK;
if (PL_op->op_type == OP_SYSWRITE
&& gv && (io = GvIO(gv))
&& (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)))
PP(pp_sysseek)
{
dVAR; dSP;
- GV *gv;
IO *io;
const int whence = POPi;
#if LSEEKSIZE > IVSIZE
- Off_t offset = (Off_t)SvNVx(POPs);
+ const Off_t offset = (Off_t)SvNVx(POPs);
#else
- Off_t offset = (Off_t)SvIVx(POPs);
+ const Off_t offset = (Off_t)SvIVx(POPs);
#endif
MAGIC *mg;
- gv = PL_last_in_gv = (GV*)POPs;
+ GV * const gv = PL_last_in_gv = (GV*)POPs;
if (gv && (io = GvIO(gv))
&& (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar)))
if (PL_op->op_type == OP_SEEK)
PUSHs(boolSV(do_seek(gv, offset, whence)));
else {
- Off_t sought = do_sysseek(gv, offset, whence);
+ const Off_t sought = do_sysseek(gv, offset, whence);
if (sought < 0)
PUSHs(&PL_sv_undef);
else {
- SV* sv = sought ?
+ SV* const sv = sought ?
#if LSEEKSIZE > IVSIZE
newSVnv((NV)sought)
#else
}
}
else {
- SV *sv = POPs;
+ SV * const sv = POPs;
const char *name;
if (SvTYPE(sv) == SVt_PVGV) {
result = 0;
#else
{
- int tmpfd;
+ const int tmpfd = PerlLIO_open(name, O_RDWR);
- if ((tmpfd = PerlLIO_open(name, O_RDWR)) < 0)
+ if (tmpfd < 0)
result = 0;
else {
if (my_chsize(tmpfd, len) < 0)
PP(pp_ioctl)
{
dSP; dTARGET;
- SV *argsv = POPs;
+ SV * const argsv = POPs;
const unsigned int func = POPu;
const int optype = PL_op->op_type;
+ GV * const gv = (GV*)POPs;
+ IO * const io = gv ? GvIOn(gv) : Null(IO*);
char *s;
IV retval;
- GV *gv = (GV*)POPs;
- IO *io = gv ? GvIOn(gv) : 0;
if (!io || !argsv || !IoIFP(io)) {
if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
#ifdef FLOCK
dSP; dTARGET;
I32 value;
- int argtype;
- GV *gv;
IO *io = NULL;
PerlIO *fp;
+ const int argtype = POPi;
+ GV * const gv = (MAXARG == 0) ? PL_last_in_gv : (GV*)POPs;
- argtype = POPi;
- if (MAXARG == 0)
- gv = PL_last_in_gv;
- else
- gv = (GV*)POPs;
if (gv && (io = GvIO(gv)))
fp = IoIFP(io);
else {
fp = Nullfp;
io = NULL;
}
+ /* XXX Looks to me like io is always NULL at this point */
if (fp) {
(void)PerlIO_flush(fp);
value = (I32)(PerlLIO_flock(PerlIO_fileno(fp), argtype) >= 0);
{
#ifdef HAS_SOCKET
dSP;
- GV *gv;
- register IO *io;
- int protocol = POPi;
- int type = POPi;
- int domain = POPi;
+ const int protocol = POPi;
+ const int type = POPi;
+ const int domain = POPi;
+ GV * const gv = (GV*)POPs;
+ register IO * const io = gv ? GvIOn(gv) : NULL;
int fd;
- gv = (GV*)POPs;
- io = gv ? GvIOn(gv) : NULL;
-
if (!gv || !io) {
if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
report_evil_fh(gv, io, PL_op->op_type);
{
#if defined (HAS_SOCKETPAIR) || (defined (HAS_SOCKET) && defined(SOCK_DGRAM) && defined(AF_INET) && defined(PF_INET))
dSP;
- GV *gv1;
- GV *gv2;
- register IO *io1;
- register IO *io2;
- int protocol = POPi;
- int type = POPi;
- int domain = POPi;
+ const int protocol = POPi;
+ const int type = POPi;
+ const int domain = POPi;
+ GV * const gv2 = (GV*)POPs;
+ GV * const gv1 = (GV*)POPs;
+ register IO * const io1 = gv1 ? GvIOn(gv1) : NULL;
+ register IO * const io2 = gv2 ? GvIOn(gv2) : NULL;
int fd[2];
- gv2 = (GV*)POPs;
- gv1 = (GV*)POPs;
- io1 = gv1 ? GvIOn(gv1) : NULL;
- io2 = gv2 ? GvIOn(gv2) : NULL;
if (!gv1 || !gv2 || !io1 || !io2) {
if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) {
if (!gv1 || !io1)
extern void GETPRIVMODE();
extern void GETUSERMODE();
#endif
- SV *addrsv = POPs;
+ SV * const addrsv = POPs;
/* OK, so on what platform does bind modify addr? */
const char *addr;
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
STRLEN len;
int bind_ok = 0;
#ifdef MPE
{
#ifdef HAS_SOCKET
dSP;
- SV *addrsv = POPs;
+ SV * const addrsv = POPs;
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
const char *addr;
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
STRLEN len;
if (!io || !IoIFP(io))
{
#ifdef HAS_SOCKET
dSP;
- int backlog = POPi;
- GV *gv = (GV*)POPs;
- register IO *io = gv ? GvIOn(gv) : NULL;
+ const int backlog = POPi;
+ GV * const gv = (GV*)POPs;
+ register IO * const io = gv ? GvIOn(gv) : NULL;
if (!gv || !io || !IoIFP(io))
goto nuts;
{
#ifdef HAS_SOCKET
dSP; dTARGET;
- GV *ngv;
- GV *ggv;
register IO *nstio;
register IO *gstio;
char namebuf[MAXPATHLEN];
#else
Sock_size_t len = sizeof namebuf;
#endif
+ GV * const ggv = (GV*)POPs;
+ GV * const ngv = (GV*)POPs;
int fd;
- ggv = (GV*)POPs;
- ngv = (GV*)POPs;
-
if (!ngv)
goto badexit;
if (!ggv)
{
#ifdef HAS_SOCKET
dSP; dTARGET;
- int how = POPi;
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
+ const int how = POPi;
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
if (!io || !IoIFP(io))
goto nuts;
{
#ifdef HAS_SOCKET
dSP;
- int optype = PL_op->op_type;
- SV *sv;
+ const int optype = PL_op->op_type;
+ SV * const sv = (optype == OP_GSOCKOPT) ? sv_2mortal(NEWSV(22, 257)) : POPs;
+ const unsigned int optname = (unsigned int) POPi;
+ const unsigned int lvl = (unsigned int) POPi;
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
int fd;
- unsigned int optname;
- unsigned int lvl;
- GV *gv;
- register IO *io;
Sock_size_t len;
- if (optype == OP_GSOCKOPT)
- sv = sv_2mortal(NEWSV(22, 257));
- else
- sv = POPs;
- optname = (unsigned int) POPi;
- lvl = (unsigned int) POPi;
-
- gv = (GV*)POPs;
- io = GvIOn(gv);
if (!io || !IoIFP(io))
goto nuts;
{
#ifdef HAS_SOCKET
dSP;
- int optype = PL_op->op_type;
+ const int optype = PL_op->op_type;
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
+ Sock_size_t len;
SV *sv;
int fd;
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
- Sock_size_t len;
if (!io || !IoIFP(io))
goto nuts;
}
}
else {
- SV* sv = POPs;
+ SV* const sv = POPs;
if (SvTYPE(sv) == SVt_PVGV) {
gv = (GV*)sv;
goto do_fstat;
{
#ifdef HAS_CHROOT
dSP; dTARGET;
- char *tmps = POPpx;
+ char * const tmps = POPpx;
TAINT_PROPER("chroot");
PUSHi( chroot(tmps) >= 0 );
RETURN;
{
dSP; dTARGET;
int anum;
- const char *tmps2 = POPpconstx;
- const char *tmps = SvPV_nolen_const(TOPs);
+ const char * const tmps2 = POPpconstx;
+ const char * const tmps = SvPV_nolen_const(TOPs);
TAINT_PROPER("rename");
#ifdef HAS_RENAME
anum = PerlLIO_rename(tmps, tmps2);
# endif
{
- const char *tmps2 = POPpconstx;
- const char *tmps = SvPV_nolen_const(TOPs);
+ const char * const tmps2 = POPpconstx;
+ const char * const tmps = SvPV_nolen_const(TOPs);
TAINT_PROPER(PL_op_desc[op_type]);
result =
# if defined(HAS_LINK)
Safefree(cmdline);
if (myfp) {
- SV *tmpsv = sv_newmortal();
+ SV * const tmpsv = sv_newmortal();
/* Need to save/restore 'PL_rs' ?? */
s = sv_gets(tmpsv, myfp, 0);
(void)PerlProc_pclose(myfp);
PP(pp_mkdir)
{
dSP; dTARGET;
- int mode;
-#ifndef HAS_MKDIR
- int oldumask;
-#endif
STRLEN len;
const char *tmps;
bool copy = FALSE;
-
- if (MAXARG > 1)
- mode = POPi;
- else
- mode = 0777;
+ const int mode = (MAXARG > 1) ? POPi : 0777;
TRIMSLASHES(tmps,len,copy);
#ifdef HAS_MKDIR
SETi( PerlDir_mkdir(tmps, mode) >= 0 );
#else
+ {
+ int oldumask;
SETi( dooneliner("mkdir", tmps) );
oldumask = PerlLIO_umask(0);
PerlLIO_umask(oldumask);
PerlLIO_chmod(tmps, (mode & ~oldumask) & 0777);
+ }
#endif
if (copy)
Safefree(tmps);
{
#if defined(Direntry_t) && defined(HAS_READDIR)
dSP;
- const char *dirname = POPpconstx;
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
+ const char * const dirname = POPpconstx;
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
if (!io)
goto nope;
SV *sv;
const I32 gimme = GIMME;
- GV *gv = (GV *)POPs;
- register Direntry_t *dp;
- register IO *io = GvIOn(gv);
+ GV * const gv = (GV *)POPs;
+ register const Direntry_t *dp;
+ register IO * const io = GvIOn(gv);
if (!io || !IoDIRP(io))
goto nope;
# if !defined(HAS_TELLDIR_PROTO) || defined(NEED_TELLDIR_PROTO)
long telldir (DIR *);
# endif
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
if (!io || !IoDIRP(io))
goto nope;
{
#if defined(HAS_SEEKDIR) || defined(seekdir)
dSP;
- long along = POPl;
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
+ const long along = POPl;
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
if (!io || !IoDIRP(io))
goto nope;
{
#if defined(HAS_REWINDDIR) || defined(rewinddir)
dSP;
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
if (!io || !IoDIRP(io))
goto nope;
{
#if defined(Direntry_t) && defined(HAS_READDIR)
dSP;
- GV *gv = (GV*)POPs;
- register IO *io = GvIOn(gv);
+ GV * const gv = (GV*)POPs;
+ register IO * const io = GvIOn(gv);
if (!io || !IoDIRP(io))
goto nope;
#ifdef HAS_FORK
dSP; dTARGET;
Pid_t childpid;
- GV *tmpgv;
EXTEND(SP, 1);
PERL_FLUSHALL_FOR_CHILD;
if (childpid < 0)
RETSETUNDEF;
if (!childpid) {
- if ((tmpgv = gv_fetchpv("$", TRUE, SVt_PV))) {
+ GV * const tmpgv = gv_fetchpv("$", TRUE, SVt_PV);
+ if (tmpgv) {
SvREADONLY_off(GvSV(tmpgv));
sv_setiv(GvSV(tmpgv), (IV)PerlProc_getpid());
SvREADONLY_on(GvSV(tmpgv));
{
#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL)
dSP; dTARGET;
- Pid_t pid;
+ const int optype = POPi;
+ const Pid_t pid = TOPi;
Pid_t result;
- int optype;
int argflags;
- optype = POPi;
- pid = TOPi;
if (PL_signals & PERL_SIGNALS_UNSAFE_FLAG)
result = wait4pid(pid, &argflags, optype);
else {
#endif
}
if (PL_op->op_flags & OPf_STACKED) {
- SV *really = *++MARK;
+ SV * const really = *++MARK;
value = (I32)do_aexec5(really, MARK, SP, pp[1], did_pipes);
}
else if (SP - MARK != 1)
PL_statusvalue = 0;
result = 0;
if (PL_op->op_flags & OPf_STACKED) {
- SV *really = *++MARK;
+ SV * const really = *++MARK;
# if defined(WIN32) || defined(OS2) || defined(__SYMBIAN32__)
value = (I32)do_aspawn(really, MARK, SP);
# else
}
PERL_FLUSHALL_FOR_CHILD;
if (PL_op->op_flags & OPf_STACKED) {
- SV *really = *++MARK;
+ SV * const really = *++MARK;
value = (I32)do_aexec(really, MARK, SP);
}
else if (SP - MARK != 1)
{
#ifdef HAS_GETPGRP
dSP; dTARGET;
- Pid_t pid;
Pid_t pgrp;
+ const Pid_t pid = (MAXARG < 1) ? 0 : SvIVx(POPs);
- if (MAXARG < 1)
- pid = 0;
- else
- pid = SvIVx(POPs);
#ifdef BSD_GETPGRP
pgrp = (I32)BSD_GETPGRP(pid);
#else
{
#ifdef HAS_GETPRIORITY
dSP; dTARGET;
- int who = POPi;
- int which = TOPi;
+ const int who = POPi;
+ const int which = TOPi;
SETi( getpriority(which, who) );
RETURN;
#else
{
#ifdef HAS_SETPRIORITY
dSP; dTARGET;
- int niceval = POPi;
- int who = POPi;
- int which = TOPi;
+ const int niceval = POPi;
+ const int who = POPi;
+ const int which = TOPi;
TAINT_PROPER("setpriority");
SETi( setpriority(which, who, niceval) >= 0 );
RETURN;
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
dSP; dMARK; dTARGET;
- int anum = do_ipcget(PL_op->op_type, MARK, SP);
+ const int anum = do_ipcget(PL_op->op_type, MARK, SP);
SP = MARK;
if (anum == -1)
RETPUSHUNDEF;
{
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
dSP; dMARK; dTARGET;
- int anum = do_ipcctl(PL_op->op_type, MARK, SP);
+ const int anum = do_ipcctl(PL_op->op_type, MARK, SP);
SP = MARK;
if (anum == -1)
RETSETUNDEF;
EXTEND(SP, 10);
if (which == OP_GHBYNAME) {
#ifdef HAS_GETHOSTBYNAME
- char* name = POPpbytex;
+ const char* const name = POPpbytex;
hent = PerlSock_gethostbyname(name);
#else
DIE(aTHX_ PL_no_sock_func, "gethostbyname");
}
else if (which == OP_GHBYADDR) {
#ifdef HAS_GETHOSTBYADDR
- int addrtype = POPi;
- SV *addrsv = POPs;
+ const int addrtype = POPi;
+ SV * const addrsv = POPs;
STRLEN addrlen;
Netdb_host_t addr = (Netdb_host_t) SvPVbyte(addrsv, addrlen);
if (which == OP_GNBYNAME){
#ifdef HAS_GETNETBYNAME
- char *name = POPpbytex;
+ const char * const name = POPpbytex;
nent = PerlSock_getnetbyname(name);
#else
DIE(aTHX_ PL_no_sock_func, "getnetbyname");
}
else if (which == OP_GNBYADDR) {
#ifdef HAS_GETNETBYADDR
- int addrtype = POPi;
- Netdb_net_t addr = (Netdb_net_t) (U32)POPu;
+ const int addrtype = POPi;
+ const Netdb_net_t addr = (Netdb_net_t) (U32)POPu;
nent = PerlSock_getnetbyaddr(addr, addrtype);
#else
DIE(aTHX_ PL_no_sock_func, "getnetbyaddr");
if (which == OP_GPBYNAME) {
#ifdef HAS_GETPROTOBYNAME
- char* name = POPpbytex;
+ const char* const name = POPpbytex;
pent = PerlSock_getprotobyname(name);
#else
DIE(aTHX_ PL_no_sock_func, "getprotobyname");
}
else if (which == OP_GPBYNUMBER) {
#ifdef HAS_GETPROTOBYNUMBER
- int number = POPi;
+ const int number = POPi;
pent = PerlSock_getprotobynumber(number);
#else
DIE(aTHX_ PL_no_sock_func, "getprotobynumber");
if (which == OP_GSBYNAME) {
#ifdef HAS_GETSERVBYNAME
- char *proto = POPpbytex;
- char *name = POPpbytex;
-
- if (proto && !*proto)
- proto = Nullch;
-
- sent = PerlSock_getservbyname(name, proto);
+ const char * const proto = POPpbytex;
+ const char * const name = POPpbytex;
+ sent = PerlSock_getservbyname(name, (proto && !*proto) ? Nullch : proto);
#else
DIE(aTHX_ PL_no_sock_func, "getservbyname");
#endif
}
else if (which == OP_GSBYPORT) {
#ifdef HAS_GETSERVBYPORT
- char *proto = POPpbytex;
+ const char * const proto = POPpbytex;
unsigned short port = (unsigned short)POPu;
-
- if (proto && !*proto)
- proto = Nullch;
-
#ifdef HAS_HTONS
port = PerlSock_htons(port);
#endif
- sent = PerlSock_getservbyport(port, proto);
+ sent = PerlSock_getservbyport(port, (proto && !*proto) ? Nullch : proto);
#else
DIE(aTHX_ PL_no_sock_func, "getservbyport");
#endif
switch (which) {
case OP_GPWNAM:
{
- char* name = POPpbytex;
+ const char* const name = POPpbytex;
pwent = getpwnam(name);
}
break;
* has a different API than the Solaris/IRIX one. */
# if defined(HAS_GETSPNAM) && !defined(_AIX)
{
- struct spwd *spwent;
- int saverrno; /* Save and restore errno so that
+ const int saverrno = errno;
+ const struct spwd * const spwent = getspnam(pwent->pw_name);
+ /* Save and restore errno so that
* underprivileged attempts seem
* to have never made the unsccessful
* attempt to retrieve the shadow password. */
-
- saverrno = errno;
- spwent = getspnam(pwent->pw_name);
errno = saverrno;
if (spwent && spwent->sp_pwdp)
sv_setpv(sv, spwent->sp_pwdp);
struct group *grent;
if (which == OP_GGRNAM) {
- char* name = POPpbytex;
+ const char* const name = POPpbytex;
grent = (struct group *)getgrnam(name);
}
else if (which == OP_GGRGID) {
- Gid_t gid = POPi;
+ const Gid_t gid = POPi;
grent = (struct group *)getgrgid(gid);
}
else
lockf_emulate_flock(int fd, int operation)
{
int i;
- int save_errno;
+ const int save_errno = 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)