X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=doio.c;h=1719bf16c1464e73fa1aa0d6de56c755bf3f6d12;hb=47cadb06ccb7dbe87fdda243544a1ecb06fb104f;hp=85d604bc0385ffb8a701ce43780860f3722d7cca;hpb=9d116dd7c895b17badf4ad422ae44da0c4df7bc2;p=p5sagit%2Fp5-mst-13.2.git diff --git a/doio.c b/doio.c index 85d604b..1719bf1 100644 --- a/doio.c +++ b/doio.c @@ -125,9 +125,14 @@ do_open(GV *gv, register char *name, I32 len, int as_raw, int rawmode, int rawpe } if (as_raw) { +#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) = '<'; @@ -183,13 +188,21 @@ do_open(GV *gv, register char *name, I32 len, int as_raw, int rawmode, int rawpe if (*name == '|') { /*SUPPRESS 530*/ for (name++; isSPACE(*name); name++) ; + if (*name == '\0') { /* command is missing 19990114 */ + dTHR; + if (ckWARN(WARN_PIPE)) + warner(WARN_PIPE, "Missing command in piped open"); + errno = EPIPE; + goto say_false; + } if (strNE(name,"-")) 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; @@ -279,6 +292,13 @@ do_open(GV *gv, register char *name, I32 len, int as_raw, int rawmode, int rawpe name[--len] = '\0'; /*SUPPRESS 530*/ for (; isSPACE(*name); name++) ; + if (*name == '\0') { /* command is missing 19990114 */ + dTHR; + if (ckWARN(WARN_PIPE)) + warner(WARN_PIPE, "Missing command in piped open"); + errno = EPIPE; + goto say_false; + } if (strNE(name,"-")) TAINT_ENV(); TAINT_PROPER("piped open"); @@ -298,8 +318,9 @@ do_open(GV *gv, register char *name, I32 len, int as_raw, int rawmode, int rawpe } } 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) && @@ -359,8 +380,12 @@ do_open(GV *gv, register char *name, I32 len, int as_raw, int rawmode, int rawpe 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) { @@ -459,7 +484,7 @@ nextargv(register GV *gv) || (_djstat_fail_bits & _STFAIL_TRUENAME)!=0 #endif ) { - warn("Can't do inplace edit: %s would not be uniq", + warn("Can't do inplace edit: %s would not be unique", SvPVX(sv) ); do_close(gv,FALSE); continue; @@ -545,7 +570,7 @@ nextargv(register GV *gv) } 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); @@ -616,8 +641,10 @@ do_close(GV *gv, bool not_implicit) 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; @@ -701,7 +728,7 @@ do_eof(GV *gv) return TRUE; } -long +Off_t do_tell(GV *gv) { register IO *io; @@ -714,14 +741,17 @@ do_tell(GV *gv) #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; @@ -733,22 +763,28 @@ do_seek(GV *gv, long int pos, int whence) #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; } @@ -759,7 +795,7 @@ do_binmode(PerlIO *fp, int iotype, int flag) if (flag != TRUE) croak("panic: unsetting binmode"); /* Not implemented yet */ #ifdef DOSISH -#ifdef atarist +#if defined(atarist) || defined(__MINT__) if (!PerlIO_flush(fp) && (fp->_flag |= _IOBIN)) return 1; else @@ -868,8 +904,11 @@ do_print(register SV *sv, PerlIO *fp) } 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)) { @@ -909,8 +948,8 @@ my_stat(ARGSproto) 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,""); @@ -920,6 +959,7 @@ my_stat(ARGSproto) else { SV* sv = POPs; char *s; + STRLEN n_a; PUTBACK; if (SvTYPE(sv) == SVt_PVGV) { tmpgv = (GV*)sv; @@ -930,13 +970,13 @@ my_stat(ARGSproto) 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; } } @@ -946,6 +986,7 @@ my_lstat(ARGSproto) { djSP; SV *sv; + STRLEN n_a; if (PL_op->op_flags & OPf_REF) { EXTEND(SP,1); if (cGVOP->op_gv == PL_defgv) { @@ -960,14 +1001,14 @@ my_lstat(ARGSproto) 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 - PL_laststatval = PerlLIO_stat(SvPV(sv, PL_na),&PL_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; } @@ -976,6 +1017,7 @@ do_aexec(SV *really, register SV **mark, register SV **sp) { register char **a; char *tmps; + STRLEN n_a; if (sp > mark) { dTHR; @@ -983,19 +1025,20 @@ do_aexec(SV *really, register SV **mark, register SV **sp) 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; @@ -1097,8 +1140,12 @@ do_exec(char *cmd) 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; @@ -1116,10 +1163,11 @@ apply(I32 type, register SV **mark, register SV **sp) char *what; char *s; SV **oldmark = mark; + STRLEN n_a; #define APPLY_TAINT_PROPER() \ STMT_START { \ - if (PL_tainting && PL_tainted) { goto taint_proper_label; } \ + if (PL_tainted) { TAINT_PROPER(what); } \ } STMT_END /* This is a first heuristic; it doesn't catch tainting magic. */ @@ -1141,7 +1189,7 @@ apply(I32 type, register SV **mark, register SV **sp) 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--; @@ -1158,7 +1206,7 @@ apply(I32 type, register SV **mark, register SV **sp) 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--; @@ -1178,7 +1226,7 @@ nothing in the core. 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; @@ -1248,7 +1296,7 @@ nothing in the core. 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)) @@ -1293,7 +1341,7 @@ nothing in the core. 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--; @@ -1306,10 +1354,6 @@ nothing in the core. } return tot; - taint_proper_label: - TAINT_PROPER(what); - return 0; /* this should never happen */ - #undef APPLY_TAINT_PROPER } @@ -1418,7 +1462,7 @@ do_ipcget(I32 optype, SV **mark, SV **sp) #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 */ @@ -1475,7 +1519,7 @@ do_ipcctl(I32 optype, SV **mark, SV **sp) #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 } @@ -1492,7 +1536,9 @@ do_ipcctl(I32 optype, SV **mark, SV **sp) 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