diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-05-07 09:02:24 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-05-07 09:02:24 +0000 |
commit | 30981883e827aa69632bca87e2764ef1ab152fa8 (patch) | |
tree | e1095f47308154adb4c7d01f0b14a4f737d2da8e /lib/libc/db/recno/rec_open.c | |
parent | 6a0d2fe1f44c1b101f0a8a97b06b5e847918cf81 (diff) |
db release 1.85
Diffstat (limited to 'lib/libc/db/recno/rec_open.c')
-rw-r--r-- | lib/libc/db/recno/rec_open.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/lib/libc/db/recno/rec_open.c b/lib/libc/db/recno/rec_open.c index e67a7b6f000..d2c9369b730 100644 --- a/lib/libc/db/recno/rec_open.c +++ b/lib/libc/db/recno/rec_open.c @@ -1,7 +1,7 @@ -/* $NetBSD: rec_open.c,v 1.6 1995/02/27 13:25:05 cgd Exp $ */ +/* $NetBSD: rec_open.c,v 1.7 1996/05/03 21:38:49 cgd Exp $ */ /*- - * Copyright (c) 1990, 1993 + * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -38,9 +38,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #if 0 -static char sccsid[] = "@(#)rec_open.c 8.6 (Berkeley) 2/22/94"; +static char sccsid[] = "@(#)rec_open.c 8.10 (Berkeley) 9/1/94"; #else -static char rcsid[] = "$NetBSD: rec_open.c,v 1.6 1995/02/27 13:25:05 cgd Exp $"; +static char rcsid[] = "$NetBSD: rec_open.c,v 1.7 1996/05/03 21:38:49 cgd Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -104,7 +104,7 @@ __rec_open(fname, flags, mode, openinfo, dflags) t = dbp->internal; if (openinfo) { if (openinfo->flags & R_FIXEDLEN) { - SET(t, R_FIXLEN); + F_SET(t, R_FIXLEN); t->bt_reclen = openinfo->reclen; if (t->bt_reclen == 0) goto einval; @@ -113,12 +113,11 @@ __rec_open(fname, flags, mode, openinfo, dflags) } else t->bt_bval = '\n'; - SET(t, R_RECNO); + F_SET(t, R_RECNO); if (fname == NULL) - SET(t, R_EOF | R_INMEM); + F_SET(t, R_EOF | R_INMEM); else t->bt_rfd = rfd; - t->bt_rcursor = 0; if (fname != NULL) { /* @@ -130,20 +129,20 @@ __rec_open(fname, flags, mode, openinfo, dflags) if (lseek(rfd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) { switch (flags & O_ACCMODE) { case O_RDONLY: - SET(t, R_RDONLY); + F_SET(t, R_RDONLY); break; default: goto einval; } slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) goto err; - SET(t, R_CLOSEFP); + F_SET(t, R_CLOSEFP); t->bt_irec = - ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe; + F_ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe; } else { switch (flags & O_ACCMODE) { case O_RDONLY: - SET(t, R_RDONLY); + F_SET(t, R_RDONLY); break; case O_RDWR: break; @@ -163,8 +162,16 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) * fails if the file is too large. */ if (sb.st_size == 0) - SET(t, R_EOF); + F_SET(t, R_EOF); else { +#ifdef MMAP_NOT_AVAILABLE + /* + * XXX + * Mmap doesn't work correctly on many current + * systems. In particular, it can fail subtly, + * with cache coherency problems. Don't use it + * for now. + */ t->bt_msize = sb.st_size; if ((t->bt_smap = mmap(NULL, t->bt_msize, PROT_READ, MAP_PRIVATE, rfd, @@ -172,9 +179,12 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) goto slow; t->bt_cmap = t->bt_smap; t->bt_emap = t->bt_smap + sb.st_size; - t->bt_irec = ISSET(t, R_FIXLEN) ? + t->bt_irec = F_ISSET(t, R_FIXLEN) ? __rec_fmap : __rec_vmap; - SET(t, R_MEMMAPPED); + F_SET(t, R_MEMMAPPED); +#else + goto slow; +#endif } } } @@ -192,13 +202,14 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) if ((h = mpool_get(t->bt_mp, P_ROOT, 0)) == NULL) goto err; if ((h->flags & P_TYPE) == P_BLEAF) { - h->flags = h->flags & ~P_TYPE | P_RLEAF; + F_CLR(h, P_TYPE); + F_SET(h, P_RLEAF); mpool_put(t->bt_mp, h, MPOOL_DIRTY); } else mpool_put(t->bt_mp, h, 0); if (openinfo && openinfo->flags & R_SNAPSHOT && - !ISSET(t, R_EOF | R_INMEM) && + !F_ISSET(t, R_EOF | R_INMEM) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) goto err; return (dbp); @@ -228,7 +239,7 @@ __rec_fd(dbp) } /* In-memory database can't have a file descriptor. */ - if (ISSET(t, R_INMEM)) { + if (F_ISSET(t, R_INMEM)) { errno = ENOENT; return (-1); } |