Commits

Anonymous committed 3b97fee

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>

Comments (0)

Files changed (2)

 {
 	ssize_t size;
 
+	if (!len)
+		return 0;
 	size = write_in_full(fd, buf, len);
 	if (!size)
 		return error("file write: disk full");
 {
 	ssize_t loaded;
 
+	if (!count)
+		return;
 	loaded = read_in_full(fd, buf, count);
 	if (loaded == 0)
 		die("unexpected end of file");
 {
 	ssize_t written;
 
+	if (!count)
+		return;
 	written = write_in_full(fd, buf, count);
 	if (written == 0)
 		die("disk full?");
 {
 	ssize_t written;
 
+	if (!count)
+		return 1;
 	written = write_in_full(fd, buf, count);
 	if (written == 0) {
 		fprintf(stderr, "%s: disk full?\n", 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);