From a7cda1a164bd83c6b8180758fe73dd5ac76918e4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 9 Mar 2008 11:15:10 +0100 Subject: [PATCH] add dbwrap_change_int32_atomic (cherry picked from commit 4ee21a98bc3d1c41a6d8868e98118c58372b2d1a) --- source/lib/dbwrap_util.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/lib/dbwrap_util.c b/source/lib/dbwrap_util.c index 002d5720193..ba1f6ae96e0 100644 --- a/source/lib/dbwrap_util.c +++ b/source/lib/dbwrap_util.c @@ -88,3 +88,31 @@ uint32_t dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr, return 0; } +int32 dbwrap_change_int32_atomic(struct db_context *db, const char *keystr, + int32 *oldval, int32 change_val) +{ + struct db_record *rec; + int32 val = -1; + TDB_DATA data; + + if (!(rec = db->fetch_locked(db, NULL, + string_term_tdb_data(keystr)))) { + return -1; + } + + if ((rec->value.dptr != NULL) + && (rec->value.dsize == sizeof(val))) { + val = IVAL(rec->value.dptr, 0); + } + + val += change_val; + + data.dsize = sizeof(val); + data.dptr = (uint8 *)&val; + + rec->store(rec, data, TDB_REPLACE); + + TALLOC_FREE(rec); + + return 0; +} -- 2.11.4.GIT