mirror of https://gerrit.osmocom.org/libosmocore
pseudotalloc: Add simplistic implementation of talloc_asprintf
fsm.c uses this function. When compiled with --enable-embedded, it triggers a warning: fsm.c: In function 'osmo_fsm_inst_alloc': fsm.c:213:4: warning: implicit declaration of function 'talloc_asprintf' [-Wimplicit-function-declaration] fi->name = talloc_asprintf(fi, "%s(%s)", fsm->name, id); Change-Id: I61cd83d4c8570af1e452c945ac6f194baf7e6ac4
This commit is contained in:
parent
ffa41ca665
commit
00f4ef7262
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "talloc.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void *_talloc_zero(const void *ctx, size_t size, const char *name)
|
||||
{
|
||||
|
@ -61,3 +62,18 @@ void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const
|
|||
{
|
||||
return talloc_zero_size(ctx, el_size * count);
|
||||
}
|
||||
|
||||
char *talloc_asprintf(const void *ctx, const char *fmt, ...)
|
||||
{
|
||||
char *buf;
|
||||
size_t len = 128;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
buf = talloc_size(ctx, len);
|
||||
if (len < vsnprintf(buf, len, fmt, args))
|
||||
strcpy(&buf[len-6], "[...]");
|
||||
|
||||
va_end(args);
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -39,4 +39,4 @@ void *_talloc_zero_array(const void *ctx,
|
|||
size_t el_size,
|
||||
unsigned count,
|
||||
const char *name);
|
||||
|
||||
char *talloc_asprintf(const void *ctx, const char *fmt, ...);
|
||||
|
|
Loading…
Reference in New Issue