# HG changeset patch # User Timo Sirainen # Date 1139924518 -7200 # Node ID 323c09be5f0067ab4ce5898542757e9950fe665f # Parent 6519f3c7bd63113248d8024273b9855afc046400 Moved dupliated close_save_errno() code to public close_keep_errno() function. diff -r 6519f3c7bd63 -r 323c09be5f00 src/lib/Makefile.am --- a/src/lib/Makefile.am Tue Feb 14 15:06:58 2006 +0200 +++ b/src/lib/Makefile.am Tue Feb 14 15:41:58 2006 +0200 @@ -4,6 +4,7 @@ base64.c \ bsearch-insert-pos.c \ buffer.c \ + close-keep-errno.c \ compat.c \ data-stack.c \ env-util.c \ @@ -85,6 +86,7 @@ base64.h \ bsearch-insert-pos.h \ buffer.h \ + close-keep-errno.h \ compat.h \ data-stack.h \ env-util.h \ diff -r 6519f3c7bd63 -r 323c09be5f00 src/lib/close-keep-errno.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/close-keep-errno.c Tue Feb 14 15:41:58 2006 +0200 @@ -0,0 +1,13 @@ +/* Copyright (c) 2006 Timo Sirainen */ + +#include "lib.h" +#include "close-keep-errno.h" + +#include + +void close_keep_errno(int fd) +{ + int old_errno = errno; + (void)close(fd); + errno = old_errno; +} diff -r 6519f3c7bd63 -r 323c09be5f00 src/lib/close-keep-errno.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/close-keep-errno.h Tue Feb 14 15:41:58 2006 +0200 @@ -0,0 +1,7 @@ +#ifndef __CLOSE_KEEP_ERRNO_H +#define __CLOSE_KEEP_ERRNO_H + +/* Close the file handle without changing errno. */ +void close_keep_errno(int fd); + +#endif diff -r 6519f3c7bd63 -r 323c09be5f00 src/lib/network.c --- a/src/lib/network.c Tue Feb 14 15:06:58 2006 +0200 +++ b/src/lib/network.c Tue Feb 14 15:41:58 2006 +0200 @@ -1,6 +1,7 @@ /* Copyright (c) 1999-2005 Timo Sirainen */ #include "lib.h" +#include "close-keep-errno.h" #include "fd-set-nonblock.h" #include "network.h" @@ -101,13 +102,6 @@ return 0; } -static inline void close_save_errno(int fd) -{ - int old_errno = errno; - (void)close(fd); - errno = old_errno; -} - /* Connect to socket with ip address */ int net_connect_ip(const struct ip_addr *ip, unsigned int port, const struct ip_addr *my_ip) @@ -141,7 +135,7 @@ if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) { /* failed, set it back to INADDR_ANY */ i_error("bind(%s) failed: %m", net_ip2addr(my_ip)); - close_save_errno(fd); + close_keep_errno(fd); return -1; } } @@ -157,7 +151,7 @@ if (ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK) #endif { - close_save_errno(fd); + close_keep_errno(fd); return -1; } @@ -189,7 +183,7 @@ /* connect */ ret = connect(fd, (struct sockaddr *) &sa, sizeof(sa)); if (ret < 0 && errno != EINPROGRESS) { - close_save_errno(fd); + close_keep_errno(fd); return -1; } @@ -305,7 +299,7 @@ } /* error */ - close_save_errno(fd); + close_keep_errno(fd); return -1; } @@ -342,7 +336,7 @@ i_error("listen() failed: %m"); } - close_save_errno(fd); + close_keep_errno(fd); return -1; } diff -r 6519f3c7bd63 -r 323c09be5f00 src/lib/unlink-directory.c --- a/src/lib/unlink-directory.c Tue Feb 14 15:06:58 2006 +0200 +++ b/src/lib/unlink-directory.c Tue Feb 14 15:41:58 2006 +0200 @@ -33,6 +33,7 @@ #define _GNU_SOURCE /* for O_NOFOLLOW with Linux */ #include "lib.h" +#include "close-keep-errno.h" #include "unlink-directory.h" #include @@ -40,13 +41,6 @@ #include #include -#define close_save_errno(fd) \ - STMT_START { \ - old_errno = errno; \ - (void)close(fd); \ - errno = old_errno; \ - } STMT_END - static int unlink_directory_r(const char *dir) { DIR *dirp; @@ -74,7 +68,7 @@ return -1; if (fstat(dir_fd, &st2) < 0) { - close_save_errno(dir_fd); + close_keep_errno(dir_fd); return -1; } @@ -87,13 +81,13 @@ } #endif if (fchdir(dir_fd) < 0) { - close_save_errno(dir_fd); + close_keep_errno(dir_fd); return -1; } dirp = opendir("."); if (dirp == NULL) { - close_save_errno(dir_fd); + close_keep_errno(dir_fd); return -1; }