diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-01-07 15:22:43 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2011-01-07 15:22:43 +0000 |
commit | 7c2986ff4a631b3ad967d64df9502c03463d41f7 (patch) | |
tree | 8937630e3c6fbb2d799ef8ff0c2bb8d0526b8f5b /Build/source/libs/zziplib/zziplib-0.13.60/test/zzipself.c | |
parent | 1c2a7c6d12cd8d1cb6ca50cd0a71d2a1605fc4d4 (diff) |
zziplib 0.13.59
git-svn-id: svn://tug.org/texlive/trunk@20965 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/zziplib/zziplib-0.13.60/test/zzipself.c')
-rw-r--r-- | Build/source/libs/zziplib/zziplib-0.13.60/test/zzipself.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Build/source/libs/zziplib/zziplib-0.13.60/test/zzipself.c b/Build/source/libs/zziplib/zziplib-0.13.60/test/zzipself.c new file mode 100644 index 00000000000..2cd115e75af --- /dev/null +++ b/Build/source/libs/zziplib/zziplib-0.13.60/test/zzipself.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2000,2001,2002 Guido Draheim <guidod@gmx.de> + * Use freely under the restrictions of the ZLIB License + */ + +#include <stdio.h> +#include <stdlib.h> +#include <zzip/zzip.h> + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +static const char usage[] = +{ + " zzipself <file>... \n" + " - prints the file to stdout, so you may want to redirect the output; \n" + " the file can be a normal file or an inflated part of a zip-archive, \n" + " however in this case the zip-archive happens to be the executed\n" + " binary itself, as if this program is a self-extract header of a zip. \n" + " zzipself README # same as # zzcat zzipself/README \n" +}; + +int +main (int argc, char ** argv) +{ + int status = 0; + int argn; + if (argc <= 1) + { + printf (usage); + exit (0); + } + + for (argn=1; argn < argc; argn++) + { + /* ZZIP_FILE* fp = zzip_fopen (argv[0]+"/"+argv[argn], "rbi"); */ + /* .... = zzip_open (argv[0]+"/"+argv[argn], O_RDONLY|O_BINARY, + * ZZIP_CASELESS|ZZIP_ONLYZIP, ext, 0); */ + + static const char* ext[] = { "", ".exe", ".EXE", 0 }; + ZZIP_FILE* fp; + ZZIP_DIR* zip = zzip_opendir_ext_io (argv[0], + ZZIP_CASELESS|ZZIP_ONLYZIP, ext, 0); + + if (! zip) { perror(argv[0]); break; } + + fp = zzip_file_open (zip, argv[argn], ZZIP_CASELESS); + + if (! fp) + { + perror (argv[argn]); + continue; + }else{ + char buf[17]; + int n; + + /* read chunks of 16 bytes into buf and print them to stdout */ + while (0 < (n = zzip_read(fp, buf, 16))) + { + buf[n] = '\0'; +# ifdef STDOUT_FILENO + write (STDOUT_FILENO, buf, n); +# else + fwrite (buf, 1, n, stdout); +# endif + } + + if (n == -1) + { + perror (argv[argn]); + status ++; + } + } + + zzip_file_close (fp); + zzip_closedir (zip); + } + + return status; +} + +/* + * Local variables: + * c-file-style: "stroustrup" + * End: + */ |