diff options
author | Gregor Beck <gbeck@sernet.de> | 2011-08-17 11:44:12 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-10-11 14:17:56 +0200 |
commit | 7b9bf285140d937de41945170108d9f193baeefd (patch) | |
tree | eb5de0a7468aeae4926e130d81b0a4e06968e4e5 /source3 | |
parent | ebcb92118241a5bd4be92374b1c257236ba3b1db (diff) | |
download | samba-7b9bf285140d937de41945170108d9f193baeefd.tar.gz samba-7b9bf285140d937de41945170108d9f193baeefd.tar.bz2 samba-7b9bf285140d937de41945170108d9f193baeefd.zip |
s3:dbwrap: fix db_rbt_traverse() to return the record count on success
this makes it consistent with documented behaviour of tdb_traverse()
Signed-off-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/dbwrap/dbwrap_rbt.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/source3/lib/dbwrap/dbwrap_rbt.c b/source3/lib/dbwrap/dbwrap_rbt.c index 450e4588b9..cc4e0dd129 100644 --- a/source3/lib/dbwrap/dbwrap_rbt.c +++ b/source3/lib/dbwrap/dbwrap_rbt.c @@ -320,7 +320,7 @@ static int db_rbt_wipe(struct db_context *db) { struct db_rbt_ctx *old_ctx = talloc_get_type_abort( db->private_data, struct db_rbt_ctx); - struct db_rbt_ctx *new_ctx = TALLOC_ZERO_P(db, struct db_rbt_ctx); + struct db_rbt_ctx *new_ctx = talloc_zero(db, struct db_rbt_ctx); if (new_ctx == NULL) { return -1; } @@ -369,7 +369,7 @@ static int db_rbt_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, static int db_rbt_traverse_internal(struct rb_node *n, int (*f)(struct db_record *db, void *private_data), - void *private_data) + void *private_data, uint32_t* count) { struct db_rbt_node *r; struct db_record rec; @@ -379,7 +379,7 @@ static int db_rbt_traverse_internal(struct rb_node *n, return 0; } - ret = db_rbt_traverse_internal(n->rb_left, f, private_data); + ret = db_rbt_traverse_internal(n->rb_left, f, private_data, count); if (ret != 0) { return ret; } @@ -389,11 +389,12 @@ static int db_rbt_traverse_internal(struct rb_node *n, db_rbt_parse_node(r, &rec.key, &rec.value); ret = f(&rec, private_data); + (*count) ++; if (ret != 0) { return ret; } - return db_rbt_traverse_internal(n->rb_right, f, private_data); + return db_rbt_traverse_internal(n->rb_right, f, private_data, count); } static int db_rbt_traverse(struct db_context *db, @@ -403,8 +404,16 @@ static int db_rbt_traverse(struct db_context *db, { struct db_rbt_ctx *ctx = talloc_get_type_abort( db->private_data, struct db_rbt_ctx); + uint32_t count = 0; - return db_rbt_traverse_internal(ctx->tree.rb_node, f, private_data); + int ret = db_rbt_traverse_internal(ctx->tree.rb_node, f, private_data, &count); + if (ret != 0) { + return -1; + } + if (count > INT_MAX) { + return -1; + } + return count; } static int db_rbt_get_seqnum(struct db_context *db) |