mirror of
https://github.com/pengutronix/genimage.git
synced 2024-11-23 17:53:52 +08:00
util: add save string concat with formated string
An example: ```c char *txt = NULL; for (int i = 0; i < 5; i++) xstrcatf(&txt, " %d", i); puts(txt); ``` will produce the output: ` 0 1 2 3 4` Signed-off-by: Denis Osterland-Heim <Denis.Osterland@diehl.com>
This commit is contained in:
parent
351d50e378
commit
344416f5d9
@ -17,6 +17,7 @@ void image_error(struct image *image, const char *fmt, ...) __attribute__ ((form
|
||||
void image_info(struct image *image, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
||||
void image_debug(struct image *image, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
||||
void xasprintf(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
||||
void xstrcatf(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3)));
|
||||
|
||||
const char *imagepath(void);
|
||||
const char *inputpath(void);
|
||||
|
17
util.c
17
util.c
@ -76,6 +76,23 @@ void xasprintf(char **strp, const char *fmt, ...)
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
void xstrcatf(char **strp, const char *fmt, ...)
|
||||
{
|
||||
char *tmp;
|
||||
va_list list;
|
||||
|
||||
va_start(list, fmt);
|
||||
xvasprintf(&tmp, fmt, list);
|
||||
va_end(list);
|
||||
if (*strp) {
|
||||
*strp = xrealloc(*strp, strlen(*strp) + strlen(tmp) + 1);
|
||||
strcat(*strp, tmp);
|
||||
free(tmp);
|
||||
} else {
|
||||
*strp = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
static void image_log(struct image *image, int level, const char *fmt,
|
||||
va_list args)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user