diff mbox series

[7/7] support: Add support_create_temp_fifo

Message ID 20180904204553.6971-8-adhemerval.zanella@linaro.org
State Superseded
Headers show
Series General fixes and refactor for BZ#12683 | expand

Commit Message

Adhemerval Zanella Netto Sept. 4, 2018, 8:45 p.m. UTC
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(+)

-- 
2.17.1
diff mbox series

Patch

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.  */