diff options
author | 2004-07-09 19:13:46 +0000 | |
---|---|---|
committer | 2004-07-09 19:13:46 +0000 | |
commit | b49ee53909ffa69bbf15c0f37938a7c418433ae8 (patch) | |
tree | 80353d16abc79e832704c9b90d71239fba6427e2 /usr.bin/patch/patch.c | |
parent | brings in a few fixes from NetBSD... (diff) | |
download | wireguard-openbsd-b49ee53909ffa69bbf15c0f37938a7c418433ae8.tar.xz wireguard-openbsd-b49ee53909ffa69bbf15c0f37938a7c418433ae8.zip |
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@
Diffstat (limited to 'usr.bin/patch/patch.c')
-rw-r--r-- | usr.bin/patch/patch.c | 19 |
1 files changed, 17 insertions, 2 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; } |