summaryrefslogtreecommitdiff
path: root/regress/sys/kern
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-08 17:05:56 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-08 17:05:56 +0000
commitfd17255120c171497dd24dc296aba3364f7a5a2e (patch)
tree4609f3c0cd33a3b226e4a76b78f315c507bc002d /regress/sys/kern
parentf80f775710521877a1c1f60cc469933fa458b327 (diff)
Simple test for fcntl(F_DUPFD).
Diffstat (limited to 'regress/sys/kern')
-rw-r--r--regress/sys/kern/fcntl_dup/Makefile5
-rw-r--r--regress/sys/kern/fcntl_dup/fcntl_dup.c39
2 files changed, 44 insertions, 0 deletions
diff --git a/regress/sys/kern/fcntl_dup/Makefile b/regress/sys/kern/fcntl_dup/Makefile
new file mode 100644
index 00000000000..6038a7ee1b0
--- /dev/null
+++ b/regress/sys/kern/fcntl_dup/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2002/02/08 17:05:55 art Exp $
+
+PROG= fcntl_dup
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/fcntl_dup/fcntl_dup.c b/regress/sys/kern/fcntl_dup/fcntl_dup.c
new file mode 100644
index 00000000000..ddad17ae908
--- /dev/null
+++ b/regress/sys/kern/fcntl_dup/fcntl_dup.c
@@ -0,0 +1,39 @@
+/* $OpenBSD: fcntl_dup.c,v 1.1 2002/02/08 17:05:55 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()
+{
+ 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 = fcntl(fd1, F_DUPFD)) < 0)
+ err(1, "fcntl(F_DUPFD)");
+
+ /* Test 2: Was close-on-exec cleared? */
+ if (fcntl(fd2, F_GETFD) != 0)
+ errx(1, "fcntl(F_DUPFD) didn't clear close-on-exec");
+
+ return 0;
+}