summaryrefslogtreecommitdiff
path: root/src/base/archive.c~
diff options
context:
space:
mode:
authorTomas Chvatal (scarabeus) <tomas.chvatal@gmail.com>2008-10-22 22:50:54 +0200
committerTomas Chvatal (scarabeus) <tomas.chvatal@gmail.com>2008-10-22 22:50:54 +0200
commite12753d2ec9db83ec08bb9db63902a82fb245cdd (patch)
tree6e4a63b790d6335f969f88b797a927e0fb25f37a /src/base/archive.c~
parent0b4d9821c7333b8c4bdf7e0eeb750aef502a1137 (diff)
X
Diffstat (limited to 'src/base/archive.c~')
-rw-r--r--src/base/archive.c~73
1 files changed, 73 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
+