static int write_buffer(int fd, const void *buf, size_t len)
{
- ssize_t size;
-
- if (!len)
- return 0;
- size = write_in_full(fd, buf, len);
- if (!size)
- return error("file write: disk full");
- if (size < 0)
+ if (write_in_full(fd, buf, len) < 0)
return error("file write error (%s)", strerror(errno));
return 0;
}
void write_or_die(int fd, const void *buf, size_t count)
{
- ssize_t written;
-
- if (!count)
- return;
- written = write_in_full(fd, buf, count);
- if (written == 0)
- die("disk full?");
- else if (written < 0) {
+ if (write_in_full(fd, buf, count) < 0) {
if (errno == EPIPE)
exit(0);
die("write error (%s)", strerror(errno));
int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg)
{
- ssize_t written;
-
- if (!count)
- return 1;
- written = write_in_full(fd, buf, count);
- if (written == 0) {
- fprintf(stderr, "%s: disk full?\n", msg);
- return 0;
- }
- else if (written < 0) {
+ if (write_in_full(fd, buf, count) < 0) {
if (errno == EPIPE)
exit(0);
fprintf(stderr, "%s: write error (%s)\n",
int write_or_whine(int fd, const void *buf, size_t count, const char *msg)
{
- ssize_t written;
-
- if (!count)
- return 1;
- written = write_in_full(fd, buf, count);
- if (written == 0) {
- fprintf(stderr, "%s: disk full?\n", msg);
- return 0;
- }
- else if (written < 0) {
+ if (write_in_full(fd, buf, count) < 0) {
fprintf(stderr, "%s: write error (%s)\n",
msg, strerror(errno));
return 0;