mirror of
https://github.com/linux-sunxi/u-boot-sunxi.git
synced 2024-02-12 11:16:03 +08:00
tiny-printf: Support snprintf()
Add a simple version of this function for SPL. It does not check the buffer size as this would add to the code size. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Stefan Roese <sr@denx.de>
This commit is contained in:
@ -16,6 +16,9 @@
|
|||||||
static char *bf;
|
static char *bf;
|
||||||
static char zs;
|
static char zs;
|
||||||
|
|
||||||
|
/* Current position in sprintf() output string */
|
||||||
|
static char *outstr;
|
||||||
|
|
||||||
static void out(char c)
|
static void out(char c)
|
||||||
{
|
{
|
||||||
*bf++ = c;
|
*bf++ = c;
|
||||||
@ -40,7 +43,7 @@ static void div_out(unsigned int *num, unsigned int div)
|
|||||||
out_dgt(dgt);
|
out_dgt(dgt);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vprintf(const char *fmt, va_list va)
|
int _vprintf(const char *fmt, va_list va, void (*putc)(const char ch))
|
||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
char *p;
|
char *p;
|
||||||
@ -133,8 +136,28 @@ int printf(const char *fmt, ...)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
ret = vprintf(fmt, va);
|
ret = _vprintf(fmt, va, putc);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void putc_outstr(char ch)
|
||||||
|
{
|
||||||
|
*outstr++ = ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Note that size is ignored */
|
||||||
|
int snprintf(char *buf, size_t size, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list va;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
va_start(va, fmt);
|
||||||
|
outstr = buf;
|
||||||
|
ret = _vprintf(fmt, va, putc_outstr);
|
||||||
|
va_end(va);
|
||||||
|
*outstr = '\0';
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user