aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-29 13:02:53 +0100
committerMax Kellermann <max@duempel.org>2013-10-29 13:02:53 +0100
commit163848ab3b4a1680ba30e167ea19e977c08556f5 (patch)
tree14f5813b3252916daddad649b643bc96db90c171 /src
parent03747ba93e29d76e664dcc493a21f320117d62d8 (diff)
downloadmpd-163848ab3b4a1680ba30e167ea19e977c08556f5.tar.gz
mpd-163848ab3b4a1680ba30e167ea19e977c08556f5.tar.xz
mpd-163848ab3b4a1680ba30e167ea19e977c08556f5.zip
fd_util: avoid unnecessary fcntl() calls
Diffstat (limited to 'src')
-rw-r--r--src/system/fd_util.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/system/fd_util.c b/src/system/fd_util.c
index 17976a5ee..b4a7032e6 100644
--- a/src/system/fd_util.c
+++ b/src/system/fd_util.c
@@ -58,15 +58,17 @@
static int
fd_mask_flags(int fd, int and_mask, int xor_mask)
{
- int ret;
-
assert(fd >= 0);
- ret = fcntl(fd, F_GETFD, 0);
- if (ret < 0)
- return ret;
+ const int old_flags = fcntl(fd, F_GETFD, 0);
+ if (old_flags < 0)
+ return old_flags;
+
+ const int new_flags = (old_flags & and_mask) ^ xor_mask;
+ if (new_flags == old_flags)
+ return old_flags;
- return fcntl(fd, F_SETFD, (ret & and_mask) ^ xor_mask);
+ return fcntl(fd, F_SETFD, new_flags);
}
#endif /* !WIN32 */