diff options
author | David E. O'Brien <obrien@FreeBSD.org> | 2013-07-02 17:09:57 +0000 |
---|---|---|
committer | David E. O'Brien <obrien@FreeBSD.org> | 2013-07-02 17:09:57 +0000 |
commit | 07b3f0f7db7ec4cc407a26f20b9f545c92a571e3 (patch) | |
tree | 20eae0d150ecc5a34ea92caea2efc1309b34b15c | |
parent | af8056441e3f7ef883f0682cbbc5ee33d0975c2f (diff) | |
download | src-07b3f0f7db7ec4cc407a26f20b9f545c92a571e3.tar.gz src-07b3f0f7db7ec4cc407a26f20b9f545c92a571e3.zip |
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.
Notes
Notes:
svn path=/head/; revision=252512
-rw-r--r-- | gnu/usr.bin/patch/pch.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/gnu/usr.bin/patch/pch.c b/gnu/usr.bin/patch/pch.c index dba4582e52a4..e2c9548a808b 100644 --- a/gnu/usr.bin/patch/pch.c +++ b/gnu/usr.bin/patch/pch.c @@ -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; } |