diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-01-31 03:51:22 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-01-31 03:51:22 +0000 |
commit | 21d8ae059d2a81f4fd840680b415c5a415385513 (patch) | |
tree | 2dc56bfed70795261f3ce39150697306ef87d130 /lib/libc | |
parent | 8c27d4f6c9fc500439427662013e027b85a5d1c9 (diff) |
Use pread(2) and pwrite(2) instead of lseek(2) + read(2) / write(2).
Based on changes from NetBSD (thorpej).
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/db/hash/hash.c | 7 | ||||
-rw-r--r-- | lib/libc/db/hash/hash_page.c | 10 | ||||
-rw-r--r-- | lib/libc/db/mpool/mpool.c | 27 |
3 files changed, 20 insertions, 24 deletions
diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c index f647dc81bed..88c07a0fef4 100644 --- a/lib/libc/db/hash/hash.c +++ b/lib/libc/db/hash/hash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hash.c,v 1.10 2001/08/04 21:11:10 millert Exp $ */ +/* $OpenBSD: hash.c,v 1.11 2002/01/31 03:51:21 millert Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; #else -static char rcsid[] = "$OpenBSD: hash.c,v 1.10 2001/08/04 21:11:10 millert Exp $"; +static char rcsid[] = "$OpenBSD: hash.c,v 1.11 2002/01/31 03:51:21 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -502,8 +502,7 @@ flush_meta(hashp) whdrp = &whdr; swap_header_copy(&hashp->hdr, whdrp); #endif - if ((lseek(fp, (off_t)0, SEEK_SET) == -1) || - ((wsize = write(fp, whdrp, sizeof(HASHHDR))) == -1)) + if ((wsize = pwrite(fp, whdrp, sizeof(HASHHDR), (off_t)0)) == -1) return (-1); else if (wsize != sizeof(HASHHDR)) { diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 80d6c0a81eb..0936f6a12e1 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hash_page.c,v 1.7 1999/02/15 05:11:24 millert Exp $ */ +/* $OpenBSD: hash_page.c,v 1.8 2002/01/31 03:51:21 millert Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; #else -static char rcsid[] = "$OpenBSD: hash_page.c,v 1.7 1999/02/15 05:11:24 millert Exp $"; +static char rcsid[] = "$OpenBSD: hash_page.c,v 1.8 2002/01/31 03:51:21 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -543,8 +543,7 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) page = BUCKET_TO_PAGE(bucket); else page = OADDR_TO_PAGE(bucket); - if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || - ((rsize = read(fd, p, size)) == -1)) + if ((rsize = pread(fd, p, size, (off_t)page << hashp->BSHIFT)) == -1) return (-1); bp = (u_int16_t *)p; if (!rsize) @@ -614,8 +613,7 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) page = BUCKET_TO_PAGE(bucket); else page = OADDR_TO_PAGE(bucket); - if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || - ((wsize = write(fd, p, size)) == -1)) + if ((wsize = pwrite(fd, p, size, (off_t)page << hashp->BSHIFT)) == -1) /* Errno is set */ return (-1); if (wsize != size) { diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c index 008132644f1..bb4c0ac9a9a 100644 --- a/lib/libc/db/mpool/mpool.c +++ b/lib/libc/db/mpool/mpool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpool.c,v 1.6 1999/02/15 05:11:25 millert Exp $ */ +/* $OpenBSD: mpool.c,v 1.7 2002/01/31 03:51:21 millert Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)mpool.c 8.7 (Berkeley) 11/2/95"; #else -static char rcsid[] = "$OpenBSD: mpool.c,v 1.6 1999/02/15 05:11:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: mpool.c,v 1.7 2002/01/31 03:51:21 millert Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -238,20 +238,21 @@ mpool_get(mp, pgno, flags) ++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) { - if (nr > 0) { - /* A partial read is definitely bad. */ - errno = EINVAL; + if ((nr = pread(mp->fd, bp->page, mp->pagesize, off)) != mp->pagesize) { + switch (nr) { + case -1: + /* errno is set for us by pread(). */ return (NULL); - } else { + case 0: /* - * A zero-length reads, means you need to create a + * A zero-length read means you need to create a * new page. */ memset(bp->page, 0, mp->pagesize); + default: + /* A partial read is definitely bad. */ + errno = EINVAL; + return (NULL); } } @@ -426,9 +427,7 @@ mpool_write(mp, bp) (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; |