* Use an asprintf wrapper, to report errors and NULLify the result.

This commit is contained in:
Justin Maggard
2012-03-14 17:57:21 +00:00
parent c9d979886b
commit cabbd0b1de
10 changed files with 77 additions and 53 deletions

17
utils.c
View File

@ -52,6 +52,23 @@ strncpyt(char *dst, const char *src, size_t len)
dst[len-1] = '\0';
}
inline int
xasprintf(char **strp, char *fmt, ...)
{
va_list args;
int ret;
va_start(args, fmt);
ret = vasprintf(strp, fmt, args);
va_end(args);
if( ret < 0 )
{
DPRINTF(E_WARN, L_GENERAL, "xasprintf: allocation failed\n");
*strp = NULL;
}
return ret;
}
int
ends_with(const char * haystack, const char * needle)
{