3 * Guido Draheim <guidod@gmx.de>
4 * Tomi Ollila <Tomi.Ollila@iki.fi>
6 * Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim
8 * use under the restrictions of the
9 * Lesser GNU General Public License
10 * or alternatively the restrictions
11 * of the Mozilla Public License 1.1
19 #if defined ZZIP_HAVE_WINDOWS_H
20 #define WIN32_LEAN_AND_MEAN
25 #ifdef ZZIP_HAVE_UNISTD_H
26 #include <unistd.h> /* sleep */
33 #if __GNUC__+0 >= 3 && __GNUC_MINOR__+0 >= 3
35 # warning suppress a warning where the compiler should have optimized instead.
37 #define I_(_T,_L,_R) do { _T _l = (_T) _L; \
38 _l _R; _L = (typeof(_L)) _l; } while(0)
40 #define I_(_T,_L,_R) _L _R
43 int main(int argc, char ** argv)
46 const char * name = "test.zip";
51 if (argc > 1 && argv[1] != NULL)
53 if (! strcmp (argv[1], "--help")) {
54 printf ("zziptest [testfile]\n - selftest defaults to 'test.zip'");
56 }else if (! strcmp (argv[1], "--version")) {
57 printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
59 }else if (! strcmp (argv[1], "--quick")) {
70 printf("Opening zip file `%s'... ", name);
71 { int fd = open (name, O_RDONLY|O_BINARY);
72 if (fd == -1) { perror ("could not open input file"); return 0; }
73 if (! (dir = zzip_dir_fdopen(fd, &rv)))
75 printf("error %d.\n", rv);
81 printf("{check...\n");
82 { struct zzip_dir_hdr * hdr = dir->hdr0;
85 { printf ("could not find first header in dir_hdr"); }
90 printf("\ncompression method: %d", hdr->d_compr);
91 if (hdr->d_compr == 0) printf(" (stored)");
92 else if (hdr->d_compr == 8) printf(" (deflated)");
93 else printf(" (unknown)");
94 printf("\ncrc32: %x\n", hdr->d_crc32);
95 printf("compressed size: %d\n", hdr->d_csize);
96 printf("uncompressed size: %d\n", hdr->d_usize);
97 printf("offset of file in archive: %d\n", hdr->d_off);
98 printf("filename: %s\n\n", hdr->d_name);
100 if (hdr->d_reclen == 0) break;
101 I_(char *, hdr, += hdr->d_reclen);
102 if (! quick) sleep(1);
108 { printf("{contents...\n");
109 for (i = 0; i < 2; i++)
113 while((d=zzip_readdir(dir)))
115 printf(" name \"%s\", compr %d, size %d, ratio %2d\n",
116 d->d_name, d->d_compr, d->st_size,
117 100 - (d->d_csize|1)*100/(d->st_size|1));
119 printf(" %d. time ---------------\n", i + 1);
128 const char * name = argv[1]? argv[1]: "README";
131 printf("Opening file `%s' in zip archive... ", name);
132 fp = zzip_file_open(dir, (char *)name, ZZIP_CASEINSENSITIVE);
135 { printf("error %d: %s\n", zzip_error(dir), zzip_strerror_of(dir)); }
139 printf("Contents of the file:\n");
141 while (0 < (i = zzip_file_read(fp, buf, 16)))
144 /*printf("\n*** read %d ***\n", i); fflush(stdout); */
146 /*write(1, buf, i);*/ /* Windows does not have write !!! */
148 if (i < 0) printf("error %d\n", zzip_error(dir));
157 * c-file-style: "stroustrup"