diff options
author | Volker Lendecke <vlendec@samba.org> | 2007-02-19 11:19:53 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:18:04 -0500 |
commit | 39c1ebff22aaacbe2745e7b6ad832e9ed302fe81 (patch) | |
tree | 010f391cb7fd5deb6d981d7bff9fb6e9028c4197 /source3/tdb/common/io.c | |
parent | c909c6722b065e898da43b0e1448fc4314649553 (diff) | |
download | samba-39c1ebff22aaacbe2745e7b6ad832e9ed302fe81.tar.gz samba-39c1ebff22aaacbe2745e7b6ad832e9ed302fe81.tar.bz2 samba-39c1ebff22aaacbe2745e7b6ad832e9ed302fe81.zip |
r21444: Check in tdb_parse_record. Not merging to the other branches yet, we need to
agree on the behaviour of non-existing records.
Tridge, can you comment? Should we change tdb_fetch, or should we have
different concepts in tdb_fetch() and tdb_parse_record() ?
Volker
(This used to be commit fba79e75c0138c3ae4e73014a1d1a2c2045c35bb)
Diffstat (limited to 'source3/tdb/common/io.c')
-rw-r--r-- | source3/tdb/common/io.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source3/tdb/common/io.c b/source3/tdb/common/io.c index 988ce1d911..9a8e270dcc 100644 --- a/source3/tdb/common/io.c +++ b/source3/tdb/common/io.c @@ -355,6 +355,40 @@ char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t 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 + (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) { |