}
if (as_raw) {
- result = rawmode & 3;
- IoTYPE(io) = "<>++"[result];
+#if defined(O_LARGEFILE)
+ rawmode |= O_LARGEFILE;
+#endif
+
+#ifndef O_ACCMODE
+#define O_ACCMODE 3 /* Assume traditional implementation */
+#endif
+
+ switch (result = rawmode & O_ACCMODE) {
+ case O_RDONLY:
+ IoTYPE(io) = '<';
+ break;
+ case O_WRONLY:
+ IoTYPE(io) = '>';
+ break;
+ case O_RDWR:
+ default:
+ IoTYPE(io) = '+';
+ break;
+ }
+
writing = (result > 0);
fd = PerlLIO_open3(name, rawmode, rawperm);
+
if (fd == -1)
fp = NULL;
else {
char *fpmode;
- if (result == 0)
+ if (result == O_RDONLY)
fpmode = "r";
#ifdef O_APPEND
else if (rawmode & O_APPEND)
- fpmode = (result == 1) ? "a" : "a+";
+ fpmode = (result == O_WRONLY) ? "a" : "a+";
#endif
else
- fpmode = (result == 1) ? "w" : "r+";
+ fpmode = (result == O_WRONLY) ? "w" : "r+";
fp = PerlIO_fdopen(fd, fpmode);
if (!fp)
PerlLIO_close(fd);
TAINT_ENV();
TAINT_PROPER("piped open");
if (name[strlen(name)-1] == '|') {
+ dTHR;
name[strlen(name)-1] = '\0' ;
- if (PL_dowarn)
- warn("Can't do bidirectional pipe");
+ if (ckWARN(WARN_PIPE))
+ warner(WARN_PIPE, "Can't do bidirectional pipe");
}
fp = PerlProc_popen(name,"w");
writing = 1;
}
}
if (!fp) {
- if (PL_dowarn && IoTYPE(io) == '<' && strchr(name, '\n'))
- warn(warn_nl, "open");
+ dTHR;
+ if (ckWARN(WARN_NEWLINE) && IoTYPE(io) == '<' && strchr(name, '\n'))
+ warner(WARN_NEWLINE, PL_warn_nl, "open");
goto say_false;
}
if (IoTYPE(io) &&
#ifdef S_IFMT
!(PL_statbuf.st_mode & S_IFMT)
#else
- !statbuf.st_mode
+ !PL_statbuf.st_mode
#endif
) {
char tmpbuf[256];
PerlIO_clearerr(fp);
}
#if defined(HAS_FCNTL) && defined(F_SETFD)
- fd = PerlIO_fileno(fp);
- fcntl(fd,F_SETFD,fd > PL_maxsysfd);
+ {
+ int save_errno = errno;
+ fd = PerlIO_fileno(fp);
+ fcntl(fd,F_SETFD,fd > PL_maxsysfd); /* can change errno */
+ errno = save_errno;
+ }
#endif
IoIFP(io) = fp;
if (writing) {
#ifdef HAS_FCHMOD
(void)fchmod(PL_lastfd,PL_filemode);
#else
- (void)PerlLIO_chmod(oldname,filemode);
+ (void)PerlLIO_chmod(PL_oldname,PL_filemode);
#endif
}
PL_filemode = 0;
sv_setsv(GvSV(gv),sv);
SvSETMAGIC(GvSV(gv));
PL_oldname = SvPVx(GvSV(gv), oldlen);
- if (do_open(gv,PL_oldname,oldlen,PL_inplace!=0,0,0,Nullfp)) {
+ if (do_open(gv,PL_oldname,oldlen,PL_inplace!=0,O_RDONLY,0,Nullfp)) {
if (PL_inplace) {
TAINT_PROPER("inplace open");
if (oldlen == 1 && *PL_oldname == '-') {
return IoIFP(GvIOp(gv));
}
#ifndef FLEXFILENAMES
- filedev = statbuf.st_dev;
- fileino = statbuf.st_ino;
+ filedev = PL_statbuf.st_dev;
+ fileino = PL_statbuf.st_ino;
#endif
PL_filemode = PL_statbuf.st_mode;
fileuid = PL_statbuf.st_uid;
sv_catpv(sv,PL_inplace);
}
#ifndef FLEXFILENAMES
- if (PerlLIO_stat(SvPVX(sv),&statbuf) >= 0
- && statbuf.st_dev == filedev
- && statbuf.st_ino == fileino
+ if (PerlLIO_stat(SvPVX(sv),&PL_statbuf) >= 0
+ && PL_statbuf.st_dev == filedev
+ && PL_statbuf.st_ino == fileino
#ifdef DJGPP
|| (_djstat_fail_bits & _STFAIL_TRUENAME)!=0
#endif
#else
do_close(gv,FALSE);
(void)PerlLIO_unlink(SvPVX(sv));
- (void)PerlLIO_rename(oldname,SvPVX(sv));
- do_open(gv,SvPVX(sv),SvCUR(sv),inplace!=0,0,0,Nullfp);
+ (void)PerlLIO_rename(PL_oldname,SvPVX(sv));
+ do_open(gv,SvPVX(sv),SvCUR(sv),PL_inplace!=0,O_RDONLY,0,Nullfp);
#endif /* DOSISH */
#else
(void)UNLINK(SvPVX(sv));
- if (link(oldname,SvPVX(sv)) < 0) {
+ if (link(PL_oldname,SvPVX(sv)) < 0) {
warn("Can't rename %s to %s: %s, skipping file",
- oldname, SvPVX(sv), Strerror(errno) );
+ PL_oldname, SvPVX(sv), Strerror(errno) );
do_close(gv,FALSE);
continue;
}
- (void)UNLINK(oldname);
+ (void)UNLINK(PL_oldname);
#endif
}
else {
sv_setpvn(sv,">",!PL_inplace);
sv_catpvn(sv,PL_oldname,oldlen);
SETERRNO(0,0); /* in case sprintf set errno */
+#ifdef VMS
+ if (!do_open(PL_argvoutgv,SvPVX(sv),SvCUR(sv),PL_inplace!=0,
+ O_WRONLY|O_CREAT|O_TRUNC,0,Nullfp)) {
+#else
if (!do_open(PL_argvoutgv,SvPVX(sv),SvCUR(sv),PL_inplace!=0,
O_WRONLY|O_CREAT|OPEN_EXCL,0666,Nullfp)) {
+#endif
warn("Can't do inplace edit on %s: %s",
PL_oldname, Strerror(errno) );
do_close(gv,FALSE);
#else
# if !(defined(WIN32) && defined(__BORLANDC__))
/* Borland runtime creates a readonly file! */
- (void)PerlLIO_chmod(oldname,filemode);
+ (void)PerlLIO_chmod(PL_oldname,PL_filemode);
# endif
#endif
if (fileuid != PL_statbuf.st_uid || filegid != PL_statbuf.st_gid) {
(void)fchown(PL_lastfd,fileuid,filegid);
#else
#ifdef HAS_CHOWN
- (void)PerlLIO_chown(oldname,fileuid,filegid);
+ (void)PerlLIO_chown(PL_oldname,fileuid,filegid);
#endif
#endif
}
}
else
PerlIO_printf(PerlIO_stderr(), "Can't open %s: %s\n",
- SvPV(sv, PL_na), Strerror(errno));
+ SvPV(sv, oldlen), Strerror(errno));
}
if (PL_inplace) {
(void)do_close(PL_argvoutgv,FALSE);
io = GvIO(gv);
if (!io) { /* never opened */
if (not_implicit) {
- if (PL_dowarn)
- warn("Close on unopened file <%s>",GvENAME(gv));
+ dTHR;
+ if (ckWARN(WARN_UNOPENED))
+ warner(WARN_UNOPENED,
+ "Close on unopened file <%s>",GvENAME(gv));
SETERRNO(EBADF,SS$_IVCHAN);
}
return FALSE;
return TRUE;
}
-long
+Off_t
do_tell(GV *gv)
{
register IO *io;
#endif
return PerlIO_tell(fp);
}
- if (PL_dowarn)
- warn("tell() on unopened file");
+ {
+ dTHR;
+ if (ckWARN(WARN_UNOPENED))
+ warner(WARN_UNOPENED, "tell() on unopened file");
+ }
SETERRNO(EBADF,RMS$_IFI);
- return -1L;
+ return (Off_t)-1;
}
bool
-do_seek(GV *gv, long int pos, int whence)
+do_seek(GV *gv, Off_t pos, int whence)
{
register IO *io;
register PerlIO *fp;
#endif
return PerlIO_seek(fp, pos, whence) >= 0;
}
- if (PL_dowarn)
- warn("seek() on unopened file");
+ {
+ dTHR;
+ if (ckWARN(WARN_UNOPENED))
+ warner(WARN_UNOPENED, "seek() on unopened file");
+ }
SETERRNO(EBADF,RMS$_IFI);
return FALSE;
}
-long
-do_sysseek(GV *gv, long int pos, int whence)
+Off_t
+do_sysseek(GV *gv, Off_t pos, int whence)
{
register IO *io;
register PerlIO *fp;
if (gv && (io = GvIO(gv)) && (fp = IoIFP(io)))
return PerlLIO_lseek(PerlIO_fileno(fp), pos, whence);
- if (PL_dowarn)
- warn("sysseek() on unopened file");
+ {
+ dTHR;
+ if (ckWARN(WARN_UNOPENED))
+ warner(WARN_UNOPENED, "sysseek() on unopened file");
+ }
SETERRNO(EBADF,RMS$_IFI);
return -1L;
}
}
switch (SvTYPE(sv)) {
case SVt_NULL:
- if (PL_dowarn)
- warn(warn_uninit);
+ {
+ dTHR;
+ if (ckWARN(WARN_UNINITIALIZED))
+ warner(WARN_UNINITIALIZED, PL_warn_uninit);
+ }
return TRUE;
case SVt_IV:
if (SvIOK(sv)) {
else {
if (tmpgv == PL_defgv)
return PL_laststatval;
- if (PL_dowarn)
- warn("Stat on unopened file <%s>",
+ if (ckWARN(WARN_UNOPENED))
+ warner(WARN_UNOPENED, "Stat on unopened file <%s>",
GvENAME(tmpgv));
PL_statgv = Nullgv;
sv_setpv(PL_statname,"");
else {
SV* sv = POPs;
char *s;
+ STRLEN n_a;
PUTBACK;
if (SvTYPE(sv) == SVt_PVGV) {
tmpgv = (GV*)sv;
goto do_fstat;
}
- s = SvPV(sv, PL_na);
+ s = SvPV(sv, n_a);
PL_statgv = Nullgv;
sv_setpv(PL_statname, s);
PL_laststype = OP_STAT;
PL_laststatval = PerlLIO_stat(s, &PL_statcache);
- if (PL_laststatval < 0 && PL_dowarn && strchr(s, '\n'))
- warn(warn_nl, "stat");
+ if (PL_laststatval < 0 && ckWARN(WARN_NEWLINE) && strchr(s, '\n'))
+ warner(WARN_NEWLINE, PL_warn_nl, "stat");
return PL_laststatval;
}
}
{
djSP;
SV *sv;
+ STRLEN n_a;
if (PL_op->op_flags & OPf_REF) {
EXTEND(SP,1);
if (cGVOP->op_gv == PL_defgv) {
PL_statgv = Nullgv;
sv = POPs;
PUTBACK;
- sv_setpv(PL_statname,SvPV(sv, PL_na));
+ sv_setpv(PL_statname,SvPV(sv, n_a));
#ifdef HAS_LSTAT
- PL_laststatval = PerlLIO_lstat(SvPV(sv, PL_na),&PL_statcache);
+ PL_laststatval = PerlLIO_lstat(SvPV(sv, n_a),&PL_statcache);
#else
- laststatval = PerlLIO_stat(SvPV(sv, na),&statcache);
+ PL_laststatval = PerlLIO_stat(SvPV(sv, n_a),&PL_statcache);
#endif
- if (PL_laststatval < 0 && PL_dowarn && strchr(SvPV(sv, PL_na), '\n'))
- warn(warn_nl, "lstat");
+ if (PL_laststatval < 0 && ckWARN(WARN_NEWLINE) && strchr(SvPV(sv, n_a), '\n'))
+ warner(WARN_NEWLINE, PL_warn_nl, "lstat");
return PL_laststatval;
}
{
register char **a;
char *tmps;
+ STRLEN n_a;
if (sp > mark) {
dTHR;
a = PL_Argv;
while (++mark <= sp) {
if (*mark)
- *a++ = SvPVx(*mark, PL_na);
+ *a++ = SvPVx(*mark, n_a);
else
*a++ = "";
}
*a = Nullch;
if (*PL_Argv[0] != '/') /* will execvp use PATH? */
TAINT_ENV(); /* testing IFS here is overkill, probably */
- if (really && *(tmps = SvPV(really, PL_na)))
+ if (really && *(tmps = SvPV(really, n_a)))
PerlProc_execvp(tmps,PL_Argv);
else
PerlProc_execvp(PL_Argv[0],PL_Argv);
- if (PL_dowarn)
- warn("Can't exec \"%s\": %s", PL_Argv[0], Strerror(errno));
+ if (ckWARN(WARN_EXEC))
+ warner(WARN_EXEC, "Can't exec \"%s\": %s",
+ PL_Argv[0], Strerror(errno));
}
do_execfree();
return FALSE;
do_execfree();
goto doshell;
}
- if (PL_dowarn)
- warn("Can't exec \"%s\": %s", PL_Argv[0], Strerror(errno));
+ {
+ dTHR;
+ if (ckWARN(WARN_EXEC))
+ warner(WARN_EXEC, "Can't exec \"%s\": %s",
+ PL_Argv[0], Strerror(errno));
+ }
}
do_execfree();
return FALSE;
char *what;
char *s;
SV **oldmark = mark;
+ STRLEN n_a;
#define APPLY_TAINT_PROPER() \
STMT_START { \
APPLY_TAINT_PROPER();
tot = sp - mark;
while (++mark <= sp) {
- char *name = SvPVx(*mark, PL_na);
+ char *name = SvPVx(*mark, n_a);
APPLY_TAINT_PROPER();
if (PerlLIO_chmod(name, val))
tot--;
APPLY_TAINT_PROPER();
tot = sp - mark;
while (++mark <= sp) {
- char *name = SvPVx(*mark, PL_na);
+ char *name = SvPVx(*mark, n_a);
APPLY_TAINT_PROPER();
if (PerlLIO_chown(name, val, val2))
tot--;
APPLY_TAINT_PROPER();
if (mark == sp)
break;
- s = SvPVx(*++mark, PL_na);
+ s = SvPVx(*++mark, n_a);
if (isUPPER(*s)) {
if (*s == 'S' && s[1] == 'I' && s[2] == 'G')
s += 3;
APPLY_TAINT_PROPER();
tot = sp - mark;
while (++mark <= sp) {
- s = SvPVx(*mark, PL_na);
+ s = SvPVx(*mark, n_a);
APPLY_TAINT_PROPER();
if (PL_euid || PL_unsafe) {
if (UNLINK(s))
#ifdef HAS_LSTAT
if (PerlLIO_lstat(s,&PL_statbuf) < 0 || S_ISDIR(PL_statbuf.st_mode))
#else
- if (PerlLIO_stat(s,&statbuf) < 0 || S_ISDIR(statbuf.st_mode))
+ if (PerlLIO_stat(s,&PL_statbuf) < 0 || S_ISDIR(PL_statbuf.st_mode))
#endif
tot--;
else {
APPLY_TAINT_PROPER();
tot = sp - mark;
while (++mark <= sp) {
- char *name = SvPVx(*mark, PL_na);
+ char *name = SvPVx(*mark, n_a);
APPLY_TAINT_PROPER();
if (PerlLIO_utime(name, &utbuf))
tot--;
#endif
#if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM)
default:
- croak("%s not implemented", op_desc[optype]);
+ croak("%s not implemented", PL_op_desc[optype]);
#endif
}
return -1; /* should never happen */
#endif
#if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM)
default:
- croak("%s not implemented", op_desc[optype]);
+ croak("%s not implemented", PL_op_desc[optype]);
#endif
}
a = SvPV(astr, len);
if (len != infosize)
croak("Bad arg length for %s, is %lu, should be %ld",
- op_desc[optype], (unsigned long)len, (long)infosize);
+ PL_op_desc[optype],
+ (unsigned long)len,
+ (long)infosize);
}
}
else