summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-08 19:05:19 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-08 19:05:19 +0000
commit44f62621594155349e2c2a58499258202d8f2ef2 (patch)
tree031ba9dd1274c17f030eea299b42d9fe975adf01 /regress/sys
parent37a5a713de54b10c7fbd242dbcf11e83eb798946 (diff)
Simple test for pread.
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/kern/pread/Makefile5
-rw-r--r--regress/sys/kern/pread/pread.c48
2 files changed, 53 insertions, 0 deletions
diff --git a/regress/sys/kern/pread/Makefile b/regress/sys/kern/pread/Makefile
new file mode 100644
index 00000000000..5979802f056
--- /dev/null
+++ b/regress/sys/kern/pread/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2002/02/08 19:05:18 art Exp $
+
+PROG= pread
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/pread/pread.c b/regress/sys/kern/pread/pread.c
new file mode 100644
index 00000000000..23f28155d3f
--- /dev/null
+++ b/regress/sys/kern/pread/pread.c
@@ -0,0 +1,48 @@
+/* $OpenBSD: pread.c,v 1.1 2002/02/08 19:05:18 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/dup2XXXXXXXXX";
+ const char magic[10] = "0123456789";
+ char c;
+ int fd;
+
+ 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]);
+
+ if (pread(fd, &c, 1, 7) != 1)
+ err(1, "pread");
+
+ if (c != magic[7])
+ errx(1, "pread %c != %c", c, 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;
+}