]> granicus.if.org Git - zziplib/commitdiff
This commit was generated by cvs2svn to compensate for changes in r85, which
authorGuido Draheim <guidod@gmx.de>
Wed, 13 Aug 2003 22:44:22 +0000 (22:44 +0000)
committerGuido Draheim <guidod@gmx.de>
Wed, 13 Aug 2003 22:44:22 +0000 (22:44 +0000)
included commits to RCS files with non-trunk default branches.

bins/unzzip.c [new file with mode: 0644]

diff --git a/bins/unzzip.c b/bins/unzzip.c
new file mode 100644 (file)
index 0000000..48710ee
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ *     Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
+ *      Use freely under the restrictions of the ZLIB license.
+ *
+ *      This file is used as an example to clarify zzip api usage.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <zzip/zzip.h>
+
+#ifdef ZZIP_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef ZZIP_HAVE_IO_H
+#include <io.h>
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+static const char usage[] = 
+{
+    "unzzip <dir>.. \n"
+    "  - unzzip the files contained in a zip archive."
+};
+
+int 
+main (int argc, char ** argv)
+{
+    int argn;
+    int exitcode = 0;
+    zzip_error_t error;
+
+    if (argc <= 1)
+    {
+        printf (usage);
+        exit(0);
+    }
+    
+    for (argn=1; argn < argc; argn++)
+    {
+        ZZIP_DIR * dir;
+        ZZIP_DIRENT d;
+  
+        dir = zzip_dir_open(argv[argn], &error);
+        if (! dir)
+        {
+            fprintf (stderr, "did not open %s: \n", argv[argn]);
+           fprintf (stderr, "%s: %s\n", argv[argn], zzip_strerror(error));
+           exitcode++;
+            continue;
+        }
+  
+        if (argc > 2) printf ("%s: \n", argv[argn]);
+
+       /* read each dir entry and show one line of info per file */
+        while (zzip_dir_read (dir, &d))
+        {
+           int output;
+           ZZIP_FILE* input = zzip_file_open (dir, d.d_name, O_RDONLY);
+           if (! input)
+           {
+               fprintf (stderr, "|did not open %s: \n", d.d_name);
+               fprintf (stderr, "|%s: %s\n", d.d_name, zzip_strerror_of(dir));
+               continue;
+           }
+
+           output = creat (d.d_name, 0664);
+           if (output == -1)
+           {
+               fprintf (stderr, "|output file %s: \n", d.d_name);
+               perror(d.d_name);
+               zzip_file_close (input);
+               continue;
+           }
+
+           printf("%s\n", d.d_name);
+           
+           { 
+               char buf[17]; zzip_ssize_t n;
+               /* read chunks of 16 bytes into buf */
+               while (0 < (n = zzip_read (input, buf, 16)))
+               {
+                   write (output, buf, n);
+               }
+
+               if (n == -1)
+                   perror (d.d_name);
+           }
+           close (output);
+           zzip_file_close (input);
+        }
+
+        zzip_dir_close(dir);
+    }
+    
+    return exitcode;
+} 
+
+/* 
+ * Local variables:
+ * c-file-style: "stroustrup"
+ * End:
+ */