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;