2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1996-2002
5
* Sleepycat Software. All rights reserved.
11
static const char revid[] = "$Id$";
14
#ifndef NO_SYSTEM_INCLUDES
15
#include <sys/types.h>
21
#include "dbinc/db_page.h"
22
#include "dbinc/db_am.h"
28
* PUBLIC: int __db_ret __P((DB *,
29
* PUBLIC: PAGE *, u_int32_t, DBT *, void **, u_int32_t *));
32
__db_ret(dbp, h, indx, dbt, memp, memsize)
49
hk = P_ENTRY(dbp, h, indx);
50
if (HPAGE_PTYPE(hk) == H_OFFPAGE) {
51
memcpy(&ho, hk, sizeof(HOFFPAGE));
52
return (__db_goff(dbp, dbt,
53
ho.tlen, ho.pgno, memp, memsize));
55
len = LEN_HKEYDATA(dbp, h, dbp->pgsize, indx);
56
data = HKEYDATA_DATA(hk);
61
bk = GET_BKEYDATA(dbp, h, indx);
62
if (B_TYPE(bk->type) == B_OVERFLOW) {
64
return (__db_goff(dbp, dbt,
65
bo->tlen, bo->pgno, memp, memsize));
71
return (__db_pgfmt(dbp->dbenv, h->pgno));
74
return (__db_retcopy(dbp->dbenv, dbt, data, len, memp, memsize));
79
* Copy the returned data into the user's DBT, handling special flags.
81
* PUBLIC: int __db_retcopy __P((DB_ENV *, DBT *,
82
* PUBLIC: void *, u_int32_t, void **, u_int32_t *));
85
__db_retcopy(dbenv, dbt, data, len, memp, memsize)
95
/* If returning a partial record, reset the length. */
96
if (F_ISSET(dbt, DB_DBT_PARTIAL)) {
97
data = (u_int8_t *)data + dbt->doff;
98
if (len > dbt->doff) {
107
* Return the length of the returned record in the DBT size field.
108
* This satisfies the requirement that if we're using user memory
109
* and insufficient memory was provided, return the amount necessary
115
* Allocate memory to be owned by the application: DB_DBT_MALLOC,
119
* We always allocate memory, even if we're copying out 0 bytes. This
120
* guarantees consistency, i.e., the application can always free memory
121
* without concern as to how many bytes of the record were requested.
123
* Use the memory specified by the application: DB_DBT_USERMEM.
126
* If the length we're going to copy is 0, the application-supplied
127
* memory pointer is allowed to be NULL.
129
if (F_ISSET(dbt, DB_DBT_MALLOC)) {
130
if ((ret = __os_umalloc(dbenv, len, &dbt->data)) != 0)
132
} else if (F_ISSET(dbt, DB_DBT_REALLOC)) {
133
if ((ret = __os_urealloc(dbenv, len, &dbt->data)) != 0)
135
} else if (F_ISSET(dbt, DB_DBT_USERMEM)) {
136
if (len != 0 && (dbt->data == NULL || dbt->ulen < len))
138
} else if (memp == NULL || memsize == NULL) {
141
if (len != 0 && (*memsize == 0 || *memsize < len)) {
142
if ((ret = __os_realloc(dbenv, len, memp)) != 0) {
152
memcpy(dbt->data, data, len);