- lbx = lbx_fopen(f, name);
- if (!lbx) {
- errmsg("failed to open archive: %s.\n", lbx_strerror());
- return EXIT_FAILURE;
+ while (1) {
+ unsigned char buf[1024];
+
+ rc = lbx_file_read(f, buf, sizeof buf);
+ 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))
+ tool_err(-1, "error reading archive: %s", lbx_errmsg());
+ else
+ ret = 0;
+ break;
+ }
+ }
+
+ if (fclose(of) == EOF) {
+ tool_err(0, "%s: fclose", stat->name);
+ return -1;