oui: Make parsing of oui.conf more robust
[netsniff-ng.git] / ioexact.c
blob1600784d993eb8871d27d47e65d2df0cce786ac2
1 #include <errno.h>
2 #include <unistd.h>
3 #include <signal.h>
5 #include "ioexact.h"
7 extern volatile sig_atomic_t sigint;
9 ssize_t read_exact(int fd, void *buf, size_t len, int mayexit)
11 ssize_t num = 0, written;
13 while (len > 0 && !sigint) {
14 if ((written = read(fd, buf, len)) < 0) {
15 if (errno == EAGAIN && num > 0)
16 continue;
17 if (mayexit)
18 return -1;
19 else
20 continue;
22 if (!written)
23 return 0;
24 len -= written;
25 buf += written;
26 num += written;
29 return num;
32 ssize_t write_exact(int fd, void *buf, size_t len, int mayexit)
34 ssize_t num = 0, written;
36 while (len > 0 && !sigint) {
37 if ((written = write(fd, buf, len)) < 0) {
38 if (errno == EAGAIN && num > 0)
39 continue;
40 if (mayexit)
41 return -1;
42 else
43 continue;
45 if (!written)
46 return 0;
47 len -= written;
48 buf += written;
49 num += written;
52 return num;