diff options
Diffstat (limited to 'regress/sys/kern')
-rw-r--r-- | regress/sys/kern/pread/pread.c | 16 | ||||
-rw-r--r-- | regress/sys/kern/preadv/preadv.c | 22 | ||||
-rw-r--r-- | regress/sys/kern/pwrite/pwrite.c | 16 | ||||
-rw-r--r-- | regress/sys/kern/pwritev/pwritev.c | 18 |
4 files changed, 60 insertions, 12 deletions
diff --git a/regress/sys/kern/pread/pread.c b/regress/sys/kern/pread/pread.c index c4640dd1a32..4a57babdb1b 100644 --- a/regress/sys/kern/pread/pread.c +++ b/regress/sys/kern/pread/pread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pread.c,v 1.2 2003/07/31 21:48:09 deraadt Exp $ */ +/* $OpenBSD: pread.c,v 1.3 2011/11/05 15:43:04 guenther Exp $ */ /* * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. */ @@ -6,6 +6,7 @@ #include <stdlib.h> #include <unistd.h> #include <err.h> +#include <errno.h> #include <fcntl.h> int @@ -14,7 +15,7 @@ main(int argc, char *argv[]) char temp[] = "/tmp/dup2XXXXXXXXX"; const char magic[10] = "0123456789"; char c; - int fd; + int fd, ret; if ((fd = mkstemp(temp)) < 0) err(1, "mkstemp"); @@ -44,5 +45,16 @@ main(int argc, char *argv[]) if (c != magic[1]) errx(1, "read2 %c != %c", c, magic[1]); + close(fd); + + /* also, verify that pread fails on ttys */ + fd = open("/dev/tty", O_RDWR); + if (fd < 0) + printf("skipping tty test\n"); + else if ((ret = pread(fd, &c, 1, 7)) != -1) + errx(1, "pread succeeded on tty, returning %d", ret); + else if (errno != ESPIPE) + err(1, "pread"); + return 0; } diff --git a/regress/sys/kern/preadv/preadv.c b/regress/sys/kern/preadv/preadv.c index 261af959608..8bb2036f188 100644 --- a/regress/sys/kern/preadv/preadv.c +++ b/regress/sys/kern/preadv/preadv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: preadv.c,v 1.2 2003/07/31 21:48:09 deraadt Exp $ */ +/* $OpenBSD: preadv.c,v 1.3 2011/11/05 15:43:04 guenther Exp $ */ /* * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. */ @@ -8,6 +8,7 @@ #include <stdlib.h> #include <unistd.h> #include <err.h> +#include <errno.h> #include <fcntl.h> int @@ -16,7 +17,7 @@ main(int argc, char *argv[]) char temp[] = "/tmp/dup2XXXXXXXXX"; const char magic[10] = "0123456789"; char c, c1, c2; - int fd; + int fd, ret; struct iovec iv[2]; if ((fd = mkstemp(temp)) < 0) @@ -41,13 +42,13 @@ main(int argc, char *argv[]) iv[1].iov_len = 1; if (preadv(fd, iv, 2, 7) != 2) - err(1, "pread"); + err(1, "preadv"); if (c1 != magic[7]) - errx(1, "pread %c != %c", c1, magic[7]); + errx(1, "preadv %c != %c", c1, magic[7]); if (c2 != magic[8]) - errx(1, "pread %c != %c", c2, magic[7]); + errx(1, "preadv %c != %c", c2, magic[7]); if (read(fd, &c, 1) != 1) err(1, "read2"); @@ -55,5 +56,16 @@ main(int argc, char *argv[]) if (c != magic[1]) errx(1, "read2 %c != %c", c, magic[1]); + close(fd); + + /* also, verify that preadv fails on ttys */ + fd = open("/dev/tty", O_RDWR); + if (fd < 0) + printf("skipping tty test\n"); + else if ((ret = preadv(fd, iv, 2, 7)) != -1) + errx(1, "preadv succeeded on tty, returning %d", ret); + else if (errno != ESPIPE) + err(1, "preadv"); + return 0; } diff --git a/regress/sys/kern/pwrite/pwrite.c b/regress/sys/kern/pwrite/pwrite.c index 80ba0143ecf..1cfeacab090 100644 --- a/regress/sys/kern/pwrite/pwrite.c +++ b/regress/sys/kern/pwrite/pwrite.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwrite.c,v 1.3 2003/09/02 23:52:17 david Exp $ */ +/* $OpenBSD: pwrite.c,v 1.4 2011/11/05 15:43:04 guenther Exp $ */ /* * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. */ @@ -7,6 +7,7 @@ #include <string.h> #include <unistd.h> #include <err.h> +#include <errno.h> #include <fcntl.h> int @@ -17,7 +18,7 @@ main(int argc, char *argv[]) const char zeroes[10] = "0000000000"; char buf[10]; char c; - int fd; + int fd, ret; if ((fd = mkstemp(temp)) < 0) err(1, "mkstemp"); @@ -48,5 +49,16 @@ main(int argc, char *argv[]) if (memcmp(buf, "0000125400", 10) != 0) errx(1, "data mismatch: %s != %s", buf, "0000125400"); + close(fd); + + /* also, verify that pwrite fails on ttys */ + fd = open("/dev/tty", O_RDWR); + if (fd < 0) + printf("skipping tty test\n"); + else if ((ret = pwrite(fd, &c, 1, 7)) != -1) + errx(1, "pwrite succeeded on tty, returning %d", ret); + else if (errno != ESPIPE) + err(1, "pwrite"); + return 0; } diff --git a/regress/sys/kern/pwritev/pwritev.c b/regress/sys/kern/pwritev/pwritev.c index 6012869cc7d..759ecb19123 100644 --- a/regress/sys/kern/pwritev/pwritev.c +++ b/regress/sys/kern/pwritev/pwritev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pwritev.c,v 1.3 2003/09/02 23:52:17 david Exp $ */ +/* $OpenBSD: pwritev.c,v 1.4 2011/11/05 15:43:04 guenther Exp $ */ /* * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. */ @@ -9,6 +9,7 @@ #include <string.h> #include <unistd.h> #include <err.h> +#include <errno.h> #include <fcntl.h> int @@ -20,7 +21,7 @@ main(int argc, char *argv[]) char buf[10]; struct iovec iov[2]; char c; - int fd; + int fd, ret; if ((fd = mkstemp(temp)) < 0) err(1, "mkstemp"); @@ -38,7 +39,7 @@ main(int argc, char *argv[]) iov[1].iov_len = 2; if (pwritev(fd, iov, 2, 4) != 4) - err(1, "pwrite"); + err(1, "pwritev"); if (read(fd, &c, 1) != 1) err(1, "read"); @@ -56,5 +57,16 @@ main(int argc, char *argv[]) if (memcmp(buf, "0000895800", 10) != 0) errx(1, "data mismatch: %s != %s", buf, "0000895800"); + close(fd); + + /* also, verify that pwritev fails on ttys */ + fd = open("/dev/tty", O_RDWR); + if (fd < 0) + printf("skipping tty test\n"); + else if ((ret = pwritev(fd, iov, 2, 7)) != -1) + errx(1, "pwritev succeeded on tty, returning %d", ret); + else if (errno != ESPIPE) + err(1, "pwritev"); + return 0; } |