contrib/chg/util.c
changeset 28855 f5764e177bbe
parent 28854 ddef14468952
child 34309 b94db1780365
--- a/contrib/chg/util.c	Sun Apr 10 03:14:32 2016 +0100
+++ b/contrib/chg/util.c	Mon Apr 11 00:17:17 2016 +0100
@@ -8,6 +8,7 @@
  */
 
 #include <errno.h>
+#include <fcntl.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -91,6 +92,15 @@
 		abortmsgerrno("failed to fchdir");
 }
 
+void fsetcloexec(int fd)
+{
+	int flags = fcntl(fd, F_GETFD);
+	if (flags < 0)
+		abortmsgerrno("cannot get flags of fd %d", fd);
+	if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0)
+		abortmsgerrno("cannot set flags of fd %d", fd);
+}
+
 void *mallocx(size_t size)
 {
 	void *result = malloc(size);