beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / bins / zzcat.c
blob27225820784bd6611d64152b9c57a74124ac5cd6
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 <zzip/zzip.h>
7 #include <stdio.h>
8 #include <string.h>
10 #ifndef O_BINARY
11 #define O_BINARY 0
12 #endif
14 static const char usage[] =
16 " zzcat <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 " to get 'README' from dist.zip you may write \n"
20 " zzcat dist/README \n"
23 int
24 main (int argc, char ** argv)
26 int argn;
28 if (argc <= 1 || ! strcmp (argv[1], "--help"))
30 printf (usage);
31 return 0;
33 if (! strcmp (argv[1], "--version"))
35 printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
36 return 0;
39 for (argn=1; argn < argc; argn++)
41 ZZIP_FILE* fp = zzip_open (argv[argn], O_RDONLY|O_BINARY);
43 if (! fp)
45 perror (argv[argn]);
46 continue;
47 }else{
48 char buf[17];
49 int n;
51 /* read chunks of 16 bytes into buf and print them to stdout */
52 while (0 < (n = zzip_read(fp, buf, 16)))
54 buf[n] = '\0';
55 # ifdef STDOUT_FILENO
56 write (STDOUT_FILENO, buf, n);
57 # else
58 fwrite (buf, 1, n, stdout);
59 # endif
62 if (n == -1)
63 perror (argv[argn]);
67 return 0;
70 /*
71 * Local variables:
72 * c-file-style: "stroustrup"
73 * End: