Browse Source

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>
maint
Eric Wong 18 years ago committed by Junio C Hamano
parent
commit
3b97fee23d
  1. 2
      sha1_file.c
  2. 8
      write_or_die.c

2
sha1_file.c

@ -1620,6 +1620,8 @@ static int write_buffer(int fd, const void *buf, size_t len)
{ {
ssize_t size; ssize_t size;


if (!len)
return 0;
size = write_in_full(fd, buf, len); size = write_in_full(fd, buf, len);
if (!size) if (!size)
return error("file write: disk full"); return error("file write: disk full");

8
write_or_die.c

@ -26,6 +26,8 @@ void read_or_die(int fd, void *buf, size_t count)
{ {
ssize_t loaded; ssize_t loaded;


if (!count)
return;
loaded = read_in_full(fd, buf, count); loaded = read_in_full(fd, buf, count);
if (loaded == 0) if (loaded == 0)
die("unexpected end of file"); die("unexpected end of file");
@ -58,6 +60,8 @@ void write_or_die(int fd, const void *buf, size_t count)
{ {
ssize_t written; ssize_t written;


if (!count)
return;
written = write_in_full(fd, buf, count); written = write_in_full(fd, buf, count);
if (written == 0) if (written == 0)
die("disk full?"); die("disk full?");
@ -72,6 +76,8 @@ int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg)
{ {
ssize_t written; ssize_t written;


if (!count)
return 1;
written = write_in_full(fd, buf, count); written = write_in_full(fd, buf, count);
if (written == 0) { if (written == 0) {
fprintf(stderr, "%s: disk full?\n", msg); 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)
{ {
ssize_t written; ssize_t written;


if (!count)
return 1;
written = write_in_full(fd, buf, count); written = write_in_full(fd, buf, count);
if (written == 0) { if (written == 0) {
fprintf(stderr, "%s: disk full?\n", msg); fprintf(stderr, "%s: disk full?\n", msg);

Loading…
Cancel
Save