8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / db / os / os_rw.c
blob46eac1bf518e75ca36bd1479b4d0cde38de3c2cb
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.11 (Sleepycat) 10/12/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"
22 #include "os_jump.h"
25 * __os_io --
26 * Do an I/O.
28 * PUBLIC: int __os_io __P((DB_IO *, int, ssize_t *));
30 int
31 __os_io(db_iop, op, niop)
32 DB_IO *db_iop;
33 int op;
34 ssize_t *niop;
36 int ret;
38 #ifdef HAVE_PREAD
39 switch (op) {
40 case DB_IO_READ:
41 if (__db_jump.j_read != NULL)
42 goto slow;
43 *niop = pread(db_iop->fd_io, db_iop->buf,
44 db_iop->bytes, (off_t)db_iop->pgno * db_iop->pagesize);
45 break;
46 case DB_IO_WRITE:
47 if (__db_jump.j_write != NULL)
48 goto slow;
49 *niop = pwrite(db_iop->fd_io, db_iop->buf,
50 db_iop->bytes, (off_t)db_iop->pgno * db_iop->pagesize);
51 break;
53 if (*niop == db_iop->bytes)
54 return (0);
55 slow:
56 #endif
57 if (db_iop->mutexp != NULL)
58 (void)__db_mutex_lock(db_iop->mutexp, db_iop->fd_lock);
60 if ((ret = __os_seek(db_iop->fd_io,
61 db_iop->pagesize, db_iop->pgno, 0, 0, SEEK_SET)) != 0)
62 goto err;
63 switch (op) {
64 case DB_IO_READ:
65 ret =
66 __os_read(db_iop->fd_io, db_iop->buf, db_iop->bytes, niop);
67 break;
68 case DB_IO_WRITE:
69 ret =
70 __os_write(db_iop->fd_io, db_iop->buf, db_iop->bytes, niop);
71 break;
74 err: if (db_iop->mutexp != NULL)
75 (void)__db_mutex_unlock(db_iop->mutexp, db_iop->fd_lock);
77 return (ret);
82 * __os_read --
83 * Read from a file handle.
85 * PUBLIC: int __os_read __P((int, void *, size_t, ssize_t *));
87 int
88 __os_read(fd, addr, len, nrp)
89 int fd;
90 void *addr;
91 size_t len;
92 ssize_t *nrp;
94 size_t offset;
95 ssize_t nr;
96 u_int8_t *taddr;
98 for (taddr = addr,
99 offset = 0; offset < len; taddr += nr, offset += nr) {
100 if ((nr = __db_jump.j_read != NULL ?
101 __db_jump.j_read(fd, taddr, len - offset) :
102 read(fd, taddr, len - offset)) < 0)
103 return (errno);
104 if (nr == 0)
105 break;
107 *nrp = taddr - (u_int8_t *)addr;
108 return (0);
112 * __os_write --
113 * Write to a file handle.
115 * PUBLIC: int __os_write __P((int, void *, size_t, ssize_t *));
118 __os_write(fd, addr, len, nwp)
119 int fd;
120 void *addr;
121 size_t len;
122 ssize_t *nwp;
124 size_t offset;
125 ssize_t nw;
126 u_int8_t *taddr;
128 for (taddr = addr,
129 offset = 0; offset < len; taddr += nw, offset += nw)
130 if ((nw = __db_jump.j_write != NULL ?
131 __db_jump.j_write(fd, taddr, len - offset) :
132 write(fd, taddr, len - offset)) < 0)
133 return (errno);
134 *nwp = len;
135 return (0);