-int extract(LBX *lbx, const char *name, int verbose, char **argv) {
- size_t nfiles;
+int extract_file(LBXfile *f, const struct lbx_statbuf *stat)
+{
+ int ret = -1;
+ size_t rc;
+ FILE *of;
+
+ of = fopen(stat->name, "wb");
+ if (!of) {
+ tool_err(0, "%s: fopen", stat->name);
+ return -1;
+ }
+
+ while (1) {
+ 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 < sizeof buf) {
+ if (lbx_file_eof(f))
+ ret = 0;
+ break;
+ }
+ }
+
+ if (fclose(of) == EOF) {
+ tool_err(0, "%s: fclose", stat->name);
+ return -1;
+ }
+
+ return ret;
+}
+
+int extract(struct lbx *lbx, int verbose, char **argv)
+{