unifdef's -M option is like sed's -i option, editing in-place and saving
a backup with the supplied extension.
Currently, if -M '' is passed:
* the original file is copied to the backup filename (i.e. itself)
* the temp file is copied to the original filename
It therefore has the same behavior as sed -i ''. However, this
is brittle and maybe even inadvertent. It's also undocumented.
The below diff:
* adds a sentence from sed(1) to the man page
* only creates a backup file when it's actually a backup file (no nop
copying)
Am I understanding correctly? ok?
Index: unifdef.1
===================================================================
RCS file: /cvs/src/usr.bin/unifdef/unifdef.1,v
retrieving revision 1.24
diff -u -p -r1.24 unifdef.1
--- unifdef.1 12 Sep 2015 15:27:38 -0000 1.24
+++ unifdef.1 2 Dec 2015 04:44:15 -0000
@@ -312,6 +312,9 @@ Modify input files in place, and keep ba
appending the
.Ar backext
to the input filenames.
+If a zero length
+.Ar extension
+is given, no backup will be saved.
.Pp
.It Fl m
Modify one or more input files in place.
Index: unifdef.c
===================================================================
RCS file: /cvs/src/usr.bin/unifdef/unifdef.c,v
retrieving revision 1.24
diff -u -p -r1.24 unifdef.c
--- unifdef.c 9 Oct 2015 01:37:09 -0000 1.24
+++ unifdef.c 2 Dec 2015 04:44:15 -0000
@@ -425,7 +425,7 @@ processinout(const char *ifn, const char
process();
- if (backext != NULL) {
+ if (backext != NULL && *backext != '\0') {
char *backname = astrcat(ofn, backext);
if (rename(ofn, backname) < 0)
err(2, "can't rename \"%s\" to \"%s\"", ofn, backname);