1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1997-2009 Oracle. All rights reserved.
*
* $Id$
*/
#include "db_config.h"
#include "db_int.h"
/*
* __dbt_usercopy --
* Take a copy of the user's data, if a callback is supplied.
*
* PUBLIC: int __dbt_usercopy __P((ENV *, DBT *));
*/
int
__dbt_usercopy(env, dbt)
ENV *env;
DBT *dbt;
{
void *buf;
int ret;
if (dbt == NULL || !F_ISSET(dbt, DB_DBT_USERCOPY) || dbt->size == 0 ||
dbt->data != NULL)
return (0);
buf = NULL;
if ((ret = __os_umalloc(env, dbt->size, &buf)) != 0 ||
(ret = env->dbt_usercopy(dbt, 0, buf, dbt->size,
DB_USERCOPY_GETDATA)) != 0)
goto err;
dbt->data = buf;
return (0);
err: if (buf != NULL) {
__os_ufree(env, buf);
dbt->data = NULL;
}
return (ret);
}
/*
* __dbt_userfree --
* Free a copy of the user's data, if necessary.
*
* PUBLIC: void __dbt_userfree __P((ENV *, DBT *, DBT *, DBT *));
*/
void
__dbt_userfree(env, key, pkey, data)
ENV *env;
DBT *key, *pkey, *data;
{
if (key != NULL &&
F_ISSET(key, DB_DBT_USERCOPY) && key->data != NULL) {
__os_ufree(env, key->data);
key->data = NULL;
}
if (pkey != NULL &&
F_ISSET(pkey, DB_DBT_USERCOPY) && pkey->data != NULL) {
__os_ufree(env, pkey->data);
pkey->data = NULL;
}
if (data != NULL &&
F_ISSET(data, DB_DBT_USERCOPY) && data->data != NULL) {
__os_ufree(env, data->data);
data->data = NULL;
}
}
|