Add handling for any nil-length string passed to -i for the backup extension.

Add a note that this is kinda-sorta dangerous to the manual page.
This commit is contained in:
Juli Mallett
2002-05-07 23:32:26 +00:00
parent 2fa9c646bb
commit 5d16412db7
2 changed files with 21 additions and 2 deletions
+14 -2
View File
@@ -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)
+7
View File
@@ -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.