summaryrefslogtreecommitdiff
path: root/doio.c
diff options
context:
space:
mode:
authorChip Salzenberg <chip@pobox.com>1998-02-03 04:16:50 -0500
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1998-02-06 14:56:30 +0000
commit85aff5773f2412a54180cc35f86370c56b65bf77 (patch)
tree58aa1481b34d450e99d317950157b92887658fa2 /doio.c
parente1c148c28bf3335bbd0ad9a2070b0917265c00c3 (diff)
downloadperl-85aff5773f2412a54180cc35f86370c56b65bf77.tar.gz
Some Chip patches (some tweaked to match _5x source):
Subject: [PATCH] local leakage Date: Tue, 3 Feb 1998 09:16:50 -0500 (EST) Subject: [PATCH] NULs in patterns Date: Wed, 4 Feb 1998 01:33:51 -0500 (EST) Subject: [PATCH] Configure on PerlIO Date: Wed, 4 Feb 1998 01:38:43 -0500 (EST) Subject: [PATCH] Avoid core dump on package alias Date: Wed, 4 Feb 1998 15:38:42 -0500 (EST) Subject: [PATCH] Fix name of $Foo::{'Bar::'} Date: Wed, 4 Feb 1998 16:37:51 -0500 (EST) p4raw-id: //depot/perl@462
Diffstat (limited to 'doio.c')
-rw-r--r--doio.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/doio.c b/doio.c
index b25bb9c30f..d720f99d04 100644
--- a/doio.c
+++ b/doio.c
@@ -40,12 +40,18 @@
# include <utime.h>
# endif
#endif
+
#ifdef I_FCNTL
#include <fcntl.h>
#endif
#ifdef I_SYS_FILE
#include <sys/file.h>
#endif
+#ifdef O_EXCL
+# define OPEN_EXCL O_EXCL
+#else
+# define OPEN_EXCL 0
+#endif
#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
#include <signal.h>
@@ -381,16 +387,16 @@ nextargv(register GV *gv)
filemode = 0;
while (av_len(GvAV(gv)) >= 0) {
dTHR;
- STRLEN len;
+ STRLEN oldlen;
sv = av_shift(GvAV(gv));
SAVEFREESV(sv);
sv_setsv(GvSV(gv),sv);
SvSETMAGIC(GvSV(gv));
- oldname = SvPVx(GvSV(gv), len);
- if (do_open(gv,oldname,len,FALSE,0,0,Nullfp)) {
+ oldname = SvPVx(GvSV(gv), oldlen);
+ if (do_open(gv,oldname,oldlen,inplace!=0,0,0,Nullfp)) {
if (inplace) {
TAINT_PROPER("inplace open");
- if (strEQ(oldname,"-")) {
+ if (oldlen == 1 && *oldname == '-') {
setdefout(gv_fetchpv("STDOUT",TRUE,SVt_PVIO));
return IoIFP(GvIOp(gv));
}
@@ -439,7 +445,7 @@ nextargv(register GV *gv)
do_close(gv,FALSE);
(void)PerlLIO_unlink(SvPVX(sv));
(void)PerlLIO_rename(oldname,SvPVX(sv));
- do_open(gv,SvPVX(sv),SvCUR(sv),FALSE,0,0,Nullfp);
+ do_open(gv,SvPVX(sv),SvCUR(sv),inplace!=0,0,0,Nullfp);
#endif /* DOSISH */
#else
(void)UNLINK(SvPVX(sv));
@@ -456,8 +462,8 @@ nextargv(register GV *gv)
#if !defined(DOSISH) && !defined(AMIGAOS)
# ifndef VMS /* Don't delete; use automatic file versioning */
if (UNLINK(oldname) < 0) {
- warn("Can't rename %s to %s: %s, skipping file",
- oldname, SvPVX(sv), Strerror(errno) );
+ warn("Can't remove %s: %s, skipping file",
+ oldname, Strerror(errno) );
do_close(gv,FALSE);
continue;
}
@@ -467,10 +473,11 @@ nextargv(register GV *gv)
#endif
}
- sv_setpvn(sv,">",1);
- sv_catpv(sv,oldname);
+ sv_setpvn(sv,">",!inplace);
+ sv_catpvn(sv,oldname,oldlen);
SETERRNO(0,0); /* in case sprintf set errno */
- if (!do_open(argvoutgv,SvPVX(sv),SvCUR(sv),FALSE,0,0,Nullfp)) {
+ if (!do_open(argvoutgv,SvPVX(sv),SvCUR(sv),inplace!=0,
+ O_WRONLY|O_CREAT|OPEN_EXCL,0666,Nullfp)) {
warn("Can't do inplace edit on %s: %s",
oldname, Strerror(errno) );
do_close(gv,FALSE);