1 /* $Id: pread-t.c 5379 2002-03-31 21:45:12Z rra $ */
2 /* pread test suite. */
10 #include "inn/messages.h"
14 ssize_t test_pread(int fd, void *buf, size_t nbyte, off_t offset);
19 unsigned char buf[256], result[256];
25 for (c = 0, i = 0; i < 256; i++, c++)
27 fd = open(".testout", O_RDWR | O_CREAT | O_TRUNC, 0644);
29 sysdie("Can't create .testout");
30 if (unlink(".testout") < 0)
31 sysdie("Can't unlink .testout");
32 if (xwrite(fd, buf, 256) < 0)
33 sysdie("Can't write to .testout");
34 if (lseek(fd, 0, SEEK_SET) == (off_t) -1)
35 sysdie("Can't rewind .testout");
36 memset(result, 0, sizeof(result));
40 status = test_pread(fd, result, 128, 128);
41 ok(1, (status == 128) && !memcmp(result, buf + 128, 128));
42 status = read(fd, result, 64);
43 ok(2, (status == 64) && !memcmp(result, buf, 64));
44 status = test_pread(fd, result, 1, 256);
46 status = test_pread(fd, result, 256, 0);
47 ok(4, (status == 256) && !memcmp(result, buf, 256));
48 position = lseek(fd, 0, SEEK_CUR);
49 ok(5, position == 64);
53 status = test_pread(20, result, 1, 0);
54 ok(6, (status == -1) && (errno == EBADF));