From 48522dfd8227e3de1e3556bb58d4261964ef84d8 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 22 Jan 2012 22:28:04 -0600 Subject: Patch shouldn't be bothered by DOS newlines. --- toys/patch.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'toys') 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(" "); -- cgit v1.2.3