diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-07-09 19:13:47 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-07-09 19:13:47 +0000 |
commit | 1b5f8876ef23cb77243b61461ac7342d11382de7 (patch) | |
tree | 6247e3e2691a5bef88f1c981784356972c3c7cc3 /usr.bin/patch/patch.c | |
parent | 69254579bc244800583df8c73dbb4ec007bec6ea (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@
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; } |