[BACK]Return to append_reader.c CVS log [TXT][DIR] Up to [Development] / xfs-cmds / xfstests / src

File: [Development] / xfs-cmds / xfstests / src / append_reader.c (download)

Revision 1.1, Wed Sep 4 07:00:33 2002 UTC (15 years, 1 month ago) by fsgqa
Branch: MAIN
CVS Tags: XFS-1_3_0pre1, HEAD

add in some contributed O_APPEND test helper programs.

/* 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", i * 4);
			exit(1);
		}
	}

	exit(0);
}