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";
50 if (argc
> 1 && argv
[1] != NULL
)
52 if (! strcmp (argv
[1], "--help")) {
53 printf ("zziptest [testfile]\n - selftest defaults to 'test.zip'");
55 }else if (! strcmp (argv
[1], "--version")) {
56 printf (__FILE__
" version "ZZIP_PACKAGE
" "ZZIP_VERSION
"\n");
64 printf("Opening zip file `%s'... ", name
);
65 { int fd
= open (name
, O_RDONLY
|O_BINARY
);
66 if (fd
== -1) { perror ("could not open input file"); return 0; }
67 if (! (dir
= zzip_dir_fdopen(fd
, &rv
)))
69 printf("error %d.\n", rv
);
75 printf("{check...\n");
76 { struct zzip_dir_hdr
* hdr
= dir
->hdr0
;
79 { printf ("could not find first header in dir_hdr"); }
84 printf("\ncompression method: %d", hdr
->d_compr
);
85 if (hdr
->d_compr
== 0) printf(" (stored)");
86 else if (hdr
->d_compr
== 8) printf(" (deflated)");
87 else printf(" (unknown)");
88 printf("\ncrc32: %x\n", hdr
->d_crc32
);
89 printf("compressed size: %d\n", hdr
->d_csize
);
90 printf("uncompressed size: %d\n", hdr
->d_usize
);
91 printf("offset of file in archive: %d\n", hdr
->d_off
);
92 printf("filename: %s\n\n", hdr
->d_name
);
94 if (hdr
->d_reclen
== 0) break;
95 I_(char *, hdr
, += hdr
->d_reclen
);
102 { printf("{contents...\n");
103 for (i
= 0; i
< 2; i
++)
107 while((d
=zzip_readdir(dir
)))
109 printf(" name \"%s\", compr %d, size %d, ratio %2d\n",
110 d
->d_name
, d
->d_compr
, d
->st_size
,
111 100 - (d
->d_csize
|1)*100/(d
->st_size
|1));
113 printf(" %d. time ---------------\n", i
+ 1);
122 const char * name
= argv
[1]? argv
[1]: "README";
125 printf("Opening file `%s' in zip archive... ", name
);
126 fp
= zzip_file_open(dir
, (char *)name
, ZZIP_CASEINSENSITIVE
);
129 { printf("error %d: %s\n", zzip_error(dir
), zzip_strerror_of(dir
)); }
133 printf("Contents of the file:\n");
135 while (0 < (i
= zzip_file_read(fp
, buf
, 16)))
138 /*printf("\n*** read %d ***\n", i); fflush(stdout); */
140 /*write(1, buf, i);*/ /* Windows does not have write !!! */
142 if (i
< 0) printf("error %d\n", zzip_error(dir
));
151 * c-file-style: "stroustrup"