150995Sbostic /*- 250995Sbostic * Copyright (c) 1990 The Regents of the University of California. 350995Sbostic * All rights reserved. 450995Sbostic * 550995Sbostic * %sccs.include.redist.c% 650995Sbostic */ 750995Sbostic 850995Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*56761Sbostic static char sccsid[] = "@(#)rec_utils.c 5.4 (Berkeley) 11/13/92"; 1050995Sbostic #endif /* LIBC_SCCS and not lint */ 1150995Sbostic 1250995Sbostic #include <sys/param.h> 13*56761Sbostic 1450995Sbostic #include <db.h> 1550995Sbostic #include <stdio.h> 1650995Sbostic #include <stdlib.h> 1750995Sbostic #include <string.h> 18*56761Sbostic 1951093Sbostic #include "recno.h" 2050995Sbostic 2150995Sbostic /* 2250995Sbostic * __REC_RET -- Build return data as a result of search or scan. 2350995Sbostic * 2450995Sbostic * Parameters: 2550995Sbostic * t: tree 2650995Sbostic * d: LEAF to be returned to the user. 2750995Sbostic * data: user's data structure 2850995Sbostic * 2950995Sbostic * Returns: 3050995Sbostic * RET_SUCCESS, RET_ERROR. 3150995Sbostic */ 3250995Sbostic int 33*56761Sbostic __rec_ret(t, e, nrec, key, data) 3450995Sbostic BTREE *t; 3550995Sbostic EPG *e; 36*56761Sbostic recno_t nrec; 37*56761Sbostic DBT *key, *data; 3850995Sbostic { 3950995Sbostic register RLEAF *rl; 40*56761Sbostic register void *p; 4150995Sbostic 42*56761Sbostic if (data == NULL) 43*56761Sbostic goto retkey; 44*56761Sbostic 4550995Sbostic rl = GETRLEAF(e->page, e->index); 46*56761Sbostic 4750995Sbostic if (rl->flags & P_BIGDATA) { 4850995Sbostic if (__ovfl_get(t, rl->bytes, 4950995Sbostic &data->size, &t->bt_dbuf, &t->bt_dbufsz)) 5050995Sbostic return (RET_ERROR); 5150995Sbostic } else { 5254285Sbostic /* Use +1 in case the first record retrieved is 0 length. */ 5354285Sbostic if (rl->dsize + 1 > t->bt_dbufsz) { 5454285Sbostic if ((p = realloc(t->bt_dbuf, rl->dsize + 1)) == NULL) 5550995Sbostic return (RET_ERROR); 5651093Sbostic t->bt_dbuf = p; 5754285Sbostic t->bt_dbufsz = rl->dsize + 1; 5850995Sbostic } 5950995Sbostic bcopy(rl->bytes, t->bt_dbuf, t->bt_dbufsz); 6050995Sbostic data->size = rl->dsize; 6150995Sbostic } 6250995Sbostic data->data = t->bt_dbuf; 6350995Sbostic 64*56761Sbostic retkey: if (key == NULL) 65*56761Sbostic return (RET_SUCCESS); 66*56761Sbostic 67*56761Sbostic if (sizeof(recno_t) > t->bt_kbufsz) { 68*56761Sbostic if ((p = realloc(t->bt_kbuf, sizeof(recno_t))) == NULL) 69*56761Sbostic return (RET_ERROR); 70*56761Sbostic t->bt_kbuf = p; 71*56761Sbostic t->bt_kbufsz = sizeof(recno_t); 72*56761Sbostic } 73*56761Sbostic bcopy(&nrec, t->bt_kbuf, sizeof(recno_t)); 74*56761Sbostic key->size = sizeof(recno_t); 75*56761Sbostic key->data = t->bt_kbuf; 7650995Sbostic return (RET_SUCCESS); 7750995Sbostic } 78