This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 7/7] support: Add support_create_temp_fifo
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Tue, 4 Sep 2018 17:45:53 -0300
- Subject: [PATCH 7/7] support: Add support_create_temp_fifo
- References: <20180904204553.6971-1-adhemerval.zanella@linaro.org>
Checked on x86_64-linux-gnu.
* support/temp_file.c (support_create_temp_fifo): New function.
* support/temp_file.h (support_create_temp_fifo): New prototype.
---
ChangeLog | 3 +++
support/temp_file.c | 23 +++++++++++++++++++++++
support/temp_file.h | 6 ++++++
3 files changed, 32 insertions(+)
diff --git a/support/temp_file.c b/support/temp_file.c
index 0bbc7f9972..362ef171cc 100644
--- a/support/temp_file.c
+++ b/support/temp_file.c
@@ -86,6 +86,29 @@ create_temp_file (const char *base, char **filename)
return fd;
}
+int
+support_create_temp_fifo (const char *base, char **fifoname)
+{
+ char *fname = xasprintf ("%s/%sXXXXXX", test_dir, base);
+ mktemp (fname);
+
+ int fd = mkfifo (fname, 0600);
+ if (fd == -1)
+ {
+ printf ("cannot open temporary fifo '%s': %m\n", fname);
+ free (fname);
+ return -1;
+ }
+
+ add_temp_file (fname);
+ if (fifoname != NULL)
+ *fifoname = fname;
+ else
+ free (fname);
+
+ return fd;
+}
+
char *
support_create_temp_directory (const char *base)
{
diff --git a/support/temp_file.h b/support/temp_file.h
index c7795cc577..081b241b68 100644
--- a/support/temp_file.h
+++ b/support/temp_file.h
@@ -32,6 +32,12 @@ void add_temp_file (const char *name);
*FILENAME. */
int create_temp_file (const char *base, char **filename);
+/* Create a temporary fifo. Return the opened file descriptor on
+ success, or -1 on failure. Write the file name to *FILENAME if
+ FILENAME is not NULL. In this case, the caller is expected to free
+ *FILENAME. */
+int support_create_temp_fifo (const char *name, char **fifoname);
+
/* Create a temporary directory and schedule it for deletion. BASE is
used as a prefix for the unique directory name, which the function
returns. The caller should free this string. */
--
2.17.1