X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Ftiny-printf.c;h=8fc7e48d9942178d07c4e3ef76283ad4011e04d9;hb=0a87e05dbd1b6ddafd61603e2a9c12659168ae65;hp=5f7e27d76edf695216b46454725a9055b2d6dc25;hpb=e21c03be6d51ed8ab94885b6829cd0e719778a1e;p=oweals%2Fu-boot.git diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index 5f7e27d76e..8fc7e48d99 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: LGPL-2.1+ /* * Tiny printf version for SPL * @@ -5,8 +6,6 @@ * http://www.sparetimelabs.com/printfrevisited/printfrevisited.php * * Copyright (C) 2004,2008 Kustaa Nyholm - * - * SPDX-License-Identifier: LGPL-2.1+ */ #include @@ -158,7 +157,8 @@ static void ip4_addr_string(struct printf_info *info, u8 *addr) * decimal). */ -static void pointer(struct printf_info *info, const char *fmt, void *ptr) +static void __maybe_unused pointer(struct printf_info *info, const char *fmt, + void *ptr) { #ifdef DEBUG unsigned long num = (uintptr_t)ptr; @@ -242,6 +242,7 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) goto abort; case 'u': case 'd': + case 'i': div = 1000000000; if (islong) { num = va_arg(va, unsigned long); @@ -251,7 +252,7 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) num = va_arg(va, unsigned int); } - if (ch == 'd') { + if (ch != 'u') { if (islong && (long)num < 0) { num = -(long)num; out(info, '-'); @@ -267,6 +268,21 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) div_out(info, &num, div); } break; + case 'p': +#ifdef DEBUG + pointer(info, fmt, va_arg(va, void *)); + /* + * Skip this because it pulls in _ctype which is + * 256 bytes, and we don't generally implement + * pointer anyway + */ + while (isalnum(fmt[0])) + fmt++; + break; +#else + islong = true; + /* no break */ +#endif case 'x': if (islong) { num = va_arg(va, unsigned long); @@ -288,11 +304,6 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) case 's': p = va_arg(va, char*); break; - case 'p': - pointer(info, fmt, va_arg(va, void *)); - while (isalnum(fmt[0])) - fmt++; - break; case '%': out(info, '%'); default: @@ -367,6 +378,22 @@ int sprintf(char *buf, const char *fmt, ...) return ret; } +#if CONFIG_IS_ENABLED(LOG) +/* Note that size is ignored */ +int vsnprintf(char *buf, size_t size, const char *fmt, va_list va) +{ + struct printf_info info; + int ret; + + info.outstr = buf; + info.putc = putc_outstr; + ret = _vprintf(&info, fmt, va); + *info.outstr = '\0'; + + return ret; +} +#endif + /* Note that size is ignored */ int snprintf(char *buf, size_t size, const char *fmt, ...) { @@ -383,3 +410,9 @@ int snprintf(char *buf, size_t size, const char *fmt, ...) return ret; } + +void print_grouped_ull(unsigned long long int_val, int digits) +{ + /* Don't try to print the upper 32-bits */ + printf("%ld ", (ulong)int_val); +}