roken: Add easprintf() and evasprintf() utils

Like emalloc() and ecalloc(): errx on ENOMEM.
This commit is contained in:
Nicolas Williams
2022-12-08 20:13:44 -06:00
parent aaff3aa5c5
commit d5a87e5906
3 changed files with 41 additions and 0 deletions

View File

@@ -701,3 +701,30 @@ rk_vsnprintf (char *str, size_t sz, const char *format, va_list args)
return ret;
}
#endif
#if !defined(HAVE_EVASPRINTF) || defined(TEST_SNPRINTF)
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
rk_evasprintf(const char *format, va_list args)
{
char *s = NULL;
if (vasprintf(&s, format, args) == -1 || s == NULL)
errx(1, "Out of memory");
return s;
}
#endif
#if !defined(HAVE_EASPRINTF) || defined(TEST_SNPRINTF)
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
rk_easprintf(const char *format, ...)
{
va_list args;
char *s = NULL;
va_start(args, format);
if (vasprintf(&s, format, args) == -1 || s == NULL)
errx(1, "Out of memory");
va_end(args);
return s;
}
#endif