Avoid errors and warnings when attempting to do I/O on zero bytes
Unfortunately, while {read,write}_in_full do take into account zero-sized reads/writes; their die and whine variants do not. I have a repository where there are zero-sized files in the history that was triggering these things. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Eric Wong committed
Jan 11, 2007 at 13:43 UTC
3b97fee23df7ec78eea77151fcc0885ec3191950
2 files changed
+10
sha1_file.c
+2
@@ -1620,6 +1620,8 @@ static int write_buffer(int fd, const void *buf, size_t len)
1620
{
1621
ssize_t size;
1622
1623
+ if (!len)
1624
+ return 0;
1625
size = write_in_full(fd, buf, len);
1626
if (!size)
1627
return error("file write: disk full");
write_or_die.c
+8
@@ -26,6 +26,8 @@ void read_or_die(int fd, void *buf, size_t count)
26
{
27
ssize_t loaded;
28
29
+ if (!count)
30
+ return;
31
loaded = read_in_full(fd, buf, count);
32
if (loaded == 0)
33
die("unexpected end of file");
@@ -58,6 +60,8 @@ void write_or_die(int fd, const void *buf, size_t count)
60
{
61
ssize_t written;
62
63
+ if (!count)
64
+ return;
65
written = write_in_full(fd, buf, count);
66
if (written == 0)
67
die("disk full?");
@@ -72,6 +76,8 @@ int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg)
76
{
77
ssize_t written;
78
79
+ if (!count)
80
+ return 1;
81
written = write_in_full(fd, buf, count);
82
if (written == 0) {
83
fprintf(stderr, "%s: disk full?\n", msg);
@@ -92,6 +98,8 @@ int write_or_whine(int fd, const void *buf, size_t count, const char *msg)
98
{
99
ssize_t written;
100
101
+ if (!count)
102
+ return 1;
103
written = write_in_full(fd, buf, count);
104
if (written == 0) {
105
fprintf(stderr, "%s: disk full?\n", msg);