-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
52 lines (46 loc) · 1.24 KB
/
util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* --*- c -*--
* Copyright (C) 2014 Enrico Scholz <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include "capture.h"
bool read_all(int fd, void *dst, size_t len, bool *eof)
{
while (len > 0) {
ssize_t l = read(fd, dst, len);
if (l > 0) {
dst += l;
len -= l;
} else if (l == 0) {
if (eof)
*eof = true;
else
fprintf(stderr, "read_all: read(): EOF\n");
break;
} else if (errno == EINTR) {
continue;
} else {
fprintf(stderr, "read_all: read(): %s\n",
strerror(errno));
break;
}
}
return len == 0;
}