Mercurial > trustbridge
diff common/strhelp.c @ 319:4077eff1dd39
Added terminateing version of asprintf.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 04 Apr 2014 17:58:14 +0200 |
parents | c4a989a0d6cf |
children | 17e1c8f37d72 |
line wrap: on
line diff
--- a/common/strhelp.c Fri Apr 04 17:13:35 2014 +0200 +++ b/common/strhelp.c Fri Apr 04 17:58:14 2014 +0200 @@ -1,4 +1,8 @@ +/* Needed to get asprintf */ +#define _GNU_SOURCE 1 + #include <ctype.h> +#include <stdarg.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -194,6 +198,21 @@ free (p); } +int +xasprintf (char **strp, const char *fmt, ...) +{ + int ret; + va_list ap; + va_start(ap, fmt); + ret = vasprintf(strp, fmt, ap); + va_end(ap); + + if (ret == -1) + out_of_core(); + + return ret; +} + #ifdef WIN32 /* Adapted from GPGOL rev. e512053 */ char *