Date: Tue, 2 Jul 2013 17:09:57 +0000 (UTC) From: "David E. O'Brien" <obrien@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r252512 - head/gnu/usr.bin/patch Message-ID: <201307021709.r62H9vIT012081@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: obrien Date: Tue Jul 2 17:09:57 2013 New Revision: 252512 URL: http://svnweb.freebsd.org/changeset/base/252512 Log: Make it so that 'patch < FUBAR' and 'patch -i FUBAR' operate the same. The former makes a copy of stdin, but was not accurately putting the content of stdin into a temp file. This lead to the undercounting the number of lines in hunks containing NUL characters when reading from stdin. Thus resulting in "unexpected end of file in patch" errors. Modified: head/gnu/usr.bin/patch/pch.c Modified: head/gnu/usr.bin/patch/pch.c ============================================================================== --- head/gnu/usr.bin/patch/pch.c Tue Jul 2 16:58:15 2013 (r252511) +++ head/gnu/usr.bin/patch/pch.c Tue Jul 2 17:09:57 2013 (r252512) @@ -83,12 +83,17 @@ re_patch(void) void open_patch_file(char *filename) { + int nr, nw; + if (filename == Nullch || !*filename || strEQ(filename, "-")) { pfp = fopen(TMPPATNAME, "w"); if (pfp == Nullfp) pfatal2("can't create %s", TMPPATNAME); - while (fgets(buf, buf_size, stdin) != Nullch) - fputs(buf, pfp); + while ((nr = fread(buf, 1, buf_size, stdin)) > 0) { + nw = fwrite(buf, 1, nr, pfp); + if (nr != nw) + pfatal2("write error to %s", TMPPATNAME); + } Fclose(pfp); filename = TMPPATNAME; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307021709.r62H9vIT012081>