summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/isfdtype.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2002-10-16 16:10:24 +0000
committermillert <millert@openbsd.org>2002-10-16 16:10:24 +0000
commitd6b506985136bb8e80641bd10781bb468968d60b (patch)
treebf5c9b50c2b4c73591ad3f8c25c8b8461c2220d6 /lib/libc/gen/isfdtype.c
parentSync date parsing code with that in date(1) (which is obviously what pax's (diff)
downloadwireguard-openbsd-d6b506985136bb8e80641bd10781bb468968d60b.tar.xz
wireguard-openbsd-d6b506985136bb8e80641bd10781bb468968d60b.zip
Implement isfdtype(3) as per the POSIX.1g draft; requested by David Hill
Diffstat (limited to 'lib/libc/gen/isfdtype.c')
-rw-r--r--lib/libc/gen/isfdtype.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/libc/gen/isfdtype.c b/lib/libc/gen/isfdtype.c
new file mode 100644
index 00000000000..237dd8ae892
--- /dev/null
+++ b/lib/libc/gen/isfdtype.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+int
+isfdtype(int fd, int fdtype)
+{
+ struct stat sb;
+
+ if (fstat(fd, &sb) != 0)
+ return (-1);
+
+ return ((sb.st_mode & S_IFMT) == fdtype);
+}