From f24d88cf9da46680d52b42b92bd484e7b09ce99b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 31 May 2005 13:46:45 +0000 Subject: r7139: trying to reduce the number of diffs between trunk and 3.0; changing version to 3.0.20pre1 (This used to be commit 9727d05241574042dd3aa8844ae5c701d22e2da1) --- source3/tdb/tdb.c | 2 +- source3/tdb/tdbutil.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 8 deletions(-) (limited to 'source3/tdb') diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c index e03e571ca1..d91e6e4efc 100644 --- a/source3/tdb/tdb.c +++ b/source3/tdb/tdb.c @@ -128,7 +128,7 @@ /* free memory if the pointer is valid and zero the pointer */ #ifndef SAFE_FREE -#define SAFE_FREE(x) do { if ((x) != NULL) {free(CONST_DISCARD(void *, (x))); (x)=NULL;} } while(0) +#define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0) #endif #define BUCKET(hash) ((hash) % tdb->header.hash_size) diff --git a/source3/tdb/tdbutil.c b/source3/tdb/tdbutil.c index 4fcfb6185a..47f1bb2dc2 100644 --- a/source3/tdb/tdbutil.c +++ b/source3/tdb/tdbutil.c @@ -390,9 +390,8 @@ BOOL tdb_change_uint32_atomic(TDB_CONTEXT *tdb, const char *keystr, uint32 *oldv integers and strings. ****************************************************************************/ -size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...) +size_t tdb_pack_va(char *buf, int bufsize, const char *fmt, va_list ap) { - va_list ap; uint8 bt; uint16 w; uint32 d; @@ -405,8 +404,6 @@ size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...) const char *fmt0 = fmt; int bufsize0 = bufsize; - va_start(ap, fmt); - while (*fmt) { switch ((c = *fmt++)) { case 'b': /* unsigned 8-bit integer */ @@ -471,14 +468,54 @@ size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...) bufsize = 0; } - va_end(ap); - - DEBUG(18,("tdb_pack(%s, %d) -> %d\n", + DEBUG(18,("tdb_pack_va(%s, %d) -> %d\n", fmt0, bufsize0, (int)PTR_DIFF(buf, buf0))); return PTR_DIFF(buf, buf0); } +size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...) +{ + va_list ap; + size_t result; + + va_start(ap, fmt); + result = tdb_pack_va(buf, bufsize, fmt, ap); + va_end(ap); + return result; +} + +BOOL tdb_pack_append(TALLOC_CTX *mem_ctx, uint8_t **buf, size_t *len, + const char *fmt, ...) +{ + va_list ap; + size_t len1, len2; + + va_start(ap, fmt); + len1 = tdb_pack_va(NULL, 0, fmt, ap); + va_end(ap); + + if (mem_ctx != NULL) + *buf = TALLOC_REALLOC_ARRAY(mem_ctx, *buf, uint8_t, + (*len) + len1); + else + *buf = SMB_REALLOC_ARRAY(*buf, uint8_t, (*len) + len1); + + if (*buf == NULL) + return False; + + va_start(ap, fmt); + len2 = tdb_pack_va((*buf)+(*len), len1, fmt, ap); + va_end(ap); + + if (len1 != len2) + return False; + + *len += len2; + + return True; +} + /**************************************************************************** Useful pair of routines for packing/unpacking data consisting of integers and strings. -- cgit