]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
util: Added new tvh_pipe() helper routine.
authorAdam Sutton <dev@adamsutton.me.uk>
Tue, 27 Nov 2012 13:28:34 +0000 (13:28 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Wed, 28 Nov 2012 09:43:14 +0000 (09:43 +0000)
src/tvheadend.h
src/wrappers.c

index f03ae96d0db2d01e3a2a8db7cfc4371a3f13a90f..0ceb242c66f6932e06839bad8401466cda2c415a 100644 (file)
@@ -440,10 +440,18 @@ static inline const char *tvh_strbegins(const char *s1, const char *s2)
   return s1;
 }
 
+typedef struct th_pipe
+{
+  int rd;
+  int wr;
+} th_pipe_t;
+
 int tvh_open(const char *pathname, int flags, mode_t mode);
 
 int tvh_socket(int domain, int type, int protocol);
 
+int tvh_pipe(int flags, th_pipe_t *pipe);
+
 void hexdump(const char *pfx, const uint8_t *data, int len);
 
 uint32_t tvh_crc32(uint8_t *data, size_t datalen, uint32_t crc);
index ce38af946e9c0edec0bc119226e6d282d7e33146..fd374ec878c01d872e296e443c1468ddf9a80a45 100644 (file)
@@ -1,6 +1,7 @@
 #include <fcntl.h>
 #include <sys/types.h>          /* See NOTES */
 #include <sys/socket.h>
+#include <unistd.h>
 #include "tvheadend.h"
 
 int
@@ -29,3 +30,21 @@ tvh_socket(int domain, int type, int protocol)
   pthread_mutex_unlock(&fork_lock);
   return fd;
 }
+
+int
+tvh_pipe(int flags, th_pipe_t *p)
+{
+  int fd[2], err;
+  pthread_mutex_lock(&fork_lock);
+  err = pipe(fd);
+  if (err != -1) {
+    fcntl(fd[0], F_SETFD, fcntl(fd[0], F_GETFD) | FD_CLOEXEC);
+    fcntl(fd[1], F_SETFD, fcntl(fd[1], F_GETFD) | FD_CLOEXEC);
+    fcntl(fd[0], F_SETFL, fcntl(fd[0], F_GETFL) | flags);
+    fcntl(fd[1], F_SETFL, fcntl(fd[1], F_GETFL) | flags);
+    p->rd = fd[0];
+    p->wr = fd[1];
+  }
+  pthread_mutex_unlock(&fork_lock);
+  return err;
+}