Fix bug noticed by Volker - if sendfile returns zero then
[jra/samba/.git] / source3 / lib / sendfile.c
index fb10cae2aa3c64dec010b3f9620fab2cbecec8d0..59a18ce6e184b164946557b1758355b35e5c323c 100644 (file)
@@ -78,8 +78,12 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T of
                        }
                        return -1;
                }
-               if (nwritten == 0)
-                       return -1; /* I think we're at EOF here... */
+               if (nwritten == 0) {
+                       /*
+                        * EOF, return a short read
+                        */
+                       return hdr_len + (count - total);
+               }
                total -= nwritten;
        }
        return count + hdr_len;
@@ -156,8 +160,12 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T of
                        }
                        return -1;
                }
-               if (nwritten == 0)
-                       return -1; /* I think we're at EOF here... */
+               if (nwritten == 0) {
+                       /*
+                        * EOF, return a short read
+                        */
+                       return hdr_len + (((uint32)count) - small_total);
+               }
                small_total -= nwritten;
        }
        return count + hdr_len;