blob: 6c502792a0eab1f53484f0ea1015e28eb9460e89 [file] [log] [blame]
Lennart Poetteringc73f5e42004-12-18 22:22:54 +00001/* $Id$ */
2
Lennart Poetteringe774e8e2003-07-31 14:18:41 +00003/*
4 * This file is part of libdaemon.
5 *
6 * libdaemon is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * libdaemon is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with libdaemon; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 */
20
Lennart Poettering191905c2004-08-23 18:52:43 +000021#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
Lennart Poetteringe774e8e2003-07-31 14:18:41 +000025#include <fcntl.h>
26
27#include "dnonblock.h"
28
29int daemon_nonblock(int fd, int b) {
30 int a;
31 if ((a = fcntl(fd, F_GETFL)) < 0)
32 return -1;
33
34 if (b)
35 a |= O_NDELAY;
36 else
37 a &= ~O_NDELAY;
38
39 if (fcntl(fd, F_SETFL, a) < 0)
40 return -1;
41
42 return 0;
43}