summaryrefslogtreecommitdiffstats
path: root/ctdb/lib/util/util.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2013-11-13 14:17:32 +0100
committerMichael Adam <obnox@samba.org>2013-11-13 14:18:52 +0100
commitf087a8e2b81fae82fa571ef09d2d1cb682cc8ff8 (patch)
treed4a6b14a1594958150b733180d995b5c32025017 /ctdb/lib/util/util.c
parente80a5aba3db8e81173fa443991e08ef4a300ea5c (diff)
parent25f3c8b5269863aadbe72e304da7012782ef5b25 (diff)
downloadsamba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.tar.gz
samba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.tar.xz
samba-f087a8e2b81fae82fa571ef09d2d1cb682cc8ff8.zip
Merge branch 'master' of ctdb into 'master' of samba
Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'ctdb/lib/util/util.c')
-rw-r--r--ctdb/lib/util/util.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/ctdb/lib/util/util.c b/ctdb/lib/util/util.c
new file mode 100644
index 0000000000..af52805995
--- /dev/null
+++ b/ctdb/lib/util/util.c
@@ -0,0 +1,52 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Copyright (C) Andrew Tridgell 2005
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "system/filesys.h"
+
+
+/**
+ Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available,
+ else
+ if SYSV use O_NDELAY
+ if BSD use FNDELAY
+**/
+
+_PUBLIC_ int set_blocking(int fd, bool set)
+{
+ int val;
+#ifdef O_NONBLOCK
+#define FLAG_TO_SET O_NONBLOCK
+#else
+#ifdef SYSV
+#define FLAG_TO_SET O_NDELAY
+#else /* BSD */
+#define FLAG_TO_SET FNDELAY
+#endif
+#endif
+
+ if((val = fcntl(fd, F_GETFL, 0)) == -1)
+ return -1;
+ if(set) /* Turn blocking on - ie. clear nonblock flag */
+ val &= ~FLAG_TO_SET;
+ else
+ val |= FLAG_TO_SET;
+ return fcntl( fd, F_SETFL, val);
+#undef FLAG_TO_SET
+}