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

@@ -563,6 +563,18 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
__attribute__ ((__format__ (__printf__, 3, 0)));
#endif
#if !defined(HAVE_EVASPRINTF) || defined(NEED_EVASPRINTF_PROTO)
#define evasprintf rk_evasprintf
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
rk_evasprintf(const char *format, va_list args);
#endif
#if !defined(HAVE_EASPRINTF) || defined(NEED_EASPRINTF_PROTO)
#define easprintf rk_easprintf
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
rk_easprintf(const char *format, ...);
#endif
#ifndef HAVE_STRDUP
#define strdup rk_strdup
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);

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

View File

@@ -52,12 +52,14 @@ HEIMDAL_ROKEN_2.0 {
rk_dns_string_to_type;
rk_dns_type_to_string;
rk_dumpdata;
rk_easprintf;
rk_ecalloc;
rk_emalloc;
rk_eread;
rk_erealloc;
rk_esetenv;
rk_estrdup;
rk_evasprintf;
rk_ewrite;
rk_flock;
rk_fnmatch;