make vfs & filesystems use failable copying
[minix3.git] / test / test54.c
blob7e4776e7e772cfd5c47f45cd8a82e81783088688
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <string.h>
6 #include <err.h>
7 #include <stdlib.h>
9 int max_error = 3;
10 #include "common.h"
13 int subtest = -1;
15 static void do_test(void)
17 int fd;
18 char *wbuf, *rbuf;
19 off_t off=0;
20 size_t size;
21 ssize_t nwritten;
22 ssize_t nread;
23 char filename[] = "pwrite_test_XXXXXXX";
24 int i;
26 subtest = 1;
28 if ((fd = mkstemp(filename)) < 0) e(1);
30 size = 1 + rand() % 4096;
31 off = rand();
33 if((wbuf = malloc(sizeof(char)*size)) == NULL) e(2);
35 for(i = 0; i < size; i++) {
36 wbuf[i] = 1 + rand()%127;
39 if ((nwritten = pwrite(fd, wbuf, size, off)) < 0) e(3);
40 if ((rbuf = malloc(sizeof(char)*nwritten)) == NULL) e(4);
41 if ((nread = pread(fd, rbuf, nwritten, off)) < 0) e(5);
42 if (strncmp(rbuf, wbuf, nread) != 0) e(6);
44 close(fd);
45 free(wbuf);
46 unlink(filename);
50 int main(void)
52 start(54);
53 do_test();
54 quit();
55 return(-1); /* Unreachable */