3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
6 * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <sys/types.h>
30 #define min(a,b) ( (a)<(b) ? (a):(b) )
34 extern volatile sig_atomic_t __io_canceled;
36 static inline void io_init(void)
41 static inline void io_cancel(void)
46 /* Read exactly len bytes (Signal safe)*/
47 static inline int read_n(int fd, char *buf, int len)
49 register int t = 0, w;
51 while (!__io_canceled && len > 0) {
52 if ((w = read(fd, buf, len)) < 0) {
53 if (errno == EINTR || errno == EAGAIN)
67 /* Write exactly len bytes (Signal safe)*/
68 static inline int write_n(int fd, char *buf, int len)
70 register int t = 0, w;
72 while (!__io_canceled && len > 0) {
73 if ((w = write(fd, buf, len)) < 0) {
74 if (errno == EINTR || errno == EAGAIN)