From: Josef 'Jeff' Sipek Date: Wed, 4 Oct 2017 12:42:56 +0000 (-0400) Subject: lib: move fd_set_nonblock() to fd-util.[ch] X-Git-Tag: 2.3.0.rc1~883 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=184d3a07c99f4622c16d99efc08d6516c2c8b48a;p=thirdparty%2Fdovecot%2Fcore.git lib: move fd_set_nonblock() to fd-util.[ch] --- diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 54e47da074..31577c078a 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -29,7 +29,6 @@ liblib_la_SOURCES = \ env-util.c \ execv-const.c \ failures.c \ - fd-set-nonblock.c \ fd-util.c \ fdatasync-path.c \ fdpass.c \ @@ -182,7 +181,6 @@ headers = \ env-util.h \ execv-const.h \ failures.h \ - fd-set-nonblock.h \ fd-util.h \ fdatasync-path.h \ fdpass.h \ diff --git a/src/lib/fd-set-nonblock.c b/src/lib/fd-set-nonblock.c deleted file mode 100644 index 4b76cd71db..0000000000 --- a/src/lib/fd-set-nonblock.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (c) 1999-2017 Dovecot authors, see the included COPYING file */ - -#include "lib.h" - -#include - -void fd_set_nonblock(int fd, bool nonblock) -{ - int flags; - - flags = fcntl(fd, F_GETFL, 0); - if (flags < 0) - i_fatal("fcntl(%d, F_GETFL) failed: %m", fd); - - if (nonblock) - flags |= O_NONBLOCK; - else - flags &= ~O_NONBLOCK; - - if (fcntl(fd, F_SETFL, flags) < 0) - i_fatal("fcntl(%d, F_SETFL) failed: %m", fd); -} diff --git a/src/lib/fd-set-nonblock.h b/src/lib/fd-set-nonblock.h deleted file mode 100644 index dd25628fa6..0000000000 --- a/src/lib/fd-set-nonblock.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef FD_SET_NONBLOCK_H -#define FD_SET_NONBLOCK_H - -/* Set file descriptor to blocking/nonblocking state */ -void fd_set_nonblock(int fd, bool nonblock); - -#endif diff --git a/src/lib/fd-util.c b/src/lib/fd-util.c index 6f5db11362..80c3c95b78 100644 --- a/src/lib/fd-util.c +++ b/src/lib/fd-util.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */ +/* Copyright (c) 1999-2017 Dovecot authors, see the included COPYING file */ #include "lib.h" #include "net.h" @@ -94,3 +94,20 @@ void fd_debug_verify_leaks(int first_fd, int last_fd) if (leaks) i_fatal("fd leak found"); } + +void fd_set_nonblock(int fd, bool nonblock) +{ + int flags; + + flags = fcntl(fd, F_GETFL, 0); + if (flags < 0) + i_fatal("fcntl(%d, F_GETFL) failed: %m", fd); + + if (nonblock) + flags |= O_NONBLOCK; + else + flags &= ~O_NONBLOCK; + + if (fcntl(fd, F_SETFL, flags) < 0) + i_fatal("fcntl(%d, F_SETFL) failed: %m", fd); +} diff --git a/src/lib/fd-util.h b/src/lib/fd-util.h index d0a1255511..bf81f69d79 100644 --- a/src/lib/fd-util.h +++ b/src/lib/fd-util.h @@ -1,12 +1,13 @@ #ifndef FD_UTIL_H #define FD_UTIL_H -#include "fd-set-nonblock.h" - /* Change close-on-exec flag of fd. */ void fd_close_on_exec(int fd, bool set); /* Verify that fds in given range don't exist. */ void fd_debug_verify_leaks(int first_fd, int last_fd); +/* Set file descriptor to blocking/nonblocking state */ +void fd_set_nonblock(int fd, bool nonblock); + #endif