Fix pg_dump bug in the database-level collation patch. "datcollate" and
[PostgreSQL.git] / src / port / noblock.c
blob71a8eb6c277690970d2e48d15f86f8daf1506834
1 /*-------------------------------------------------------------------------
3 * noblock.c
4 * set a file descriptor as non-blocking
6 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * IDENTIFICATION
10 * $PostgreSQL$
12 *-------------------------------------------------------------------------
15 #include "c.h"
17 #include <fcntl.h>
20 bool
21 pg_set_noblock(int sock)
23 #if !defined(WIN32)
24 return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
25 #else
26 long ioctlsocket_ret = 1;
28 /* Returns non-0 on failure, while fcntl() returns -1 on failure */
29 return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
30 #endif
34 bool
35 pg_set_block(int sock)
37 #if !defined(WIN32)
38 int flags;
40 flags = fcntl(sock, F_GETFL);
41 if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK)))
42 return false;
43 return true;
44 #else
45 long ioctlsocket_ret = 0;
47 /* Returns non-0 on failure, while fcntl() returns -1 on failure */
48 return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
49 #endif