Use pread/pwrite instead of lseek followed by read/write.
authorPeter Avalos <pavalos@theshell.com>
Sun, 8 Feb 2009 16:41:07 +0000 (11:41 -0500)
committerPeter Avalos <pavalos@theshell.com>
Tue, 7 Apr 2009 07:09:12 +0000 (21:09 -1000)
Obtained-from: FreeBSD

lib/libc/db/mpool/mpool.c

index 1a6433d..d95c72c 100644 (file)
@@ -191,9 +191,8 @@ mpool_get(MPOOL *mp, pgno_t pgno, u_int flags __unused)
        ++mp->pageread;
 #endif
        off = mp->pagesize * pgno;
        ++mp->pageread;
 #endif
        off = mp->pagesize * pgno;
-       if (lseek(mp->fd, off, SEEK_SET) != off)
-               return (NULL);
-       if ((nr = _read(mp->fd, bp->page, mp->pagesize)) != mp->pagesize) {
+       nr = pread(mp->fd, bp->page, mp->pagesize, off);
+       if (nr != mp->pagesize) {
                if (nr >= 0)
                        errno = EFTYPE;
                return (NULL);
                if (nr >= 0)
                        errno = EFTYPE;
                return (NULL);
@@ -357,9 +356,7 @@ mpool_write(MPOOL *mp, BKT *bp)
                (mp->pgout)(mp->pgcookie, bp->pgno, bp->page);
 
        off = mp->pagesize * bp->pgno;
                (mp->pgout)(mp->pgcookie, bp->pgno, bp->page);
 
        off = mp->pagesize * bp->pgno;
-       if (lseek(mp->fd, off, SEEK_SET) != off)
-               return (RET_ERROR);
-       if (_write(mp->fd, bp->page, mp->pagesize) != mp->pagesize)
+       if (pwrite(mp->fd, bp->page, mp->pagesize, off) != mp->pagesize)
                return (RET_ERROR);
 
        bp->flags &= ~MPOOL_DIRTY;
                return (RET_ERROR);
 
        bp->flags &= ~MPOOL_DIRTY;