summaryrefslogtreecommitdiff
path: root/lib/mkfifo.c
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-11-11 13:22:04 -0700
committerEric Blake <ebb9@byu.net>2009-11-11 19:24:33 -0700
commit08166afd7322d40407cf62e3c98b97782d7d1af0 (patch)
treec0f0f5df081d95147345bb7c95906b98e3c3ba62 /lib/mkfifo.c
parentdfd4d11c50dd4729bf46c26a3bbdda0c6031409d (diff)
downloadgnulib-08166afd7322d40407cf62e3c98b97782d7d1af0.tar.gz
mkfifo: new module
Solaris 9 mkfifo("name/",mode) mistakenly creates "name". FreeBSD 7.2 mkfifo("dangling/",mode) mistakenly creates a fifo at the target of "dangling". Mingw lacks named pipes altogether, but this at least avoids link failures. * modules/mkfifo: New file. * m4/mkfifo.m4 (gl_FUNC_MKFIFO): Likewise. * lib/mkfifo.c (mkfifo): Likewise. * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Set witness defaults. * modules/sys_stat (Makefile.am): Substitute them. * lib/sys_stat.in.h (mkfifo): Declare replacement. * MODULES.html.sh (Support for systems lacking POSIX:2008): Document it. * doc/posix-functions/mkfifo.texi (mkfifo): Likewise. * modules/mkfifo-tests: New test. * tests/test-mkfifo.h (test_mkfifo): New file, borrowed in part from test-mkfifoat.c. * tests/test-mkfifo.c: New file. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'lib/mkfifo.c')
-rw-r--r--lib/mkfifo.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/mkfifo.c b/lib/mkfifo.c
new file mode 100644
index 0000000000..3c29e8f6b6
--- /dev/null
+++ b/lib/mkfifo.c
@@ -0,0 +1,58 @@
+/* Create a named fifo.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Eric Blake */
+
+#include <config.h>
+
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <string.h>
+
+#if !HAVE_MKFIFO
+/* Mingw lacks mkfifo; always fail with ENOSYS. */
+
+int
+mkfifo (char const *name _UNUSED_PARAMETER_, mode_t mode _UNUSED_PARAMETER_)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
+#else /* HAVE_MKFIFO */
+
+# undef mkfifo
+
+/* Create a named fifo FILE, with access permissions in MODE. Work
+around trailing slash bugs. */
+
+int
+rpl_mkfifo (char const *name, mode_t mode)
+{
+# if MKFIFO_TRAILING_SLASH_BUG
+ size_t len = strlen (name);
+ if (len && name[len - 1] == '/')
+ {
+ struct stat st;
+ if (stat (name, &st) == 0)
+ errno = EEXIST;
+ return -1;
+ }
+# endif
+ return mkfifo (name, mode);
+}
+#endif /* HAVE_MKFIFO */