]> git.draconx.ca Git - liblbx.git/blobdiff - src/lbxtool.c
liblbx: Correct EOF handling in lbx_file_read.
[liblbx.git] / src / lbxtool.c
index 767c30925b26c5d564920dbc154107a36a9066dd..3c4e436450caf0db09f6fe9f79cbbd653dd0add2 100644 (file)
@@ -110,19 +110,19 @@ int extract_file(LBXfile *f, const struct lbx_statbuf *stat)
                unsigned char buf[1024];
 
                rc = lbx_file_read(f, buf, sizeof buf);
-               if (rc == 0) {
-                       if (lbx_file_eof(f))
-                               ret = 0;
-                       break;
-               }
-
-               if (fwrite(buf, rc, 1, of) != 1) {
-                       tool_err(0, "%s: fwrite", stat->name);
-                       break;
+               if (rc > 0) {
+                       /* Write out any data we got. */
+                       if (fwrite(buf, rc, 1, of) != 1) {
+                               tool_err(0, "%s: fwrite", stat->name);
+                               break;
+                       }
                }
 
+               /* Now test for read errors */
                if (rc < sizeof buf) {
-                       if (lbx_file_eof(f))
+                       if (!lbx_file_eof(f))
+                               tool_err(-1, "error reading archive: %s", lbx_errmsg());
+                       else
                                ret = 0;
                        break;
                }