# HG changeset patch # User Sascha Wilde # Date 1396627094 -7200 # Node ID 4077eff1dd39e4f7d7aee8e350c223e6975ff992 # Parent 6ccaf25219fd322bfb37e840abadaf1696f02a96 Added terminateing version of asprintf. diff -r 6ccaf25219fd -r 4077eff1dd39 common/strhelp.c --- 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 +#include #include #include #include @@ -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 * diff -r 6ccaf25219fd -r 4077eff1dd39 common/strhelp.h --- a/common/strhelp.h Fri Apr 04 17:13:35 2014 +0200 +++ b/common/strhelp.h Fri Apr 04 17:58:14 2014 +0200 @@ -23,6 +23,15 @@ void xfree ( void *p ); /** + * @brief Terminating variant of asprintf + * + * This function behaves exactly like asprintf(3) but will terminate + * when an error occures (usally that means that memoy allocation + * failed). + */ +int xasprintf (char **strp, const char *fmt, ...); + +/** * @brief Returns the length of the given %NULL-terminated * string array str_array. * @param[in] str_array a %NULL-terminated array of strings