diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-08 20:04:04 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-08 20:04:04 +0000 |
commit | 5ab476588de557c9aa6a95ffb847167869aefc1a (patch) | |
tree | 677a66cc2f9c724b5f2a65e3eaf7897276c7ff70 | |
parent | 74cc050cba69fd95ad311bc915741efce4b47d3c (diff) |
Guess what? Trivial test for preadv.
-rw-r--r-- | regress/sys/kern/preadv/Makefile | 5 | ||||
-rw-r--r-- | regress/sys/kern/preadv/preadv.c | 59 |
2 files changed, 64 insertions, 0 deletions
diff --git a/regress/sys/kern/preadv/Makefile b/regress/sys/kern/preadv/Makefile new file mode 100644 index 00000000000..ebfceff6ef8 --- /dev/null +++ b/regress/sys/kern/preadv/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/02/08 20:04:03 art Exp $ + +PROG= preadv + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/preadv/preadv.c b/regress/sys/kern/preadv/preadv.c new file mode 100644 index 00000000000..0bfeb0c8121 --- /dev/null +++ b/regress/sys/kern/preadv/preadv.c @@ -0,0 +1,59 @@ +/* $OpenBSD: preadv.c,v 1.1 2002/02/08 20:04:03 art Exp $ */ +/* + * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. + */ +#include <sys/types.h> +#include <sys/uio.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <err.h> +#include <fcntl.h> + +int +main() +{ + char temp[] = "/tmp/dup2XXXXXXXXX"; + const char magic[10] = "0123456789"; + char c, c1, c2; + int fd; + struct iovec iv[2]; + + if ((fd = mkstemp(temp)) < 0) + err(1, "mkstemp"); + remove(temp); + + if (write(fd, magic, sizeof(magic)) != sizeof(magic)) + err(1, "write"); + + if (lseek(fd, 0, SEEK_SET) != 0) + err(1, "lseek"); + + if (read(fd, &c, 1) != 1) + err(1, "read1"); + + if (c != magic[0]) + errx(1, "read1 %c != %c", c, magic[0]); + + iv[0].iov_base = &c1; + iv[0].iov_len = 1; + iv[1].iov_base = &c2; + iv[1].iov_len = 1; + + if (preadv(fd, iv, 2, 7) != 2) + err(1, "pread"); + + if (c1 != magic[7]) + errx(1, "pread %c != %c", c1, magic[7]); + + if (c2 != magic[8]) + errx(1, "pread %c != %c", c2, magic[7]); + + if (read(fd, &c, 1) != 1) + err(1, "read2"); + + if (c != magic[1]) + errx(1, "read2 %c != %c", c, magic[1]); + + return 0; +} |