diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-08 20:58:03 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2002-02-08 20:58:03 +0000 |
commit | d13c21247e116c507cc520fb9d86e7b66392f662 (patch) | |
tree | c5d690f8d66145aa778b5469aa7ea54ca1551ca6 /regress/sys | |
parent | a5bc9e69498ef664274a937445b3f03bf7a1e8b4 (diff) |
test pwrite
Diffstat (limited to 'regress/sys')
-rw-r--r-- | regress/sys/kern/pwrite/Makefile | 5 | ||||
-rw-r--r-- | regress/sys/kern/pwrite/pwrite.c | 51 |
2 files changed, 56 insertions, 0 deletions
diff --git a/regress/sys/kern/pwrite/Makefile b/regress/sys/kern/pwrite/Makefile new file mode 100644 index 00000000000..5ef6587bbcf --- /dev/null +++ b/regress/sys/kern/pwrite/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/02/08 20:58:02 art Exp $ + +PROG= pwrite + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/pwrite/pwrite.c b/regress/sys/kern/pwrite/pwrite.c new file mode 100644 index 00000000000..6ee95443a0e --- /dev/null +++ b/regress/sys/kern/pwrite/pwrite.c @@ -0,0 +1,51 @@ +/* $OpenBSD: pwrite.c,v 1.1 2002/02/08 20:58:02 art Exp $ */ +/* + * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. + */ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <err.h> +#include <fcntl.h> + +int +main() +{ + char temp[] = "/tmp/pwriteXXXXXXXXX"; + const char magic[10] = "0123456789"; + const char zeroes[10] = "0000000000"; + char buf[10]; + char c; + int fd; + + if ((fd = mkstemp(temp)) < 0) + err(1, "mkstemp"); + remove(temp); + + if (write(fd, zeroes, sizeof(zeroes)) != sizeof(zeroes)) + err(1, "write"); + + if (lseek(fd, 5, SEEK_SET) != 5) + err(1, "lseek"); + + if (pwrite(fd, &magic[1], 4, 4) != 4) + err(1, "pwrite"); + + if (read(fd, &c, 1) != 1) + err(1, "read"); + + if (c != '2') + errx(1, "read %c != %c", c, '2'); + + c = '5'; + if (write(fd, &c, 1) != 1) + err(1, "write"); + + if (pread(fd, buf, 10, 0) != 10) + err(1, "pread"); + + if (memcmp(buf, "0000125400", 10) != 0) + errx(1, "data mismatch: %s != %s", buf, "0000125400"); + + return 0; +} |