+ return EXIT_SUCCESS;
+err:
+ lbx_close(lbx);
+ return EXIT_FAILURE;
+}
+
+int extract(FILE *f, const char *name, int verbose, char **argv) {
+ LBX *lbx;
+ size_t nfiles;
+ unsigned int i;
+
+ lbx = lbx_fopen(f, name);
+ if (!lbx) {
+ errmsg("failed to open archive: %s.\n", lbx_strerror());
+ return EXIT_FAILURE;
+ }
+
+ nfiles = lbx_numfiles(lbx);
+ if (verbose) {
+ printf("Files in archive: %zu\n", nfiles);
+ }
+
+ for (i = 0; i < nfiles; i++) {
+ struct lbx_statbuf stat;
+ size_t rc;
+ FILE *of;
+ int j;
+
+ lbx_stat(lbx, i, &stat);
+
+ switch (filematch(argv, stat.name)) {
+ case -1: continue;
+ case 0: break;
+ default: goto err;
+ }
+
+ of = fopen(stat.name, "wbx");
+ if (!of) {
+ errmsg("failed to create output file %s: %m.\n",
+ stat.name);
+ goto err;
+ }
+
+ if (verbose) printf("extracting %s...\n", stat.name);
+ rc = lbx_extract(lbx, i, of);
+ if (rc < stat.size) {
+ if (rc == 0) remove(stat.name);
+ errmsg("error extracting %s: %s.\n",
+ stat.name, lbx_strerror());
+ goto err;
+ }
+ if (verbose) printf("wrote %zu bytes.\n", rc);
+ }
+
+ lbx_close(lbx);
+ return EXIT_SUCCESS;
+err:
+ lbx_close(lbx);
+ return EXIT_FAILURE;