diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-08-21 07:43:29 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:58:14 -0500 |
commit | b7e1ea20dc873a753ff64653987130f03897a4e9 (patch) | |
tree | 67f37a1a19113c622dedf942f39b27ca994c1b05 /source4/lib | |
parent | b45f4ebbb880e41abf86abb54264123f3edbde05 (diff) | |
download | samba-b7e1ea20dc873a753ff64653987130f03897a4e9.tar.gz samba-b7e1ea20dc873a753ff64653987130f03897a4e9.tar.bz2 samba-b7e1ea20dc873a753ff64653987130f03897a4e9.zip |
r1985: take advantage of the new talloc in a few more places
(This used to be commit 6ffdfd779936ce8c5ca49c5f444e8da2bbeee0a8)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/talloc.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/source4/lib/talloc.c b/source4/lib/talloc.c index 8a67f83a7f..b01bcb27c8 100644 --- a/source4/lib/talloc.c +++ b/source4/lib/talloc.c @@ -20,6 +20,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* + inspired by http://swapped.cc/halloc/ +*/ + #include "includes.h" #define MAX_TALLOC_SIZE 0x10000000 @@ -81,24 +85,49 @@ void *talloc(void *context, size_t size) /* - create a named talloc pointer + add a name to an existing pointer - va_list version +*/ +static void talloc_set_name_v(void *ptr, const char *fmt, va_list ap) +{ + struct talloc_chunk *tc; + + tc = ((struct talloc_chunk *)ptr)-1; + if (tc->magic != TALLOC_MAGIC) { + return; + } + + vasprintf(&tc->name, fmt, ap); +} + +/* + add a name to an existing pointer +*/ +void talloc_set_name(void *ptr, const char *fmt, ...) _PRINTF_ATTRIBUTE(2,3) +{ + va_list ap; + va_start(ap, fmt); + talloc_set_name_v(ptr, fmt, ap); + va_end(ap); +} + +/* + create a named talloc pointer. Any talloc pointer can be named, and + talloc_named() operates just like talloc() except that it allows you + to name the pointer. */ void *talloc_named(void *context, size_t size, const char *fmt, ...) _PRINTF_ATTRIBUTE(3,4) { va_list ap; void *ptr; - struct talloc_chunk *tc; ptr = talloc(context, size); if (ptr == NULL) { return NULL; } - tc = ((struct talloc_chunk *)ptr)-1; - va_start(ap, fmt); - vasprintf(&tc->name, fmt, ap); + talloc_set_name_v(ptr, fmt, ap); va_end(ap); return ptr; |