diff options
| author | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-09-02 22:15:18 +0000 |
|---|---|---|
| committer | oroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e> | 2008-09-02 22:15:18 +0000 |
| commit | 85c0f71d6e90a451f64cd032a3e58157d57dc226 (patch) | |
| tree | a5161b0fcf86d7687e60fcee85dc20ab3f7608da /src/base | |
| parent | 7c4d8699b2e9ba64f98bd2a0290080726fa8ccfe (diff) | |
- kua, zabudol som archive
git-svn-id: http://opensvn.csie.org/tuxanci_ng@264 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/archive.c | 73 | ||||
| -rw-r--r-- | src/base/archive.h | 9 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/base/archive.c b/src/base/archive.c new file mode 100644 index 0000000..ac57721 --- /dev/null +++ b/src/base/archive.c @@ -0,0 +1,73 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <zzip/zzip.h> + +#include "archive.h" + +#define ARCHIVE_BUFFER_SIZE 1024 +#define STR_TMP_FILE_NAME 4096 + +char *extractFileFromArchive(char *archive, char *filename) +{ + char buf[ARCHIVE_BUFFER_SIZE]; + char archive_name[STR_TMP_FILE_NAME]; + char name[STR_TMP_FILE_NAME]; + + ZZIP_FILE *zip_file; + FILE *file; + zzip_ssize_t len; + + strcpy(archive_name, archive); + sprintf(strrchr(archive_name, '.'), "/%s", filename); + + sprintf(name,"/tmp/tuxanci%d-%s", getpid(), filename); + + if( (zip_file = zzip_open(archive_name, O_RDONLY)) == NULL ) + { + fprintf(stderr, "No do not open %s archive\n", archive_name); + return NULL; + } + + if( (file = fopen(name, "wb")) == NULL ) + { + fprintf(stderr, "No do not create temp file %s\n", name); + return NULL; + } + + do{ + len = zzip_read(zip_file, buf, ARCHIVE_BUFFER_SIZE); + //printf("len = %d\n", len); + + if( len > 0 ) + { + fwrite(buf, len, 1, file); + } + }while( len > 0 ); + + zzip_close(zip_file); + fclose(file); + + return strdup(name); +} + +void deleteExtractFile(char *s) +{ + unlink(s); + free(s); +} + +#if ARCHIVE_TEST +int main() +{ + char *name; + + name = extractFileFromArchive("hello/a/b/hello"); + printf("name = %s\n", name); + deleteExtractFile(name); + return 0; +} +#endif + diff --git a/src/base/archive.h b/src/base/archive.h new file mode 100644 index 0000000..62e1109 --- /dev/null +++ b/src/base/archive.h @@ -0,0 +1,9 @@ + +#ifndef ARCHIVE_H + +#define ARCHIVE_H + +extern char *extractFileFromArchive(char *archive, char *file); +extern void deleteExtractFile(char *s); + +#endif |