# HG changeset patch # User Rob Landley # Date 1327292884 21600 # Node ID 2b521c791e4ee63b81b30aaabc1b10d0774e6086 # Parent 7da38605710140425451f7ebb40e32ca47a60597 Patch shouldn't be bothered by DOS newlines. diff -r 7da386057101 -r 2b521c791e4e toys/patch.c --- a/toys/patch.c Sun Jan 22 20:33:15 2012 -0600 +++ b/toys/patch.c Sun Jan 22 22:28:04 2012 -0600 @@ -238,14 +238,15 @@ 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 @@ // 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(" ");