sys/arch/x86/include updates
[minix.git] / test / test54.c
blob4bbeafb474f252828eaeca7906ad3218a0d484f3
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 #define MAX_ERROR 3
10 #include "common.c"
12 int subtest = -1;
14 void do_test(void)
16 int fd;
17 char *wbuf, *rbuf;
18 off_t off=0;
19 size_t size;
20 ssize_t nwritten;
21 ssize_t nread;
22 char *filename = "pwrite_test_XXXXXXX";
23 int i;
25 subtest = 1;
27 if ((fd = mkstemp(filename)) < 0) e(1);
29 size = 1 + rand() % 4096;
30 off = rand();
32 if((wbuf = malloc(sizeof(char)*size)) == NULL) e(2);
34 for(i = 0; i < size; i++) {
35 wbuf[i] = 1 + rand()%127;
38 if ((nwritten = pwrite(fd, wbuf, size, off)) < 0) e(3);
39 if ((rbuf = malloc(sizeof(char)*nwritten)) == NULL) e(4);
40 if ((nread = pread(fd, rbuf, nwritten, off)) < 0) e(5);
41 if (strncmp(rbuf, wbuf, nread) != 0) e(6);
43 close(fd);
44 free(wbuf);
45 unlink(filename);
49 int main(void)
51 start(54);
52 do_test();
53 quit();
54 return(-1); /* Unreachable */