libs/libc/stdio/nano_libvsprintf.c: Add long long support. CONFIG_LIBC_LONG_LONG needs at least CONFIG_NANO_PRINTLEVEL 2. Code size for compile without CONFIG_LIBC_LONG_LONG shouldn't be affected.

This commit is contained in:
Johannes 2019-02-15 19:10:40 -06:00 committed by Gregory Nutt
parent 72bc331217
commit 41a4a40879
4 changed files with 39 additions and 8 deletions

View File

@ -118,7 +118,6 @@ config NANO_PRINTF
bool "Use nano printf code"
default y if DEFAULT_SMALL
default n if !DEFAULT_SMALL
depends on !LIBC_LONG_LONG
---help---
Replace printf code with version from newlib-nano. Can be
signifcantly smaller, especially if floating support is enabled.
@ -128,8 +127,10 @@ config NANO_PRINTLEVEL
int "Nano printf support level"
default 2 if !LIBC_FLOATINGPOINT
default 3 if LIBC_FLOATINGPOINT
range 1 2 if !LIBC_FLOATINGPOINT
range 1 3 if LIBC_FLOATINGPOINT
range 1 2 if !LIBC_FLOATINGPOINT && !LIBC_LONG_LONG
range 1 3 if LIBC_FLOATINGPOINT && !LIBC_LONG_LONG
range 2 2 if !LIBC_FLOATINGPOINT && LIBC_LONG_LONG
range 2 3 if LIBC_FLOATINGPOINT && LIBC_LONG_LONG
depends on NANO_PRINTF
---help---
Nano printf can be built into more than one support level. The

View File

@ -326,7 +326,11 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
int prec;
union
{
# ifdef CONFIG_LIBC_LONG_LONG
unsigned char __buf[22]; /* Size for -1 in octal, without '\0' */
# else
unsigned char __buf[11]; /* Size for -1 in octal, without '\0' */
# endif
# if PRINTF_LEVEL >= PRINTF_FLT
struct dtoa_s __dtoa;
# endif
@ -833,8 +837,16 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
if (c == 'd' || c == 'i')
{
long x;
#ifdef CONFIG_LIBC_LONG_LONG
long long x;
if (flags & FL_LONG)
if ((flags & FL_LONGLONG) != 0)
{
x = va_arg(ap, long long);
}
else
#endif
if ((flags & FL_LONG) != 0)
{
x = va_arg(ap, long);
}
@ -865,10 +877,18 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
}
else
{
int base;
unsigned long x;
int base;
#ifdef CONFIG_LIBC_LONG_LONG
unsigned long long x;
if (flags & FL_LONG)
if (flags & FL_LONGLONG) != 0)
{
x = va_arg(ap, unsigned long long);
}
else
#endif
if ((flags & FL_LONG) != 0)
{
x = va_arg(ap, unsigned long);
}
@ -921,7 +941,7 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
}
else
{
c = __ultoa_invert(x, (char *)buf, base) - (char *)buf;
c = __ultoa_invert(x, (char *)buf, base) - (char *)buf;
}
flags &= ~FL_NEGATIVE;

View File

@ -43,7 +43,11 @@
* Public Functions
****************************************************************************/
#ifdef CONFIG_LIBC_LONG_LONG
FAR char *__ultoa_invert(unsigned long long val, FAR char *str, int base)
#else
FAR char *__ultoa_invert(unsigned long val, FAR char *str, int base)
#endif
{
int upper = 0;

View File

@ -42,6 +42,8 @@
#include <nuttx/compiler.h>
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -57,6 +59,10 @@
/* Internal function for use from `printf'. */
FAR char *__ultoa_invert(unsigned long val, FAR char *s, int base);
#ifdef CONFIG_LIBC_LONG_LONG
FAR char *__ultoa_invert(unsigned long long val, FAR char *str, int base);
#else
FAR char *__ultoa_invert(unsigned long val, FAR char *str, int base);
#endif
#endif /* __LIBS_LIBC_STDIO_NANO_ULTOA_INVERT_H */