summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-07-28 23:19:29 +0200
committerLennart Poettering <lennart@poettering.net>2008-07-28 23:19:29 +0200
commita11ddeff5b8ca56b8d586dcf09e9be0eb4bc1d6e (patch)
tree4d7830b5ec05e9d2108a510cedc2ac32d6f5883c
parent75db16f201b3a06ca55be9956890b2a103829ffb (diff)
don't call fcntl unless we have to
-rw-r--r--libdaemon/dnonblock.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/libdaemon/dnonblock.c b/libdaemon/dnonblock.c
index b93d875..c16d511 100644
--- a/libdaemon/dnonblock.c
+++ b/libdaemon/dnonblock.c
@@ -27,17 +27,18 @@
#include "dnonblock.h"
int daemon_nonblock(int fd, int b) {
- int a;
+ int a, c;
+
if ((a = fcntl(fd, F_GETFL)) < 0)
return -1;
if (b)
- a |= O_NDELAY;
+ c = a | O_NDELAY;
else
- a &= ~O_NDELAY;
+ c = a & ~O_NDELAY;
- if (fcntl(fd, F_SETFL, a) < 0)
- return -1;
+ if (c == a)
+ return 0;
- return 0;
+ return fcntl(fd, F_SETFL, a);
}