fclose(tmpfile);
exit(1);
}
- // XXX I'd catch signals or writes errors here, but I
- // I don't think it matters as the file is overwritten
- while(fread(buf, BUFF_SIZE, 1, tmpfile) == 1) {
+ while (fread(buf, BUFF_SIZE, 1, tmpfile) > 0) {
write_buff_out(buf, BUFF_SIZE, outfd);
}
+ if (ferror(tmpfile)) {
+ perror("read temporary file");
+ fclose(tmpfile);
+ exit(1);
+ }
fclose(tmpfile);
fclose(outfd);
}
}
if (tmpfile) {
/* write whatever we have in memory to tmpfile */
- write_buff_tmp(bufstart, bufused, tmpfile);
+ if (bufused)
+ write_buff_tmp(bufstart, bufused, tmpfile);
struct stat statbuf;
if (outname && !stat(outname, &statbuf)) {
/* regular file */
exit(1);
}
}
- write_buff_out(bufstart, bufused, outfd);
+ if (bufused)
+ write_buff_out(bufstart, bufused, outfd);
fclose(outfd);
}