summaryrefslogtreecommitdiff
path: root/Build/source/libs/zziplib/zziplib-src/bins/zzip.c
blob: 2869a36a6118b147e8ee377d1b34544083c2a9ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 *	Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
 *      Use freely under the restrictions of the ZLIB license.
 *
 *      This file is used as an example to clarify zzip api usage.
 *                        (the write-api is work in progress, beware)
 */

#define _ZZIP_WRITE_SOURCE

#include <zzip/write.h>
#include <stdio.h>
#include <string.h>

#ifdef ZZIP_HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef ZZIP_HAVE_IO_H
#include <io.h>
#endif

#ifndef O_BINARY
#define O_BINARY 0
#endif

static const char usage[] = 
{
    "zzip <dir> files... \n"
    "  - zzip the files into a zip area."
};

int 
main (int argc, char ** argv)
{
    int argn;
    int exitcode = 0;
    ZZIP_DIR * dir;

    if (argc <= 1 || ! strcmp (argv[1], "--help"))
    {
        printf (usage);
        return 0;
    }
    if (! strcmp (argv[1], "--version"))
    {
#     if defined _ZZIP_ENABLE_WRITE
	printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION" - W/ -D_ZZIP_ENABLE_WRITE\n");
#     else
	printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION" - NO -D_ZZIP_ENABLE_WRITE\n");
#     endif
	return 0;
    }

    dir = zzip_dir_creat(argv[1], 0755);
    if (! dir)
    {
	fprintf (stderr, "did not creat %s: \n", argv[1]);
	perror(argv[1]);
	if (1)
	    return 1;
	else
	    fprintf (stderr, "(ignored)\n");
    }
    
    for (argn=2; argn < argc; argn++)
    {
	int input = open (argv[argn], O_RDONLY);
	if (input == -1)
	{
	    perror (argv[argn]);
	    continue;
	}
	else
	{
	    char buf[17]; zzip_ssize_t n;
	    ZZIP_FILE* output = zzip_file_creat (dir, argv[argn], 0755);
	    if (! output)
	    {
		fprintf (stderr, "|did not open %s: \n", argv[argn]);
		fprintf (stderr, "|%s: %s\n", argv[argn], 
			 zzip_strerror_of(dir));
		continue;
	    }

	    while ((n = read (input, buf, 16)))
	    {
		zzip_write (output, buf, n);
	    }
	    zzip_close (output);
        }
	close (input);
    }
    zzip_closedir(dir);
    
    return exitcode;
} 

/* 
 * Local variables:
 * c-file-style: "stroustrup"
 * End:
 */