nes-proj/arch/cpu/arm/common/dbg-io/dbg-sprintf.c

29 lines
836 B
C
Raw Normal View History

2017-11-22 00:53:42 +00:00
/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <strformat.h>
#include <string.h>
2017-11-22 00:53:42 +00:00
/*---------------------------------------------------------------------------*/
static StrFormatResult
buffer_str(void *user_data, const char *data, unsigned int len)
{
2017-11-22 00:58:50 +00:00
memcpy(*(char **)user_data, data, len);
(*(char **)user_data) += len;
return STRFORMAT_OK;
}
2017-11-22 00:53:42 +00:00
/*---------------------------------------------------------------------------*/
int
sprintf(char *str, const char *format, ...)
{
StrFormatContext ctxt;
int res;
va_list ap;
va_start(ap, format);
ctxt.write_str = buffer_str;
ctxt.user_data = &str;
res = format_str_v(&ctxt, format, ap);
*str = '\0';
va_end(ap);
return res;
}
2017-11-22 00:53:42 +00:00
/*---------------------------------------------------------------------------*/