diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-04-08 11:48:09 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-04-08 11:48:09 +0200 |
commit | c45ac5fe425e187d980b5593d7a4e3aa318e78fe (patch) | |
tree | fd953e6fc29e70a51ffb70987f0b219611321218 /memory.c | |
parent | e9f1a60fcc4e0d6ccc10b0961c0256fa0a729568 (diff) |
Memory asprintf wrapper (and small free fix)
Diffstat (limited to 'memory.c')
-rw-r--r-- | memory.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -1,3 +1,7 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdarg.h> +#include <assert.h> #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; +} |