From c45ac5fe425e187d980b5593d7a4e3aa318e78fe Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 8 Apr 2017 11:48:09 +0200 Subject: Memory asprintf wrapper (and small free fix) --- memory.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'memory.c') diff --git a/memory.c b/memory.c index aec3da2..14dddf5 100644 --- a/memory.c +++ b/memory.c @@ -1,3 +1,7 @@ +#define _GNU_SOURCE +#include +#include +#include #include "global.h" #include "memory.h" @@ -14,3 +18,14 @@ void* check_after_allocation_str(const char *func,void *ptr){ } return ptr; } + +__attribute__((format (printf, 2, 3))) +int memory_asprintf_wrapper(char **ret,const char *format,...){ + assert(ret!=NULL); + va_list ap; + va_start(ap,format); + int len=vasprintf(ret,format,ap); + va_end(ap); + check_after_allocation_str("asprintf",*ret); + return len; +} -- cgit v1.2.3-70-g09d2