summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2004-07-09 19:13:47 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2004-07-09 19:13:47 +0000
commit1b5f8876ef23cb77243b61461ac7342d11382de7 (patch)
tree6247e3e2691a5bef88f1c981784356972c3c7cc3
parent69254579bc244800583df8c73dbb4ec007bec6ea (diff)
Properly detect if a patch already has been applied, even if there
are no eols at eofs involved. Tested by quite some people. ok deraadt@
-rw-r--r--usr.bin/patch/patch.c19
-rw-r--r--usr.bin/patch/pch.c10
2 files changed, 25 insertions, 4 deletions
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 482f5b392e0..7b754871ba9 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: patch.c,v 1.40 2004/06/18 17:52:25 otto Exp $ */
+/* $OpenBSD: patch.c,v 1.41 2004/07/09 19:13:46 otto Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -27,7 +27,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: patch.c,v 1.40 2004/06/18 17:52:25 otto Exp $";
+static const char rcsid[] = "$OpenBSD: patch.c,v 1.41 2004/07/09 19:13:46 otto Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -929,6 +929,21 @@ patch_match(LINENUM base, LINENUM offset, LINENUM fuzz)
return false;
} else if (strnNE(ilineptr, plineptr, plinelen))
return false;
+ if (iline == input_lines) {
+ /*
+ * We are looking at the last line of the file.
+ * If the file has no eol, the patch line should
+ * not have one either and vice-versa. Note that
+ * plinelen > 0.
+ */
+ if (last_line_missing_eol) {
+ if (plineptr[plinelen - 1] == '\n')
+ return false;
+ } else {
+ if (plineptr[plinelen - 1] != '\n')
+ return false;
+ }
+ }
}
return true;
}
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index 55c6e725a47..bfdb1763010 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pch.c,v 1.33 2004/01/28 08:31:07 otto Exp $ */
+/* $OpenBSD: pch.c,v 1.34 2004/07/09 19:13:46 otto Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -27,7 +27,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: pch.c,v 1.33 2004/01/28 08:31:07 otto Exp $";
+static const char rcsid[] = "$OpenBSD: pch.c,v 1.34 2004/07/09 19:13:46 otto Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -967,6 +967,12 @@ hunk_done:
p_end = fillsrc - 1;
return false;
}
+ if (fillsrc > p_ptrn_lines) {
+ if (remove_special_line()) {
+ p_len[fillsrc - 1] -= 1;
+ s[p_len[fillsrc - 1]] = 0;
+ }
+ }
/* FALL THROUGH */
case '+':
if (filldst > p_end) {