beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / bins / zzip.c
bloba1e990c390708cacd2c4707019dc9ca573ea41ef
1 /*
2 * Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
3 * Use freely under the restrictions of the ZLIB license.
5 * This file is used as an example to clarify zzip api usage.
6 * (the write-api is work in progress, beware)
7 */
9 #define _ZZIP_WRITE_SOURCE
11 #include <zzip/write.h>
12 #include <stdio.h>
13 #include <string.h>
15 #ifdef ZZIP_HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18 #ifdef ZZIP_HAVE_IO_H
19 #include <io.h>
20 #endif
22 #ifndef O_BINARY
23 #define O_BINARY 0
24 #endif
26 static const char usage[] =
28 "zzip <dir> files... \n"
29 " - zzip the files into a zip area."
32 int
33 main (int argc, char ** argv)
35 int argn;
36 int exitcode = 0;
37 ZZIP_DIR * dir;
39 if (argc <= 1 || ! strcmp (argv[1], "--help"))
41 printf (usage);
42 return 0;
44 if (! strcmp (argv[1], "--version"))
46 printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
47 return 0;
50 dir = zzip_dir_creat(argv[1], 0755);
51 if (! dir)
53 fprintf (stderr, "did not creat %s: \n", argv[1]);
54 perror(argv[1]);
55 if (1)
56 return 1;
57 else
58 fprintf (stderr, "(ignored)\n");
61 for (argn=2; argn < argc; argn++)
63 int input = open (argv[argn], O_RDONLY);
64 if (input == -1)
66 perror (argv[argn]);
67 continue;
69 else
71 char buf[17]; zzip_ssize_t n;
72 ZZIP_FILE* output = zzip_file_creat (dir, argv[argn], 0755);
73 if (! output)
75 fprintf (stderr, "|did not open %s: \n", argv[argn]);
76 fprintf (stderr, "|%s: %s\n", argv[argn],
77 zzip_strerror_of(dir));
78 continue;
81 while ((n = read (input, buf, 16)))
83 zzip_write (output, buf, n);
85 zzip_close (output);
87 close (input);
89 zzip_closedir(dir);
91 return exitcode;
94 /*
95 * Local variables:
96 * c-file-style: "stroustrup"
97 * End: