summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-11-12 13:11:58 -0500
committerTavian Barnes <tavianator@tavianator.com>2017-11-12 15:17:46 -0500
commit622bcf9d46a763b7aaba75fa8421533bcbe4b981 (patch)
treeb1e7bfe8f1a108f13a1bd6d8bf03c2d852a1ce09 /util.c
parentaf7878c7474de2f6c5542ad52a0a67237387c638 (diff)
downloadbfs-622bcf9d46a763b7aaba75fa8421533bcbe4b981.tar.xz
exec: Recover from E2BIG
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/util.c b/util.c
index 0e7ec60..79bb2d2 100644
--- a/util.c
+++ b/util.c
@@ -119,6 +119,24 @@ int dup_cloexec(int fd) {
#endif
}
+int pipe_cloexec(int pipefd[2]) {
+#if __linux__ || BSD
+ return pipe2(pipefd, O_CLOEXEC);
+#else
+ if (pipe(pipefd) != 0) {
+ return -1;
+ }
+
+ if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) == -1 || fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) == -1) {
+ close(pipefd[1]);
+ close(pipefd[0]);
+ return -1;
+ }
+
+ return 0;
+#endif
+}
+
char *xregerror(int err, const regex_t *regex) {
size_t len = regerror(err, regex, NULL, 0);
char *str = malloc(len);