| 1 |
/* |
| 2 |
* Copyright (c) 2000,2001,2002 Guido Draheim <[email protected]> |
| 3 |
* Use freely under the restrictions of the ZLIB License |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <zzip/zzip.h> |
| 9 |
|
| 10 |
#ifndef O_BINARY |
| 11 |
#define O_BINARY 0 |
| 12 |
#endif |
| 13 |
|
| 14 |
static const char usage[] = |
| 15 |
{ |
| 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" |
| 22 |
}; |
| 23 |
|
| 24 |
int |
| 25 |
main (int argc, char ** argv) |
| 26 |
{ |
| 27 |
int status = 0; |
| 28 |
int argn; |
| 29 |
if (argc <= 1) |
| 30 |
{ |
| 31 |
printf (usage); |
| 32 |
exit (0); |
| 33 |
} |
| 34 |
|
| 35 |
for (argn=1; argn < argc; argn++) |
| 36 |
{ |
| 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); */ |
| 40 |
|
| 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); |
| 45 |
|
| 46 |
if (! zip) { perror(argv[0]); break; } |
| 47 |
|
| 48 |
fp = zzip_file_open (zip, argv[argn], ZZIP_CASELESS); |
| 49 |
|
| 50 |
if (! fp) |
| 51 |
{ |
| 52 |
perror (argv[argn]); |
| 53 |
continue; |
| 54 |
}else{ |
| 55 |
char buf[17]; |
| 56 |
int n; |
| 57 |
|
| 58 |
/* read chunks of 16 bytes into buf and print them to stdout */ |
| 59 |
while (0 < (n = zzip_read(fp, buf, 16))) |
| 60 |
{ |
| 61 |
buf[n] = '\0'; |
| 62 |
# ifdef STDOUT_FILENO |
| 63 |
write (STDOUT_FILENO, buf, n); |
| 64 |
# else |
| 65 |
fwrite (buf, 1, n, stdout); |
| 66 |
# endif |
| 67 |
} |
| 68 |
|
| 69 |
if (n == -1) |
| 70 |
{ |
| 71 |
perror (argv[argn]); |
| 72 |
status ++; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
zzip_file_close (fp); |
| 77 |
zzip_closedir (zip); |
| 78 |
} |
| 79 |
|
| 80 |
return status; |
| 81 |
} |
| 82 |
|
| 83 |
/* |
| 84 |
* Local variables: |
| 85 |
* c-file-style: "stroustrup" |
| 86 |
* End: |
| 87 |
*/ |