summaryrefslogtreecommitdiff
path: root/tests/mkfifo.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2025-10-18 19:06:52 +0200
committerJörg Frings-Fürst <debian@jff.email>2025-10-18 19:06:52 +0200
commit27dae84ed92f1ef0300263091972338d12e78348 (patch)
tree7c52931f474fafb8a4bd4fd15ca3461c77cdecc2 /tests/mkfifo.c
parent4682deeb62247d34de87f8e777f99e2d337fd377 (diff)
New upstream version 1.4.1upstream/1.4.1upstream
Diffstat (limited to 'tests/mkfifo.c')
-rw-r--r--tests/mkfifo.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/mkfifo.c b/tests/mkfifo.c
new file mode 100644
index 00000000..419b7b1d
--- /dev/null
+++ b/tests/mkfifo.c
@@ -0,0 +1,58 @@
+/* Create a named fifo.
+ Copyright (C) 2009-2025 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This file 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://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 (_GL_UNUSED char const *name, _GL_UNUSED mode_t mode)
+{
+ 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 == EOVERFLOW)
+ errno = EEXIST;
+ return -1;
+ }
+# endif
+ return mkfifo (name, mode);
+}
+#endif /* HAVE_MKFIFO */