mirror of
https://github.com/git/git.git
synced 2024-11-27 20:14:30 +08:00
7230e6d042
The little helper write_or_die() won't come back with bad news about full disks or broken pipes. It either succeeds or terminates the program, making additional error handling unnecessary. This patch adds the new function and uses it to replace two similar ones (the one in tar-tree originally has been copied from cat-file btw.). I chose to add the fd parameter which both lacked to make write_or_die() just as flexible as write() and thus suitable for lib-ification. There is a regression: error messages emitted by this function don't show the program name, while the replaced two functions did. That's acceptable, I think; a lot of other functions do the same. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
21 lines
369 B
C
21 lines
369 B
C
#include "cache.h"
|
|
|
|
void write_or_die(int fd, const void *buf, size_t count)
|
|
{
|
|
const char *p = buf;
|
|
ssize_t written;
|
|
|
|
while (count > 0) {
|
|
written = xwrite(fd, p, count);
|
|
if (written == 0)
|
|
die("disk full?");
|
|
else if (written < 0) {
|
|
if (errno == EPIPE)
|
|
exit(0);
|
|
die("write error (%s)", strerror(errno));
|
|
}
|
|
count -= written;
|
|
p += written;
|
|
}
|
|
}
|