beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / test / zzipself.c
blob2cd115e75afca3a1527cd16ad7f1383f52675b28
1 /*
2 * Copyright (c) 2000,2001,2002 Guido Draheim <guidod@gmx.de>
3 * Use freely under the restrictions of the ZLIB License
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <zzip/zzip.h>
10 #ifndef O_BINARY
11 #define O_BINARY 0
12 #endif
14 static const char usage[] =
16 " zzipself <file>... \n"
17 " - prints the file to stdout, so you may want to redirect the output; \n"
18 " the file can be a normal file or an inflated part of a zip-archive, \n"
19 " however in this case the zip-archive happens to be the executed\n"
20 " binary itself, as if this program is a self-extract header of a zip. \n"
21 " zzipself README # same as # zzcat zzipself/README \n"
24 int
25 main (int argc, char ** argv)
27 int status = 0;
28 int argn;
29 if (argc <= 1)
31 printf (usage);
32 exit (0);
35 for (argn=1; argn < argc; argn++)
37 /* ZZIP_FILE* fp = zzip_fopen (argv[0]+"/"+argv[argn], "rbi"); */
38 /* .... = zzip_open (argv[0]+"/"+argv[argn], O_RDONLY|O_BINARY,
39 * ZZIP_CASELESS|ZZIP_ONLYZIP, ext, 0); */
41 static const char* ext[] = { "", ".exe", ".EXE", 0 };
42 ZZIP_FILE* fp;
43 ZZIP_DIR* zip = zzip_opendir_ext_io (argv[0],
44 ZZIP_CASELESS|ZZIP_ONLYZIP, ext, 0);
46 if (! zip) { perror(argv[0]); break; }
48 fp = zzip_file_open (zip, argv[argn], ZZIP_CASELESS);
50 if (! fp)
52 perror (argv[argn]);
53 continue;
54 }else{
55 char buf[17];
56 int n;
58 /* read chunks of 16 bytes into buf and print them to stdout */
59 while (0 < (n = zzip_read(fp, buf, 16)))
61 buf[n] = '\0';
62 # ifdef STDOUT_FILENO
63 write (STDOUT_FILENO, buf, n);
64 # else
65 fwrite (buf, 1, n, stdout);
66 # endif
69 if (n == -1)
71 perror (argv[argn]);
72 status ++;
76 zzip_file_close (fp);
77 zzip_closedir (zip);
80 return status;
83 /*
84 * Local variables:
85 * c-file-style: "stroustrup"
86 * End: