=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/patch/patch.c,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- src/usr.bin/patch/patch.c 2004/06/18 17:52:25 1.40 +++ src/usr.bin/patch/patch.c 2004/07/09 19:13:46 1.41 @@ -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 @@ -929,6 +929,21 @@ 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; }