diff options
author | Günther Deschner <gd@samba.org> | 2009-06-10 21:22:33 +0200 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2009-06-10 21:25:57 +0200 |
commit | 27bb7ac5d1ae1b22954024d74c02d9ffdb283def (patch) | |
tree | ca56116dce299f41970203fb11e40c85d1260a0e /lib | |
parent | dc5c7b7f98345621f4cf1b9992ebbe9144e14ebb (diff) | |
download | samba-27bb7ac5d1ae1b22954024d74c02d9ffdb283def.tar.gz samba-27bb7ac5d1ae1b22954024d74c02d9ffdb283def.tar.bz2 samba-27bb7ac5d1ae1b22954024d74c02d9ffdb283def.zip |
lib-util: move set_blocking() call into own file.
Guenther
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/blocking.c | 62 | ||||
-rw-r--r-- | lib/util/config.mk | 1 | ||||
-rw-r--r-- | lib/util/util.c | 31 |
3 files changed, 63 insertions, 31 deletions
diff --git a/lib/util/blocking.c b/lib/util/blocking.c new file mode 100644 index 0000000000..f5933cc92b --- /dev/null +++ b/lib/util/blocking.c @@ -0,0 +1,62 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 2001-2002 + Copyright (C) Simo Sorce 2001 + Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003. + Copyright (C) James J Myers 2003 + + 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/network.h" +#include "system/filesys.h" +#include "system/locale.h" +#undef malloc +#undef strcasecmp +#undef strncasecmp +#undef strdup +#undef realloc + +/** + 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 +} diff --git a/lib/util/config.mk b/lib/util/config.mk index 3bda8ec188..ad39096c56 100644 --- a/lib/util/config.mk +++ b/lib/util/config.mk @@ -22,6 +22,7 @@ LIBSAMBA-UTIL_OBJ_FILES = $(addprefix $(libutilsrcdir)/, \ util_file.o \ data_blob.o \ util.o \ + blocking.o \ util_net.o \ fsusage.o \ ms_fnmatch.o \ diff --git a/lib/util/util.c b/lib/util/util.c index 0148bdb00d..29b47f5858 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -146,37 +146,6 @@ _PUBLIC_ bool directory_create_or_exist(const char *dname, uid_t uid, /** - 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 -} - - -/** Sleep for a specified number of milliseconds. **/ |