summaryrefslogtreecommitdiff
path: root/source3/lib/talloc.c
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2006-08-10 11:33:42 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:38:37 -0500
commit7b453b655562cbf2eb6743c2d0fd85cca68700d3 (patch)
treea5daaf335108d18dd9f7e8c53fd606fc31a3d3e0 /source3/lib/talloc.c
parent108009f2681726691da4dfbad1e1a628f6a53f44 (diff)
downloadsamba-7b453b655562cbf2eb6743c2d0fd85cca68700d3.tar.gz
samba-7b453b655562cbf2eb6743c2d0fd85cca68700d3.tar.bz2
samba-7b453b655562cbf2eb6743c2d0fd85cca68700d3.zip
r17477: Add talloc_asprintf_len and make use of it.
Volker (This used to be commit c0ff2afe0683095401fa7b7654aa3b2fe950f7b3)
Diffstat (limited to 'source3/lib/talloc.c')
-rw-r--r--source3/lib/talloc.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c
index 0e223e8bbe..35c4ddaf31 100644
--- a/source3/lib/talloc.c
+++ b/source3/lib/talloc.c
@@ -1136,6 +1136,46 @@ char *talloc_asprintf(const void *t, const char *fmt, ...)
return ret;
}
+int talloc_vasprintf_len(const void *t, char **res, const char *fmt,
+ va_list ap)
+{
+ int len;
+ va_list ap2;
+ char c;
+
+ VA_COPY(ap2, ap);
+
+ /* this call looks strange, but it makes it work on older solaris boxes */
+ if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) {
+ return len;
+ }
+
+ *res = (char *)_talloc(t, len+1);
+ if (*res) {
+ VA_COPY(ap2, ap);
+ vsnprintf(*res, len+1, fmt, ap2);
+ talloc_set_name_const(*res, *res);
+ }
+
+ return len;
+}
+
+
+/*
+ Perform string formatting, and return a pointer to newly allocated
+ memory holding the result, inside a memory pool.
+ */
+int talloc_asprintf_len(const void *t, char **res, const char *fmt, ...)
+{
+ va_list ap;
+ int len;
+
+ va_start(ap, fmt);
+ len = talloc_vasprintf_len(t, res, fmt, ap);
+ va_end(ap);
+ return len;
+}
+
/**
* Realloc @p s to append the formatted result of @p fmt and @p ap,