Update.
[glibc.git] / db2 / os / os_rw.c
blob7591041981697aa0e516681ae797640a6b5e5d76
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)os_rw.c 10.7 (Sleepycat) 4/10/98";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
17 #include <errno.h>
18 #include <unistd.h>
19 #endif
21 #include "db_int.h"
24 * __db_read --
25 * Read from a file handle.
27 * PUBLIC: int __db_read __P((int, void *, size_t, ssize_t *));
29 int
30 __db_read(fd, addr, len, nrp)
31 int fd;
32 void *addr;
33 size_t len;
34 ssize_t *nrp;
36 size_t offset;
37 ssize_t nr;
38 u_int8_t *taddr;
40 for (taddr = addr,
41 offset = 0; offset < len; taddr += nr, offset += nr) {
42 if ((nr = __os_read(fd, taddr, len - offset)) < 0)
43 return (errno);
44 if (nr == 0)
45 break;
47 *nrp = taddr - (u_int8_t *)addr;
48 return (0);
52 * __db_write --
53 * Write to a file handle.
55 * PUBLIC: int __db_write __P((int, void *, size_t, ssize_t *));
57 int
58 __db_write(fd, addr, len, nwp)
59 int fd;
60 void *addr;
61 size_t len;
62 ssize_t *nwp;
64 size_t offset;
65 ssize_t nw;
66 u_int8_t *taddr;
68 for (taddr = addr,
69 offset = 0; offset < len; taddr += nw, offset += nw)
70 if ((nw = __os_write(fd, taddr, len - offset)) < 0)
71 return (errno);
72 *nwp = len;
73 return (0);