diff options
author | obrien <obrien@FreeBSD.org> | 2013-07-02 17:09:57 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2013-07-02 17:09:57 +0000 |
commit | ef0cb7bd8f952dec5096bca3f237925a680b7e4b (patch) | |
tree | 20eae0d150ecc5a34ea92caea2efc1309b34b15c /gnu | |
parent | 50e0add9e4de4d5547753f15e5df2059b5ee1f11 (diff) | |
download | FreeBSD-src-ef0cb7bd8f952dec5096bca3f237925a680b7e4b.zip FreeBSD-src-ef0cb7bd8f952dec5096bca3f237925a680b7e4b.tar.gz |
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.
Diffstat (limited to 'gnu')
-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 dba4582..e2c9548 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; } |