blob: 79b743a0a1622ed2455c81a7190b9ce187ed4539 [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 *
Lennart Poettering70df7aa2005-11-18 20:39:12 +00006 * libdaemon is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
Lennart Poetteringe774e8e2003-07-31 14:18:41 +000010 *
11 * libdaemon is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
Lennart Poettering70df7aa2005-11-18 20:39:12 +000013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
Lennart Poetteringe774e8e2003-07-31 14:18:41 +000015 *
Lennart Poettering70df7aa2005-11-18 20:39:12 +000016 * You should have received a copy of the GNU Lesser General Public
17 * License along with libdaemon; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
Lennart Poetteringe774e8e2003-07-31 14:18:41 +000020 */
21
Lennart Poettering191905c2004-08-23 18:52:43 +000022#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
Lennart Poetteringe774e8e2003-07-31 14:18:41 +000026#include <fcntl.h>
27
28#include "dnonblock.h"
29
30int daemon_nonblock(int fd, int b) {
31 int a;
32 if ((a = fcntl(fd, F_GETFL)) < 0)
33 return -1;
34
35 if (b)
36 a |= O_NDELAY;
37 else
38 a &= ~O_NDELAY;
39
40 if (fcntl(fd, F_SETFL, a) < 0)
41 return -1;
42
43 return 0;
44}