~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/db/db_ret.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1996-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 */
7
 
 
8
 
#include "db_config.h"
9
 
 
10
 
#ifndef lint
11
 
static const char revid[] = "$Id$";
12
 
#endif /* not lint */
13
 
 
14
 
#ifndef NO_SYSTEM_INCLUDES
15
 
#include <sys/types.h>
16
 
 
17
 
#include <string.h>
18
 
#endif
19
 
 
20
 
#include "db_int.h"
21
 
#include "dbinc/db_page.h"
22
 
#include "dbinc/db_am.h"
23
 
 
24
 
/*
25
 
 * __db_ret --
26
 
 *      Build return DBT.
27
 
 *
28
 
 * PUBLIC: int __db_ret __P((DB *,
29
 
 * PUBLIC:    PAGE *, u_int32_t, DBT *, void **, u_int32_t *));
30
 
 */
31
 
int
32
 
__db_ret(dbp, h, indx, dbt, memp, memsize)
33
 
        DB *dbp;
34
 
        PAGE *h;
35
 
        u_int32_t indx;
36
 
        DBT *dbt;
37
 
        void **memp;
38
 
        u_int32_t *memsize;
39
 
{
40
 
        BKEYDATA *bk;
41
 
        HOFFPAGE ho;
42
 
        BOVERFLOW *bo;
43
 
        u_int32_t len;
44
 
        u_int8_t *hk;
45
 
        void *data;
46
 
 
47
 
        switch (TYPE(h)) {
48
 
        case P_HASH:
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));
54
 
                }
55
 
                len = LEN_HKEYDATA(dbp, h, dbp->pgsize, indx);
56
 
                data = HKEYDATA_DATA(hk);
57
 
                break;
58
 
        case P_LBTREE:
59
 
        case P_LDUP:
60
 
        case P_LRECNO:
61
 
                bk = GET_BKEYDATA(dbp, h, indx);
62
 
                if (B_TYPE(bk->type) == B_OVERFLOW) {
63
 
                        bo = (BOVERFLOW *)bk;
64
 
                        return (__db_goff(dbp, dbt,
65
 
                            bo->tlen, bo->pgno, memp, memsize));
66
 
                }
67
 
                len = bk->len;
68
 
                data = bk->data;
69
 
                break;
70
 
        default:
71
 
                return (__db_pgfmt(dbp->dbenv, h->pgno));
72
 
        }
73
 
 
74
 
        return (__db_retcopy(dbp->dbenv, dbt, data, len, memp, memsize));
75
 
}
76
 
 
77
 
/*
78
 
 * __db_retcopy --
79
 
 *      Copy the returned data into the user's DBT, handling special flags.
80
 
 *
81
 
 * PUBLIC: int __db_retcopy __P((DB_ENV *, DBT *,
82
 
 * PUBLIC:    void *, u_int32_t, void **, u_int32_t *));
83
 
 */
84
 
int
85
 
__db_retcopy(dbenv, dbt, data, len, memp, memsize)
86
 
        DB_ENV *dbenv;
87
 
        DBT *dbt;
88
 
        void *data;
89
 
        u_int32_t len;
90
 
        void **memp;
91
 
        u_int32_t *memsize;
92
 
{
93
 
        int ret;
94
 
 
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) {
99
 
                        len -= dbt->doff;
100
 
                        if (len > dbt->dlen)
101
 
                                len = dbt->dlen;
102
 
                } else
103
 
                        len = 0;
104
 
        }
105
 
 
106
 
        /*
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
110
 
         * in the size field.
111
 
         */
112
 
        dbt->size = len;
113
 
 
114
 
        /*
115
 
         * Allocate memory to be owned by the application: DB_DBT_MALLOC,
116
 
         * DB_DBT_REALLOC.
117
 
         *
118
 
         * !!!
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.
122
 
         *
123
 
         * Use the memory specified by the application: DB_DBT_USERMEM.
124
 
         *
125
 
         * !!!
126
 
         * If the length we're going to copy is 0, the application-supplied
127
 
         * memory pointer is allowed to be NULL.
128
 
         */
129
 
        if (F_ISSET(dbt, DB_DBT_MALLOC)) {
130
 
                if ((ret = __os_umalloc(dbenv, len, &dbt->data)) != 0)
131
 
                        return (ret);
132
 
        } else if (F_ISSET(dbt, DB_DBT_REALLOC)) {
133
 
                if ((ret = __os_urealloc(dbenv, len, &dbt->data)) != 0)
134
 
                        return (ret);
135
 
        } else if (F_ISSET(dbt, DB_DBT_USERMEM)) {
136
 
                if (len != 0 && (dbt->data == NULL || dbt->ulen < len))
137
 
                        return (ENOMEM);
138
 
        } else if (memp == NULL || memsize == NULL) {
139
 
                return (EINVAL);
140
 
        } else {
141
 
                if (len != 0 && (*memsize == 0 || *memsize < len)) {
142
 
                        if ((ret = __os_realloc(dbenv, len, memp)) != 0) {
143
 
                                *memsize = 0;
144
 
                                return (ret);
145
 
                        }
146
 
                        *memsize = len;
147
 
                }
148
 
                dbt->data = *memp;
149
 
        }
150
 
 
151
 
        if (len != 0)
152
 
                memcpy(dbt->data, data, len);
153
 
        return (0);
154
 
}