summaryrefslogtreecommitdiff
path: root/Build/source/libs/zziplib/zziplib-0.13.58/test/zzipsetstub.c
blob: 5d5ad0c903bbbf598f83c12f31752c1be4e6e7b0 (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
#include <stdio.h>
#include <stdlib.h>

static const char usage[] =
{
    "zzipsetstub <zipfile> <zipsfxstub>... \n"
    " overwrite the header of the zipfile with the sfxstub code.\n"
    " this is usually the last step in creating a selfextract archive\n"
    " or an application with all its data appended as a zip.\n"
};

int 
main (int argc, char ** argv)
{
    int argn;
    if (argc <= 2)
    {
        printf (usage);
        exit (0);
    }

    {
	char buf[17]; int n;
	char* zipfile = 0; FILE* zipFILE = 0;
	char* sfxfile = 0; FILE* sfxFILE = 0;
    
	for (argn=1; argn < argc; argn++)
	{
	    if (argv[argn][0] == '-') continue;
	    if (! zipfile) { zipfile = argv[argn]; continue; }
	    if (! sfxfile) { sfxfile = argv[argn]; continue; }
	    /* superflous argument */
	}

	zipFILE = fopen (zipfile, "r+b");
	if (! zipFILE) { perror (zipfile); return 1; }

	sfxFILE = fopen (sfxfile, "rb");
	if (! sfxFILE) { perror (sfxfile); return 1; }
    
	while (0 < (n = fread(buf, 1, 16, sfxFILE)))
	{
	    buf[n] = '\0';
	    fwrite (buf, 1, n, zipFILE);
	}
	
	if (n == -1) 
	    perror (argv[argn]);

	fclose (sfxFILE);
	fclose (zipFILE);
    }
    
    return 0;
} 

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