Lennart Poettering | c73f5e4 | 2004-12-18 22:22:54 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | |
Lennart Poettering | e774e8e | 2003-07-31 14:18:41 +0000 | [diff] [blame] | 3 | /* |
| 4 | * This file is part of libdaemon. |
| 5 | * |
Lennart Poettering | 70df7aa | 2005-11-18 20:39:12 +0000 | [diff] [blame] | 6 | * 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 Poettering | e774e8e | 2003-07-31 14:18:41 +0000 | [diff] [blame] | 10 | * |
| 11 | * libdaemon is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
Lennart Poettering | 70df7aa | 2005-11-18 20:39:12 +0000 | [diff] [blame] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
Lennart Poettering | e774e8e | 2003-07-31 14:18:41 +0000 | [diff] [blame] | 15 | * |
Lennart Poettering | 70df7aa | 2005-11-18 20:39:12 +0000 | [diff] [blame] | 16 | * 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 Poettering | e774e8e | 2003-07-31 14:18:41 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Lennart Poettering | 191905c | 2004-08-23 18:52:43 +0000 | [diff] [blame] | 22 | #ifdef HAVE_CONFIG_H |
| 23 | #include <config.h> |
| 24 | #endif |
| 25 | |
Lennart Poettering | e774e8e | 2003-07-31 14:18:41 +0000 | [diff] [blame] | 26 | #include <fcntl.h> |
| 27 | |
| 28 | #include "dnonblock.h" |
| 29 | |
| 30 | int 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 | } |