Debian Codegraph @

libs/zziplib/zziplib-src/bins/zzipmake-zip.c

raw
1 /*
2 * Copyright (c) 2003 Guido Draheim <[email protected]>
3 * Use freely under the restrictions of the ZLIB license.
4 *
5 * This file is used as an example to clarify zzip api usage.
6 * (the write-api is work in progress, beware)
7 */
8
9 #define _ZZIP_WRITE_SOURCE
10
11 #include <zzip/write.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include "zzipmake-zip.h"
15
16 #ifdef ZZIP_HAVE_UNISTD_H
17 #include <unistd.h>
18 #endif
19 #ifdef ZZIP_HAVE_IO_H
20 #include <io.h>
21 #endif
22
23 int rezzip_make (int argc, char ** argv)
24 {
25 int argn;
26 int exitcode = 0;
27 ZZIP_DIR * dir;
28
29 dir = zzip_dir_creat(argv[1], 0755);
30 if (! dir)
31 {
32 fprintf (stderr, "did not creat %s: \n", argv[1]);
33 perror(argv[1]);
34 if (1)
35 return 1;
36 else
37 fprintf (stderr, "(ignored)\n");
38 }
39
40 for (argn=2; argn < argc; argn++)
41 {
42 int input = open (argv[argn], O_RDONLY);
43 if (input == -1)
44 {
45 perror (argv[argn]);
46 continue;
47 }
48 else
49 {
50 char buf[17]; zzip_ssize_t n;
51 ZZIP_FILE* output = zzip_file_creat (dir, argv[argn], 0755);
52 if (! output)
53 {
54 fprintf (stderr, "|did not open %s: \n", argv[argn]);
55 fprintf (stderr, "|%s: %s\n", argv[argn],
56 zzip_strerror_of(dir));
57 continue;
58 }
59
60 while (0 < (n = read (input, buf, 16)))
61 {
62 zzip_write (output, buf, n);
63 }
64 zzip_close (output);
65 }
66 close (input);
67 }
68 zzip_dir_close(dir);
69
70 return exitcode;
71 }
72
73 /*
74 * Local variables:
75 * c-file-style: "stroustrup"
76 * End:
77 */