From 69d67122b2935ce4e7691a9480444edecac1ab8c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 9 Mar 2008 11:15:10 +0100 Subject: add dbwrap_change_int32_atomic (This used to be commit 4ee21a98bc3d1c41a6d8868e98118c58372b2d1a) --- source3/lib/dbwrap_util.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c index 002d572019..ba1f6ae96e 100644 --- a/source3/lib/dbwrap_util.c +++ b/source3/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; +} -- cgit