diff options
author | David E. O'Brien <obrien@FreeBSD.org> | 2013-07-03 22:44:26 +0000 |
---|---|---|
committer | David E. O'Brien <obrien@FreeBSD.org> | 2013-07-03 22:44:26 +0000 |
commit | 0571fd57a11a605e64763b4d62ab1d20de989b31 (patch) | |
tree | a9e0769df784c3884354be7647dd2aba8046db12 /usr.bin | |
parent | 8da93e68616426d704ca3ea8f289d2fb52c4a84c (diff) | |
download | src-0571fd57a11a605e64763b4d62ab1d20de989b31.tar.gz src-0571fd57a11a605e64763b4d62ab1d20de989b31.zip |
Merge r252512 from src/gnu/usr.bin/patch into src/usr.bin/patch:
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=252636
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/patch/pch.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 411dcac0c931..c4792b203540 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -101,13 +101,17 @@ void open_patch_file(const char *filename) { struct stat filestat; + int nr, nw; if (filename == NULL || *filename == '\0' || strEQ(filename, "-")) { pfp = fopen(TMPPATNAME, "w"); if (pfp == NULL) pfatal("can't create %s", TMPPATNAME); - while (fgets(buf, buf_size, stdin) != NULL) - fputs(buf, pfp); + while ((nr = fread(buf, 1, buf_size, stdin)) > 0) { + nw = fwrite(buf, 1, nr, pfp); + if (nr != nw) + pfatal("write error to %s", TMPPATNAME); + } if (ferror(pfp) || fclose(pfp)) pfatal("can't write %s", TMPPATNAME); filename = TMPPATNAME; |