summaryrefslogtreecommitdiff
path: root/source4/lib/tdb/common/io.c
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-02-19 11:45:33 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:48:36 -0500
commiteaaf246d4fa42df5e590ee5bfe54e672abd26b02 (patch)
tree04e79b6edf7c136816546ab1d1466763afaebbfb /source4/lib/tdb/common/io.c
parent32afb0d15fa2d941ec1c01fd9cf23200481652c9 (diff)
downloadsamba-eaaf246d4fa42df5e590ee5bfe54e672abd26b02.tar.gz
samba-eaaf246d4fa42df5e590ee5bfe54e672abd26b02.tar.bz2
samba-eaaf246d4fa42df5e590ee5bfe54e672abd26b02.zip
r21445: Apply tdb_parse_record Tridges error return, merge to 3_0_25 and 4_0
(This used to be commit afe7d7855841066b88859976ac748cbf438a9a9f)
Diffstat (limited to 'source4/lib/tdb/common/io.c')
-rw-r--r--source4/lib/tdb/common/io.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source4/lib/tdb/common/io.c b/source4/lib/tdb/common/io.c
index 5d2c5c8e2e..b3d1c56dc4 100644
--- a/source4/lib/tdb/common/io.c
+++ b/source4/lib/tdb/common/io.c
@@ -353,6 +353,40 @@ unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len
return buf;
}
+/* Give a piece of tdb data to a parser */
+
+int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key,
+ tdb_off_t offset, tdb_len_t len,
+ int (*parser)(TDB_DATA key, TDB_DATA data,
+ void *private_data),
+ void *private_data)
+{
+ TDB_DATA data;
+ int result;
+
+ data.dsize = len;
+
+ if ((tdb->transaction == NULL) && (tdb->map_ptr != NULL)) {
+ /*
+ * Optimize by avoiding the malloc/memcpy/free, point the
+ * parser directly at the mmap area.
+ */
+ if (tdb->methods->tdb_oob(tdb, offset+len, 0) != 0) {
+ return -1;
+ }
+ data.dptr = offset + (unsigned char *)tdb->map_ptr;
+ return parser(key, data, private_data);
+ }
+
+ if (!(data.dptr = tdb_alloc_read(tdb, offset, len))) {
+ return -1;
+ }
+
+ result = parser(key, data, private_data);
+ free(data.dptr);
+ return result;
+}
+
/* read/write a record */
int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec)
{