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