summaryrefslogtreecommitdiff
path: root/lib/libc/db/recno/rec_get.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/db/recno/rec_get.c')
-rw-r--r--lib/libc/db/recno/rec_get.c109
1 files changed, 59 insertions, 50 deletions
diff --git a/lib/libc/db/recno/rec_get.c b/lib/libc/db/recno/rec_get.c
index bc25104e552..a08e16f8089 100644
--- a/lib/libc/db/recno/rec_get.c
+++ b/lib/libc/db/recno/rec_get.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rec_get.c,v 1.7 1995/02/27 13:24:57 cgd Exp $ */
+/* $NetBSD: rec_get.c,v 1.8 1996/05/03 21:38:48 cgd Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -35,9 +35,9 @@
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
-static char sccsid[] = "@(#)rec_get.c 8.5 (Berkeley) 6/20/94";
+static char sccsid[] = "@(#)rec_get.c 8.9 (Berkeley) 8/18/94";
#else
-static char rcsid[] = "$NetBSD: rec_get.c,v 1.7 1995/02/27 13:24:57 cgd Exp $";
+static char rcsid[] = "$NetBSD: rec_get.c,v 1.8 1996/05/03 21:38:48 cgd Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -96,7 +96,7 @@ __rec_get(dbp, key, data, flags)
* original file.
*/
if (nrec > t->bt_nrecs) {
- if (ISSET(t, R_EOF | R_INMEM))
+ if (F_ISSET(t, R_EOF | R_INMEM))
return (RET_SPECIAL);
if ((status = t->bt_irec(t, nrec)) != RET_SUCCESS)
return (status);
@@ -107,7 +107,7 @@ __rec_get(dbp, key, data, flags)
return (RET_ERROR);
status = __rec_ret(t, e, 0, NULL, data);
- if (ISSET(t, B_DB_LOCK))
+ if (F_ISSET(t, B_DB_LOCK))
mpool_put(t->bt_mp, e->page, 0);
else
t->bt_pinned = e->page;
@@ -133,32 +133,38 @@ __rec_fpipe(t, top)
recno_t nrec;
size_t len;
int ch;
- char *p;
+ u_char *p;
- if (t->bt_dbufsz < t->bt_reclen) {
- t->bt_dbuf = (char *)(t->bt_dbuf == NULL ?
- malloc(t->bt_reclen) : realloc(t->bt_dbuf, t->bt_reclen));
- if (t->bt_dbuf == NULL)
+ if (t->bt_rdata.size < t->bt_reclen) {
+ t->bt_rdata.data = t->bt_rdata.data == NULL ?
+ malloc(t->bt_reclen) :
+ realloc(t->bt_rdata.data, t->bt_reclen);
+ if (t->bt_rdata.data == NULL)
return (RET_ERROR);
- t->bt_dbufsz = t->bt_reclen;
+ t->bt_rdata.size = t->bt_reclen;
}
- data.data = t->bt_dbuf;
+ data.data = t->bt_rdata.data;
data.size = t->bt_reclen;
- for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
+ for (nrec = t->bt_nrecs; nrec < top;) {
len = t->bt_reclen;
- for (p = t->bt_dbuf;; *p++ = ch)
- if ((ch = getc(t->bt_rfp)) == EOF || !len--) {
- if (__rec_iput(t, nrec, &data, 0)
- != RET_SUCCESS)
+ for (p = t->bt_rdata.data;; *p++ = ch)
+ if ((ch = getc(t->bt_rfp)) == EOF || !--len) {
+ if (ch != EOF)
+ *p = ch;
+ if (len != 0)
+ memset(p, t->bt_bval, len);
+ if (__rec_iput(t,
+ nrec, &data, 0) != RET_SUCCESS)
return (RET_ERROR);
+ ++nrec;
break;
}
if (ch == EOF)
break;
}
if (nrec < top) {
- SET(t, R_EOF);
+ F_SET(t, R_EOF);
return (RET_SPECIAL);
}
return (RET_SUCCESS);
@@ -184,14 +190,15 @@ __rec_vpipe(t, top)
indx_t len;
size_t sz;
int bval, ch;
- char *p;
+ u_char *p;
bval = t->bt_bval;
for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
- for (p = t->bt_dbuf, sz = t->bt_dbufsz;; *p++ = ch, --sz) {
+ for (p = t->bt_rdata.data,
+ sz = t->bt_rdata.size;; *p++ = ch, --sz) {
if ((ch = getc(t->bt_rfp)) == EOF || ch == bval) {
- data.data = t->bt_dbuf;
- data.size = p - t->bt_dbuf;
+ data.data = t->bt_rdata.data;
+ data.size = p - (u_char *)t->bt_rdata.data;
if (ch == EOF && data.size == 0)
break;
if (__rec_iput(t, nrec, &data, 0)
@@ -200,21 +207,21 @@ __rec_vpipe(t, top)
break;
}
if (sz == 0) {
- len = p - t->bt_dbuf;
- t->bt_dbufsz += (sz = 256);
- t->bt_dbuf = (char *)(t->bt_dbuf == NULL ?
- malloc(t->bt_dbufsz) :
- realloc(t->bt_dbuf, t->bt_dbufsz));
- if (t->bt_dbuf == NULL)
+ len = p - (u_char *)t->bt_rdata.data;
+ t->bt_rdata.size += (sz = 256);
+ t->bt_rdata.data = t->bt_rdata.data == NULL ?
+ malloc(t->bt_rdata.size) :
+ realloc(t->bt_rdata.data, t->bt_rdata.size);
+ if (t->bt_rdata.data == NULL)
return (RET_ERROR);
- p = t->bt_dbuf + len;
+ p = (u_char *)t->bt_rdata.data + len;
}
}
if (ch == EOF)
break;
}
if (nrec < top) {
- SET(t, R_EOF);
+ F_SET(t, R_EOF);
return (RET_SPECIAL);
}
return (RET_SUCCESS);
@@ -237,34 +244,36 @@ __rec_fmap(t, top)
{
DBT data;
recno_t nrec;
- caddr_t sp, ep;
+ u_char *sp, *ep, *p;
size_t len;
- char *p;
- if (t->bt_dbufsz < t->bt_reclen) {
- t->bt_dbuf = (char *)(t->bt_dbuf == NULL ?
- malloc(t->bt_reclen) : realloc(t->bt_dbuf, t->bt_reclen));
- if (t->bt_dbuf == NULL)
+ if (t->bt_rdata.size < t->bt_reclen) {
+ t->bt_rdata.data = t->bt_rdata.data == NULL ?
+ malloc(t->bt_reclen) :
+ realloc(t->bt_rdata.data, t->bt_reclen);
+ if (t->bt_rdata.data == NULL)
return (RET_ERROR);
- t->bt_dbufsz = t->bt_reclen;
+ t->bt_rdata.size = t->bt_reclen;
}
- data.data = t->bt_dbuf;
+ data.data = t->bt_rdata.data;
data.size = t->bt_reclen;
- sp = t->bt_cmap;
- ep = t->bt_emap;
+ sp = (u_char *)t->bt_cmap;
+ ep = (u_char *)t->bt_emap;
for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
if (sp >= ep) {
- SET(t, R_EOF);
+ F_SET(t, R_EOF);
return (RET_SPECIAL);
}
len = t->bt_reclen;
- for (p = t->bt_dbuf; sp < ep && len--; *p++ = *sp++);
- memset(p, t->bt_bval, len);
+ for (p = t->bt_rdata.data;
+ sp < ep && len > 0; *p++ = *sp++, --len);
+ if (len != 0)
+ memset(p, t->bt_bval, len);
if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS)
return (RET_ERROR);
}
- t->bt_cmap = sp;
+ t->bt_cmap = (caddr_t)sp;
return (RET_SUCCESS);
}
@@ -284,25 +293,25 @@ __rec_vmap(t, top)
recno_t top;
{
DBT data;
- caddr_t sp, ep;
+ u_char *sp, *ep;
recno_t nrec;
int bval;
- sp = t->bt_cmap;
- ep = t->bt_emap;
+ sp = (u_char *)t->bt_cmap;
+ ep = (u_char *)t->bt_emap;
bval = t->bt_bval;
for (nrec = t->bt_nrecs; nrec < top; ++nrec) {
if (sp >= ep) {
- SET(t, R_EOF);
+ F_SET(t, R_EOF);
return (RET_SPECIAL);
}
for (data.data = sp; sp < ep && *sp != bval; ++sp);
- data.size = sp - (caddr_t)data.data;
+ data.size = sp - (u_char *)data.data;
if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS)
return (RET_ERROR);
++sp;
}
- t->bt_cmap = sp;
+ t->bt_cmap = (caddr_t)sp;
return (RET_SUCCESS);
}