summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorGregor Beck <gbeck@sernet.de>2013-03-20 09:56:54 +0100
committerMichael Adam <obnox@samba.org>2013-04-18 13:15:11 +0200
commit037f57e12fb7b87e0c5c035ae85cb698bca64f4d (patch)
treea07e5a11db3116f674e8fcdb1e1b294996a713c3 /source3/lib
parent450ebe97d1c36a8041e3567c0b1fe94822909ea2 (diff)
downloadsamba-037f57e12fb7b87e0c5c035ae85cb698bca64f4d.tar.gz
samba-037f57e12fb7b87e0c5c035ae85cb698bca64f4d.tar.bz2
samba-037f57e12fb7b87e0c5c035ae85cb698bca64f4d.zip
util_tdb: add function tdb_data_string()
Signed-off-by: Gregor Beck <gbeck@sernet.de> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util_tdb.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c
index 8bfc75f18b..440c28b98d 100644
--- a/source3/lib/util_tdb.c
+++ b/source3/lib/util_tdb.c
@@ -22,6 +22,7 @@
#include "includes.h"
#include "system/filesys.h"
#include "util_tdb.h"
+#include "cbuf.h"
#undef malloc
#undef realloc
@@ -418,3 +419,35 @@ int tdb_data_cmp(TDB_DATA t1, TDB_DATA t2)
}
return ret;
}
+
+char *tdb_data_string(TALLOC_CTX *mem_ctx, TDB_DATA d)
+{
+ int len;
+ char *ret = NULL;
+ cbuf *ost = cbuf_new(mem_ctx);
+
+ if (ost == NULL) {
+ return NULL;
+ }
+
+ len = cbuf_printf(ost, "%d:");
+ if (len == -1) {
+ goto done;
+ }
+
+ if (d.dptr == NULL) {
+ len = cbuf_puts(ost, "<NULL>", -1);
+ } else {
+ len = cbuf_print_quoted(ost, (const char*)d.dptr, d.dsize);
+ }
+ if (len == -1) {
+ goto done;
+ }
+
+ cbuf_swapptr(ost, &ret, 0);
+ talloc_steal(mem_ctx, ret);
+
+done:
+ talloc_free(ost);
+ return ret;
+}