]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: move i_fd_close*() to fd-util.[ch]
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Wed, 4 Oct 2017 12:58:36 +0000 (08:58 -0400)
committerJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Thu, 5 Oct 2017 19:41:10 +0000 (15:41 -0400)
src/lib/fd-util.c
src/lib/fd-util.h
src/lib/lib.c
src/lib/macros.h

index 16cbe81b4b5ac6a957e4b28ba040893350ba7354..e1febae312cb01b10b3c7cb5204e07bc6296705c 100644 (file)
@@ -130,3 +130,25 @@ void fd_close_maybe_stdio(int *fd_in, int *fd_out)
                        i_fatal("dup2(/dev/null, %d) failed: %m", *fdp[i]);
        }
 }
+
+void i_close_fd_path_real(int *fd, const char *path, const char *arg,
+                         const char *func, const char *file, int line)
+{
+       int saved_errno;
+
+       if (*fd == -1)
+               return;
+
+       i_assert(*fd > 0);
+
+       saved_errno = errno;
+       if (unlikely(close(*fd) < 0))
+               i_error("%s: close(%s%s%s) @ %s:%d failed (fd=%d): %m",
+                       func, arg,
+                       (path == NULL) ? "" : " = ",
+                       (path == NULL) ? "" : path,
+                       file, line, *fd);
+       errno = saved_errno;
+
+       *fd = -1;
+}
index 0043eb99530d89291efbb5f40443c9ed6814ed1f..698536cd980849e7bff6ad6310e2ffe231719f41 100644 (file)
@@ -15,4 +15,12 @@ void fd_set_nonblock(int fd, bool nonblock);
    or stdout, they're replaced with /dev/null. */
 void fd_close_maybe_stdio(int *fd_in, int *fd_out);
 
+/* Close the fd and set it to -1. This assert-crashes if fd == 0, and is a
+   no-op if fd == -1. Normally fd == 0 would happen only if an uninitialized
+   fd is attempted to be closed, which is a bug. */
+void i_close_fd_path_real(int *fd, const char *path, const char *arg,
+                         const char *func, const char *file, int line);
+#define i_close_fd(fd) i_close_fd_path_real((fd), NULL, #fd, __func__, __FILE__, __LINE__)
+#define i_close_fd_path(fd, path) i_close_fd_path_real((fd), (path), #fd, __func__, __FILE__, __LINE__)
+
 #endif
index 3225a17c112ed2402c101cc1c9e65649628caf23..ccbce97801346302020d355a4151c99df8e35e54 100644 (file)
@@ -28,28 +28,6 @@ struct atexit_callback {
 
 static ARRAY(struct atexit_callback) atexit_callbacks = ARRAY_INIT;
 
-void i_close_fd_path_real(int *fd, const char *path, const char *arg,
-                         const char *func, const char *file, int line)
-{
-       int saved_errno;
-
-       if (*fd == -1)
-               return;
-
-       i_assert(*fd > 0);
-
-       saved_errno = errno;
-       if (unlikely(close(*fd) < 0))
-               i_error("%s: close(%s%s%s) @ %s:%d failed (fd=%d): %m",
-                       func, arg,
-                       (path == NULL) ? "" : " = ",
-                       (path == NULL) ? "" : path,
-                       file, line, *fd);
-       errno = saved_errno;
-
-       *fd = -1;
-}
-
 #undef i_unlink
 int i_unlink(const char *path, const char *source_fname,
             unsigned int source_linenum)
index dc73441242870b841e5c0f0c3f90ca8ef7759136..eec7cd2f02c3db510b1d1eb295c61d9927db64a5 100644 (file)
 
 #endif
 
-/* Close the fd and set it to -1. This assert-crashes if fd == 0, and is a
-   no-op if fd == -1. Normally fd == 0 would happen only if an uninitialized
-   fd is attempted to be closed, which is a bug. */
-void i_close_fd_path_real(int *fd, const char *path, const char *arg,
-                         const char *func, const char *file, int line);
-#define i_close_fd(fd) i_close_fd_path_real((fd), NULL, #fd, __func__, __FILE__, __LINE__)
-#define i_close_fd_path(fd, path) i_close_fd_path_real((fd), (path), #fd, __func__, __FILE__, __LINE__)
-
 #ifndef STATIC_CHECKER
 #  define i_unreached() \
        i_panic("file %s: line %d: unreached", __FILE__, __LINE__)