chiark / gitweb /
Makefile.in: Use -MMD, not depend.sh
[secnet.git] / util.c
diff --git a/util.c b/util.c
index 094870ff213cbc41c9f011aa1b316f646ee30992..aa85559b37be4113800c623e8dbae4dfcd0ab716 100644 (file)
--- a/util.c
+++ b/util.c
@@ -162,6 +162,20 @@ int32_t write_mpbin(MP_INT *a, uint8_t *buffer, int32_t buflen)
     return i;
 }
 
+void setcloexec(int fd) {
+    int r=fcntl(fd, F_GETFD);
+    if (r<0) fatal_perror("fcntl(,F_GETFD) failed");
+    r=fcntl(fd, F_SETFD, r|FD_CLOEXEC);
+    if (r<0) fatal_perror("fcntl(,F_SETFD,|FD_CLOEXEC) failed");
+}
+
+void pipe_cloexec(int fd[2]) {
+    int r=pipe(fd);
+    if (r) fatal_perror("pipe");
+    setcloexec(fd[0]);
+    setcloexec(fd[1]);
+}
+
 static const char *phases[NR_PHASES]={
     "PHASE_INIT",
     "PHASE_GETOPTS",