2 * Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
3 * Use freely under the restrictions of the ZLIB license.
5 * This file is used as an example to clarify zzip api usage.
10 #include <zzip/zzip.h>
12 #ifdef ZZIP_HAVE_UNISTD_H
23 static const char usage[] =
26 " - unzzip the files contained in a zip archive."
30 main (int argc, char ** argv)
42 for (argn=1; argn < argc; argn++)
47 dir = zzip_dir_open(argv[argn], &error);
50 fprintf (stderr, "did not open %s: \n", argv[argn]);
51 fprintf (stderr, "%s: %s\n", argv[argn], zzip_strerror(error));
56 if (argc > 2) printf ("%s: \n", argv[argn]);
58 /* read each dir entry and show one line of info per file */
59 while (zzip_dir_read (dir, &d))
62 ZZIP_FILE* input = zzip_file_open (dir, d.d_name, O_RDONLY);
65 fprintf (stderr, "|did not open %s: \n", d.d_name);
66 fprintf (stderr, "|%s: %s\n", d.d_name, zzip_strerror_of(dir));
70 output = creat (d.d_name, 0664);
73 fprintf (stderr, "|output file %s: \n", d.d_name);
75 zzip_file_close (input);
79 printf("%s\n", d.d_name);
82 char buf[17]; zzip_ssize_t n;
83 /* read chunks of 16 bytes into buf */
84 while (0 < (n = zzip_read (input, buf, 16)))
86 write (output, buf, n);
93 zzip_file_close (input);
104 * c-file-style: "stroustrup"