summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2001-10-08 22:40:51 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2001-10-08 22:40:51 +0000
commit24b4aa50e0701ce9ed29dab136f77fb7aa2a51bf (patch)
tree7245f69b75cb3b2c3129fb5cc9ed8291dc4a625c /regress/sys
parent8fd0ec2d232e3caebf87b2b07da45b013c439c5f (diff)
Simple dumb test for dup2.
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/kern/dup2/Makefile11
-rw-r--r--regress/sys/kern/dup2/dup2test.c39
2 files changed, 50 insertions, 0 deletions
diff --git a/regress/sys/kern/dup2/Makefile b/regress/sys/kern/dup2/Makefile
new file mode 100644
index 00000000000..2b965247bc8
--- /dev/null
+++ b/regress/sys/kern/dup2/Makefile
@@ -0,0 +1,11 @@
+# $OpenBSD: Makefile,v 1.1 2001/10/08 22:40:50 art Exp $
+
+PROG= dup2test
+NOMAN= noman, no way, man
+
+install:
+
+regress:
+ ./dup2test
+
+.include <bsd.prog.mk>
diff --git a/regress/sys/kern/dup2/dup2test.c b/regress/sys/kern/dup2/dup2test.c
new file mode 100644
index 00000000000..2b3a8a4ef0a
--- /dev/null
+++ b/regress/sys/kern/dup2/dup2test.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <fcntl.h>
+
+int
+main()
+{
+ int orgfd, fd1, fd2;
+ char temp[] = "/tmp/dup2XXXXXXXXX";
+
+ if ((orgfd = mkstemp(temp)) < 0)
+ err(1, "mkstemp");
+ remove(temp);
+
+ if (ftruncate(orgfd, 1024) != 0)
+ err(1, "ftruncate");
+
+ if ((fd1 = dup(orgfd)) < 0)
+ err(1, "dup");
+
+ /* Set close-on-exec */
+ if (fcntl(fd1, F_SETFD, 1) != 0)
+ err(1, "fcntl(F_SETFD)");
+
+ if ((fd2 = dup2(fd1, fd1 + 1)) < 0)
+ err(1, "dup2");
+
+ /* Test 1: Do we get the right fd? */
+ if (fd2 != fd1 + 1)
+ errx(1, "dup2 didn't give us the right fd");
+
+ /* Test 2: Was close-on-exec cleared? */
+ if (fcntl(fd2, F_GETFD) != 0)
+ errx(1, "dup2 didn't clear close-on-exec");
+
+ return 0;
+}