summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-08 21:06:06 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-08 21:06:06 +0000
commitde890323bb5174e6df992ff84a4d356578f87cd8 (patch)
tree6455916e2d9e111e90f204005cc6acbd9f0fbf88 /regress/sys
parent56fd4a5fbcbccf95ece87bd41c54344c7afe5e22 (diff)
test pwritev
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/kern/pwritev/Makefile5
-rw-r--r--regress/sys/kern/pwritev/pwritev.c59
2 files changed, 64 insertions, 0 deletions
diff --git a/regress/sys/kern/pwritev/Makefile b/regress/sys/kern/pwritev/Makefile
new file mode 100644
index 00000000000..4d01ee63aa6
--- /dev/null
+++ b/regress/sys/kern/pwritev/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2002/02/08 21:06:05 art Exp $
+
+PROG= pwritev
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/pwritev/pwritev.c b/regress/sys/kern/pwritev/pwritev.c
new file mode 100644
index 00000000000..11e6f6e8984
--- /dev/null
+++ b/regress/sys/kern/pwritev/pwritev.c
@@ -0,0 +1,59 @@
+/* $OpenBSD: pwritev.c,v 1.1 2002/02/08 21:06:05 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/pwritevXXXXXXXXX";
+ char magic[10] = "0123456789";
+ const char zeroes[10] = "0000000000";
+ char buf[10];
+ struct iovec iov[2];
+ 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");
+
+ iov[0].iov_base = &magic[8];
+ iov[0].iov_len = 2;
+ iov[1].iov_base = &magic[7];
+ iov[1].iov_len = 2;
+
+ if (pwritev(fd, iov, 2, 4) != 4)
+ err(1, "pwrite");
+
+ if (read(fd, &c, 1) != 1)
+ err(1, "read");
+
+ if (c != '9')
+ errx(1, "read %c != %c", c, '9');
+
+ c = '5';
+ if (write(fd, &c, 1) != 1)
+ err(1, "write");
+
+ if (pread(fd, buf, 10, 0) != 10)
+ err(1, "pread");
+
+ if (memcmp(buf, "0000895800", 10) != 0)
+ errx(1, "data mismatch: %s != %s", buf, "0000895800");
+
+ return 0;
+}