/* Copy the file src to dst 4KB per time */ int pyi_copy_file(const char *src, const char *dst, const char *filename) { FILE *in = pyi_path_fopen(src, "rb"); FILE *out = pyi_open_target(dst, filename); char buf[4096]; int error = 0; if (in == NULL || out == NULL) return -1; while (!feof(in)) { if (fread(buf, 4096, 1, in) == -1) { if (ferror(in)) { clearerr(in); error = -1; break; } } else { fwrite(buf, 4096, 1, out); if (ferror(out)) { clearerr(out); error = -1; break; } } } #ifndef WIN32 fchmod(fileno(out), S_IRUSR | S_IWUSR | S_IXUSR); #endif fclose(in); fclose(out); return error; }
/* * extract from the archive * and copy to the filesystem * relative to the directory the archive's in */ int extract2fs(ARCHIVE_STATUS *status, TOC *ptoc) { FILE *out; unsigned char *data = extract(status, ptoc); if (pyi_create_temp_path(status) == -1){ return -1; } out = pyi_open_target(status->temppath, ptoc->name); if (out == NULL) { FATALERROR("%s could not be extracted!\n", ptoc->name); return -1; } else { fwrite(data, ntohl(ptoc->ulen), 1, out); #ifndef WIN32 fchmod(fileno(out), S_IRUSR | S_IWUSR | S_IXUSR); #endif fclose(out); } free(data); return 0; }