mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 06:42:32 +08:00
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:
@@ -118,7 +118,6 @@ config NANO_PRINTF
|
|||||||
bool "Use nano printf code"
|
bool "Use nano printf code"
|
||||||
default y if DEFAULT_SMALL
|
default y if DEFAULT_SMALL
|
||||||
default n if !DEFAULT_SMALL
|
default n if !DEFAULT_SMALL
|
||||||
depends on !LIBC_LONG_LONG
|
|
||||||
---help---
|
---help---
|
||||||
Replace printf code with version from newlib-nano. Can be
|
Replace printf code with version from newlib-nano. Can be
|
||||||
signifcantly smaller, especially if floating support is enabled.
|
signifcantly smaller, especially if floating support is enabled.
|
||||||
@@ -128,8 +127,10 @@ config NANO_PRINTLEVEL
|
|||||||
int "Nano printf support level"
|
int "Nano printf support level"
|
||||||
default 2 if !LIBC_FLOATINGPOINT
|
default 2 if !LIBC_FLOATINGPOINT
|
||||||
default 3 if LIBC_FLOATINGPOINT
|
default 3 if LIBC_FLOATINGPOINT
|
||||||
range 1 2 if !LIBC_FLOATINGPOINT
|
range 1 2 if !LIBC_FLOATINGPOINT && !LIBC_LONG_LONG
|
||||||
range 1 3 if LIBC_FLOATINGPOINT
|
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
|
depends on NANO_PRINTF
|
||||||
---help---
|
---help---
|
||||||
Nano printf can be built into more than one support level. The
|
Nano printf can be built into more than one support level. The
|
||||||
|
|||||||
@@ -326,7 +326,11 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
|
|||||||
int prec;
|
int prec;
|
||||||
union
|
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' */
|
unsigned char __buf[11]; /* Size for -1 in octal, without '\0' */
|
||||||
|
# endif
|
||||||
# if PRINTF_LEVEL >= PRINTF_FLT
|
# if PRINTF_LEVEL >= PRINTF_FLT
|
||||||
struct dtoa_s __dtoa;
|
struct dtoa_s __dtoa;
|
||||||
# endif
|
# endif
|
||||||
@@ -833,8 +837,16 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
|
|||||||
if (c == 'd' || c == 'i')
|
if (c == 'd' || c == 'i')
|
||||||
{
|
{
|
||||||
long x;
|
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);
|
x = va_arg(ap, long);
|
||||||
}
|
}
|
||||||
@@ -865,10 +877,18 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int base;
|
|
||||||
unsigned long x;
|
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);
|
x = va_arg(ap, unsigned long);
|
||||||
}
|
}
|
||||||
@@ -921,7 +941,7 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
c = __ultoa_invert(x, (char *)buf, base) - (char *)buf;
|
c = __ultoa_invert(x, (char *)buf, base) - (char *)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
flags &= ~FL_NEGATIVE;
|
flags &= ~FL_NEGATIVE;
|
||||||
|
|||||||
@@ -43,7 +43,11 @@
|
|||||||
* Public Functions
|
* 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)
|
FAR char *__ultoa_invert(unsigned long val, FAR char *str, int base)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
int upper = 0;
|
int upper = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
#include <nuttx/compiler.h>
|
#include <nuttx/compiler.h>
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -57,6 +59,10 @@
|
|||||||
|
|
||||||
/* Internal function for use from `printf'. */
|
/* 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 */
|
#endif /* __LIBS_LIBC_STDIO_NANO_ULTOA_INVERT_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user