1 /* dbt.c --- DBT-frobbing functions
3 * ====================================================================
4 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
20 #include <apr_pools.h>
30 svn_fs_base__clear_dbt(DBT
*dbt
)
32 memset(dbt
, 0, sizeof(*dbt
));
38 DBT
*svn_fs_base__nodata_dbt(DBT
*dbt
)
40 svn_fs_base__clear_dbt(dbt
);
42 /* A `nodata' dbt is one which retrieves zero bytes from offset zero,
43 and stores them in a zero-byte buffer in user-allocated memory. */
44 dbt
->flags
|= (DB_DBT_USERMEM
| DB_DBT_PARTIAL
);
45 dbt
->doff
= dbt
->dlen
= 0;
52 svn_fs_base__set_dbt(DBT
*dbt
, const void *data
, u_int32_t size
)
54 svn_fs_base__clear_dbt(dbt
);
56 dbt
->data
= (void *) data
;
64 svn_fs_base__result_dbt(DBT
*dbt
)
66 svn_fs_base__clear_dbt(dbt
);
67 dbt
->flags
|= DB_DBT_MALLOC
;
73 /* An APR pool cleanup function that simply applies `free' to its
76 apr_free_cleanup(void *arg
)
85 svn_fs_base__track_dbt(DBT
*dbt
, apr_pool_t
*pool
)
88 apr_pool_cleanup_register(pool
, dbt
->data
, apr_free_cleanup
,
89 apr_pool_cleanup_null
);
96 svn_fs_base__recno_dbt(DBT
*dbt
, db_recno_t
*recno
)
98 svn_fs_base__set_dbt(dbt
, recno
, sizeof(*recno
));
99 dbt
->ulen
= dbt
->size
;
100 dbt
->flags
|= DB_DBT_USERMEM
;
107 svn_fs_base__compare_dbt(const DBT
*a
, const DBT
*b
)
109 int common_size
= a
->size
> b
->size
? b
->size
: a
->size
;
110 int cmp
= memcmp(a
->data
, b
->data
, common_size
);
115 return a
->size
- b
->size
;
120 /* Building DBT's from interesting things. */
123 /* Set DBT to the unparsed form of ID; allocate memory from POOL.
126 svn_fs_base__id_to_dbt(DBT
*dbt
,
127 const svn_fs_id_t
*id
,
130 svn_string_t
*unparsed_id
= svn_fs_base__id_unparse(id
, pool
);
131 svn_fs_base__set_dbt(dbt
, unparsed_id
->data
, unparsed_id
->len
);
136 /* Set DBT to the unparsed form of SKEL; allocate memory from POOL. */
138 svn_fs_base__skel_to_dbt(DBT
*dbt
,
142 svn_stringbuf_t
*unparsed_skel
= svn_fs_base__unparse_skel(skel
, pool
);
143 svn_fs_base__set_dbt(dbt
, unparsed_skel
->data
, unparsed_skel
->len
);
148 /* Set DBT to the text of the null-terminated string STR. DBT will
149 refer to STR's storage. Return DBT. */
151 svn_fs_base__str_to_dbt(DBT
*dbt
, const char *str
)
153 svn_fs_base__set_dbt(dbt
, str
, strlen(str
));