aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-01-22 22:28:04 -0600
committerRob Landley <rob@landley.net>2012-01-22 22:28:04 -0600
commit48522dfd8227e3de1e3556bb58d4261964ef84d8 (patch)
treecef9efb0a2e222cad1da3821131214b55384ddac
parent5b67c38f86318bfa8ff8e631aa9c5e0ea1a70c64 (diff)
downloadtoybox-48522dfd8227e3de1e3556bb58d4261964ef84d8.tar.gz
Patch shouldn't be bothered by DOS newlines.
-rw-r--r--toys/patch.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/toys/patch.c b/toys/patch.c
index 974885ce..851f4eb6 100644
--- a/toys/patch.c
+++ b/toys/patch.c
@@ -238,14 +238,15 @@ done:
void patch_main(void)
{
- int reverse = toys.optflags & FLAG_REVERSE, state = 0;
+ int reverse = toys.optflags&FLAG_REVERSE, state = 0, patchlinenum = 0,
+ strip = 0;
char *oldname = NULL, *newname = NULL;
if (TT.infile) TT.filepatch = xopen(TT.infile, O_RDONLY);
TT.filein = TT.fileout = -1;
// Loop through the lines in the patch
- for(;;) {
+ for (;;) {
char *patchline;
patchline = get_line(TT.filepatch);
@@ -253,6 +254,14 @@ void patch_main(void)
// Other versions of patch accept damaged patches,
// so we need to also.
+ if (strip || !patchlinenum++) {
+ int len = strlen(patchline);
+ if (patchline[len-1] == '\r') {
+ if (!strip) fdprintf(2, "Removing DOS newlines\n");
+ strip = 1;
+ patchline[len-1]=0;
+ }
+ }
if (!*patchline) {
free(patchline);
patchline = xstrdup(" ");