summaryrefslogtreecommitdiff
path: root/src/append_reader.c
blob: 4660268f2f52f14332e804ec749e248cb45f9cab (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
/* Simple test program for checking O_APPEND writes (see append_writer.c)
 *
 * Contributed by hatakeyama@bsd.tnes.nec.co.jp
 */
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/param.h>
#include <stdio.h>

int main(int argc, char **argv)
{
	char *file;
	int fd, i, rc, d;

	if (argc < 2)
		exit(1);

	file = argv[1];

	if ((fd = open(file, O_RDONLY, 0600)) == -1) {
		perror("couldn't open");
		exit(1);
	}

	for (i = 0; ;i ++) {
		if ((rc = read(fd, &d, sizeof(d))) != sizeof(i)) {
			if (rc == 0)
				exit(0);
			perror("couldn't read");
			exit(1);
		}

		if (d != i) {
			fprintf(stderr, "bad data, offset = %u, got %d wanted %d\n", i * 4, d, i);
			exit(1);
		}
	}

	exit(0);
}