summaryrefslogtreecommitdiffstats
path: root/extras/stripe-merge.c
blob: 3f8e4b1244d0e2854f29d31802dcc2c61b17a360 (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
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

int
main (int argc, char *argv[])
{
	int fds[argc-1];
	char buf[argc-1][4096];
	int i;
	int max_ret, ret;

	if (argc < 2) {
		printf ("Usage: %s file1 file2 ... >file\n", argv[0]);
		return 1;
	}

	for (i=0; i<argc-1; i++) {
		fds[i] = open (argv[i+1], O_RDONLY);
		if (fds[i] == -1) {
			perror (argv[i+1]);
			return 1;
		}
	}

	max_ret = 0;
	do {
		char newbuf[4096] = {0, };
		int j;

		max_ret = 0;
		for (i=0; i<argc-1; i++) {
			memset (buf[i], 0, 4096);
			ret = read (fds[i], buf[i], 4096); 
			if (ret > max_ret)
				max_ret = ret;
		}
		for (i=0; i<max_ret;i++)
			for (j=0; j<argc-1; j++)
				newbuf[i] |= buf[j][i];
		write (1, newbuf, max_ret);
	} while (max_ret);

	return 0;
}