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*54285Sbostic static char sccsid[] = "@(#)rec_utils.c 5.3 (Berkeley) 06/23/92"; 1050995Sbostic #endif /* LIBC_SCCS and not lint */ 1150995Sbostic 1250995Sbostic #include <sys/param.h> 1350995Sbostic #include <db.h> 1450995Sbostic #include <stdio.h> 1550995Sbostic #include <stdlib.h> 1650995Sbostic #include <string.h> 1751093Sbostic #include "recno.h" 1850995Sbostic 1950995Sbostic /* 2050995Sbostic * __REC_RET -- Build return data as a result of search or scan. 2150995Sbostic * 2250995Sbostic * Parameters: 2350995Sbostic * t: tree 2450995Sbostic * d: LEAF to be returned to the user. 2550995Sbostic * data: user's data structure 2650995Sbostic * 2750995Sbostic * Returns: 2850995Sbostic * RET_SUCCESS, RET_ERROR. 2950995Sbostic */ 3050995Sbostic int 3150995Sbostic __rec_ret(t, e, data) 3250995Sbostic BTREE *t; 3350995Sbostic EPG *e; 3450995Sbostic DBT *data; 3550995Sbostic { 3650995Sbostic register RLEAF *rl; 3751093Sbostic register char *p; 3850995Sbostic 3950995Sbostic rl = GETRLEAF(e->page, e->index); 4050995Sbostic if (rl->flags & P_BIGDATA) { 4150995Sbostic if (__ovfl_get(t, rl->bytes, 4250995Sbostic &data->size, &t->bt_dbuf, &t->bt_dbufsz)) 4350995Sbostic return (RET_ERROR); 4450995Sbostic } else { 45*54285Sbostic /* Use +1 in case the first record retrieved is 0 length. */ 46*54285Sbostic if (rl->dsize + 1 > t->bt_dbufsz) { 47*54285Sbostic if ((p = realloc(t->bt_dbuf, rl->dsize + 1)) == NULL) 4850995Sbostic return (RET_ERROR); 4951093Sbostic t->bt_dbuf = p; 50*54285Sbostic t->bt_dbufsz = rl->dsize + 1; 5150995Sbostic } 5250995Sbostic bcopy(rl->bytes, t->bt_dbuf, t->bt_dbufsz); 5350995Sbostic data->size = rl->dsize; 5450995Sbostic } 5550995Sbostic data->data = t->bt_dbuf; 5650995Sbostic 5750995Sbostic return (RET_SUCCESS); 5850995Sbostic } 59