Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/kinit/xpio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 815 - (show annotations) (download)
Fri Apr 24 18:32:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 766 byte(s)
-updated to klibc-1.5.15
1 /*
2 * Looping versions of pread() and pwrite()
3 */
4
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <errno.h>
8
9 #include "xpio.h"
10
11 ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
12 {
13 ssize_t ctr = 0;
14 ssize_t rv = 0;
15 char *bp = buf;
16
17 while (count) {
18 rv = pread(fd, bp, count, offset);
19
20 if (rv == 0 || (rv == -1 && errno != EINTR))
21 break;
22
23 bp += rv;
24 count -= rv;
25 offset += rv;
26 ctr += rv;
27 }
28
29 return ctr ? ctr : rv;
30 }
31
32 ssize_t xpwrite(int fd, void *buf, size_t count, off_t offset)
33 {
34 ssize_t ctr = 0;
35 ssize_t rv = 0;
36 char *bp = buf;
37
38 while (count) {
39 rv = pwrite(fd, bp, count, offset);
40
41 if (rv == 0 || (rv == -1 && errno != EINTR))
42 break;
43
44 bp += rv;
45 count -= rv;
46 offset += rv;
47 ctr += rv;
48 }
49
50 return ctr ? ctr : rv;
51 }