/[path-sandbox]/trunk/libsbutil/sb_read.c
Gentoo

Contents of /trunk/libsbutil/sb_read.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 370 - (show annotations) (download) (as text)
Sun Nov 9 10:29:58 2008 UTC (6 years, 1 month ago) by vapier
File MIME type: text/x-csrc
File size: 707 byte(s)
consolidate all random system includes into headers.h
1 /*
2 * sb_write.c
3 *
4 * IO functions.
5 *
6 * Copyright 1999-2008 Gentoo Foundation
7 * Licensed under the GPL-2
8 */
9
10 #include "headers.h"
11 #include "sbutil.h"
12
13 /* General purpose function to _reliably_ read from a file.
14 *
15 * Returns total read bytes or -1 on error.
16 */
17
18 size_t sb_read(int fd, void *buf, size_t count)
19 {
20 ssize_t n;
21 size_t accum = 0;
22
23 do {
24 n = read(fd, buf + accum, count - accum);
25
26 if (n > 0) {
27 accum += n;
28 continue;
29 }
30
31 if (n < 0) {
32 if (EINTR == errno) {
33 /* Reset errno to not trigger DBG_MSG */
34 errno = 0;
35 continue;
36 }
37
38 DBG_MSG("Failed to read from fd=%i!\n", fd);
39 return -1;
40 }
41
42 /* Found EOF */
43 break;
44 } while (accum < count);
45
46 return accum;
47 }

  ViewVC Help
Powered by ViewVC 1.1.20