From a093b8a1b6560d41009c35664fd76d8e88a3b34d Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 29 Feb 2016 22:03:04 -0800 Subject: [PATCH] Switch from dup() + fcntl(F_SETFL, FD_CLOEXEC) to fcntl(F_DUPFD_CLOEXEC) to save a second syscall. --- adsbus/opts.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adsbus/opts.c b/adsbus/opts.c index 9d5ab71..a4ba5c6 100644 --- a/adsbus/opts.c +++ b/adsbus/opts.c @@ -133,8 +133,8 @@ bool opts_add_exec_send(char *arg) { } bool opts_add_stdin(char __attribute__((unused)) *arg) { - int fd = dup(0); - assert(!fcntl(fd, F_SETFD, FD_CLOEXEC)); + int fd = fcntl(0, F_DUPFD_CLOEXEC, 0); + assert(fd >= 0); file_fd_new(fd, receive_flow, NULL); return true; } @@ -144,8 +144,8 @@ bool opts_add_stdout(char *arg) { if (!serializer) { return false; } - int fd = dup(1); - assert(!fcntl(fd, F_SETFD, FD_CLOEXEC)); + int fd = fcntl(1, F_DUPFD_CLOEXEC, 0); + assert(fd >= 0); file_fd_new(fd, send_flow, serializer); return true; }