Fix compiler warning due to missing function prototype.
[svn.git] / subversion / libsvn_fs_base / bdb / dbt.c
blob98a29a78fa46550fad3f15d669f53752b678eabb
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 * ====================================================================
18 #include <stdlib.h>
19 #include <string.h>
20 #include <apr_pools.h>
22 #define APU_WANT_DB
23 #include <apu_want.h>
25 #include "../id.h"
26 #include "dbt.h"
29 DBT *
30 svn_fs_base__clear_dbt(DBT *dbt)
32 memset(dbt, 0, sizeof(*dbt));
34 return 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;
47 return dbt;
51 DBT *
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;
57 dbt->size = size;
59 return dbt;
63 DBT *
64 svn_fs_base__result_dbt(DBT *dbt)
66 svn_fs_base__clear_dbt(dbt);
67 dbt->flags |= DB_DBT_MALLOC;
69 return dbt;
73 /* An APR pool cleanup function that simply applies `free' to its
74 argument. */
75 static apr_status_t
76 apr_free_cleanup(void *arg)
78 free(arg);
80 return 0;
84 DBT *
85 svn_fs_base__track_dbt(DBT *dbt, apr_pool_t *pool)
87 if (dbt->data)
88 apr_pool_cleanup_register(pool, dbt->data, apr_free_cleanup,
89 apr_pool_cleanup_null);
91 return dbt;
95 DBT *
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;
102 return dbt;
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);
112 if (cmp)
113 return cmp;
114 else
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.
124 Return DBT. */
125 DBT *
126 svn_fs_base__id_to_dbt(DBT *dbt,
127 const svn_fs_id_t *id,
128 apr_pool_t *pool)
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);
132 return dbt;
136 /* Set DBT to the unparsed form of SKEL; allocate memory from POOL. */
137 DBT *
138 svn_fs_base__skel_to_dbt(DBT *dbt,
139 skel_t *skel,
140 apr_pool_t *pool)
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);
144 return dbt;
148 /* Set DBT to the text of the null-terminated string STR. DBT will
149 refer to STR's storage. Return DBT. */
150 DBT *
151 svn_fs_base__str_to_dbt(DBT *dbt, const char *str)
153 svn_fs_base__set_dbt(dbt, str, strlen(str));
154 return dbt;