[misc] Add string_printf function

This commit is contained in:
chme 2017-04-09 09:16:00 +02:00
parent 4423cd4ce6
commit 4e6b78ca29
2 changed files with 25 additions and 0 deletions

View File

@ -32,6 +32,7 @@
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <limits.h>
#include <sys/param.h>
#ifndef CLOCK_REALTIME
@ -1132,3 +1133,25 @@ log_fatal_null(int domain, const char *func, int line)
DPRINTF(E_FATAL, domain, "%s returned NULL at line %d\n", func, line);
abort();
}
/*
* Wrapper function for vasprintf by Intel Corporation
* Published under the L-GPL 2.1 licence as part of clr-boot-manager
*
* https://github.com/clearlinux/clr-boot-manager
*/
char *string_printf(const char *fmt, ...)
{
char *ret = NULL;
va_list va;
va_start(va, fmt);
if (vasprintf(&ret, fmt, va) < 0)
{
DPRINTF(E_FATAL, L_MISC, "Out of memory for string_printf\n");
abort();
}
va_end(va);
return ret;
}

View File

@ -196,4 +196,6 @@ void log_fatal_err(int domain, const char *func, int line, int err);
void log_fatal_errno(int domain, const char *func, int line);
void log_fatal_null(int domain, const char *func, int line);
char *string_printf(const char *fmt, ...);
#endif /* !__MISC_H__ */