summaryrefslogtreecommitdiff
path: root/minix/tests/test54.c
blob: 7e4776e7e772cfd5c47f45cd8a82e81783088688 (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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <err.h>
#include <stdlib.h>

int max_error = 3;
#include "common.h"


int subtest = -1;

static void do_test(void)
{
	int fd;
	char *wbuf, *rbuf;
	off_t off=0;
	size_t size;
	ssize_t nwritten;
	ssize_t nread;
	char filename[] = "pwrite_test_XXXXXXX";
	int i;

	subtest = 1;

	if ((fd = mkstemp(filename)) < 0) e(1);

	size = 1 + rand() % 4096;
	off = rand();

	if((wbuf = malloc(sizeof(char)*size)) == NULL) e(2);

	for(i = 0; i < size; i++) {
		wbuf[i] = 1 + rand()%127;
	}
	
	if ((nwritten = pwrite(fd, wbuf, size, off)) < 0) e(3);
	if ((rbuf = malloc(sizeof(char)*nwritten)) == NULL) e(4);
	if ((nread = pread(fd, rbuf, nwritten, off)) < 0) e(5);
	if (strncmp(rbuf, wbuf, nread) != 0) e(6);

	close(fd);
	free(wbuf);
	unlink(filename);
}


int main(void)
{
	start(54);
	do_test();
	quit();
	return(-1);	/* Unreachable */
}