xref: /csrg-svn/lib/libc/db/recno/rec_utils.c (revision 50995)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)rec_utils.c	5.1 (Berkeley) 09/04/91";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/param.h>
13 #include <db.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include "../btree/btree.h"
18 
19 /*
20  * __REC_RET -- Build return data as a result of search or scan.
21  *
22  * Parameters:
23  *	t:	tree
24  *	d:	LEAF to be returned to the user.
25  *	data:	user's data structure
26  *
27  * Returns:
28  *	RET_SUCCESS, RET_ERROR.
29  */
30 int
31 __rec_ret(t, e, data)
32 	BTREE *t;
33 	EPG *e;
34 	DBT *data;
35 {
36 	register RLEAF *rl;
37 
38 	rl = GETRLEAF(e->page, e->index);
39 	if (rl->flags & P_BIGDATA) {
40 		if (__ovfl_get(t, rl->bytes,
41 		    &data->size, &t->bt_dbuf, &t->bt_dbufsz))
42 			return (RET_ERROR);
43 	} else {
44 		if (rl->dsize > t->bt_dbufsz) {
45 			if ((t->bt_dbuf =
46 			    realloc(t->bt_dbuf, rl->dsize)) == NULL)
47 				return (RET_ERROR);
48 			t->bt_dbufsz = rl->dsize;
49 		}
50 		bcopy(rl->bytes, t->bt_dbuf, t->bt_dbufsz);
51 		data->size = rl->dsize;
52 	}
53 	data->data = t->bt_dbuf;
54 
55 	return (RET_SUCCESS);
56 }
57