aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/sed
diff options
context:
space:
mode:
authorJuli Mallett <jmallett@FreeBSD.org>2002-05-07 23:32:26 +0000
committerJuli Mallett <jmallett@FreeBSD.org>2002-05-07 23:32:26 +0000
commit5d16412db7a1314d1f7b984a365066dbcfb54ce3 (patch)
tree218affa9c0831cab1cb3d31d7389c36caa49d159 /usr.bin/sed
parent2fa9c646bb56a71d4825a4161db010409d23f921 (diff)
downloadsrc-5d16412db7a1314d1f7b984a365066dbcfb54ce3.tar.gz
src-5d16412db7a1314d1f7b984a365066dbcfb54ce3.zip
Notes
Diffstat (limited to 'usr.bin/sed')
-rw-r--r--usr.bin/sed/main.c16
-rw-r--r--usr.bin/sed/sed.17
2 files changed, 21 insertions, 2 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index b4c0916dc6fd..812f62e100e1 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -320,6 +320,8 @@ mf_fgets(sp, spflag)
fname = files->fname;
if ((f = fopen(fname, "r")) == NULL)
err(1, "%s", fname);
+ if (inplace != NULL && *inplace == '\0')
+ unlink(fname);
}
if ((c = getc(f)) != EOF) {
(void)ungetc(c, f);
@@ -366,6 +368,8 @@ mf_fgets(sp, spflag)
fname = files->fname;
if ((f = fopen(fname, "r")) == NULL)
err(1, "%s", fname);
+ if (inplace != NULL && *inplace == '\0')
+ unlink(fname);
}
}
(void)ungetc(c, f);
@@ -427,8 +431,16 @@ inplace_edit(filename)
return -1;
}
- strlcpy(backup, *filename, MAXPATHLEN);
- strlcat(backup, inplace, MAXPATHLEN);
+ if (*inplace == '\0') {
+ char template[] = "/tmp/sed.XXXXXXXXXX";
+
+ if (mktemp(template) == NULL)
+ err(1, "mktemp");
+ strlcpy(backup, template, MAXPATHLEN);
+ } else {
+ strlcpy(backup, *filename, MAXPATHLEN);
+ strlcat(backup, inplace, MAXPATHLEN);
+ }
input = open(*filename, O_RDONLY);
if (input == -1)
diff --git a/usr.bin/sed/sed.1 b/usr.bin/sed/sed.1
index 4005463d2230..e7bd8b252b18 100644
--- a/usr.bin/sed/sed.1
+++ b/usr.bin/sed/sed.1
@@ -102,6 +102,13 @@ The editing commands should each be listed on a separate line.
.It Fl i Ar extension
Edit files in-place, saving backups with the specified
.Ar extension .
+If a zero-length
+.Ar extension
+is given, no backup will be saved.
+It is not recommended to give a zero-length
+.Ar extension
+when in-place editing files, as you risk corruption or partial content
+in situations where disk space is exhausted, etc.
.It Fl n
By default, each line of input is echoed to the standard output after
all of the commands have been applied to it.