mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 19:30:12 +01:00
Refactored zip support for pilerexport
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
5331297c55
commit
b5a8255be1
@ -326,34 +326,14 @@ int write_to_zip_file(char *filename){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(filename, O_RDONLY);
|
zip_source_t *zs = zip_source_file(z, filename, 0, 0);
|
||||||
if(fd == -1){
|
if(zs && zip_file_add(z, filename, zs, ZIP_FL_ENC_UTF_8) >= 0){
|
||||||
printf("cannot open: %s\n", filename);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct stat st;
|
|
||||||
if(fstat(fd, &st)){
|
|
||||||
close(fd);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if(addr == MAP_FAILED) return ret;
|
|
||||||
|
|
||||||
zip_source_t *zs = zip_source_buffer(z, addr, st.st_size, 0);
|
|
||||||
|
|
||||||
if(zip_file_add(z, filename, zs, ZIP_FL_ENC_UTF_8) == -1){
|
|
||||||
printf("error adding file %s: %s\n", filename, zip_strerror(z));
|
|
||||||
zip_source_free(zs);
|
|
||||||
} else {
|
|
||||||
ret = OK;
|
ret = OK;
|
||||||
|
} else {
|
||||||
|
printf("error adding file %s: %s\n", filename, zip_strerror(z));
|
||||||
}
|
}
|
||||||
|
|
||||||
zip_close(z);
|
zip_close(z);
|
||||||
munmap(addr, st.st_size);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user