This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 11dc1df1891 libc: improve libc dependencies in case of LIBM_NONE
11dc1df1891 is described below

commit 11dc1df189184ac4a25090ab09b2dff508f95f6c
Author: Petro Karashchenko <[email protected]>
AuthorDate: Sun Dec 14 17:29:31 2025 +0100

    libc: improve libc dependencies in case of LIBM_NONE
    
    Currently the code for strtof, strtod and strtold is in the list
    of files to compile unconditionally, but when trying to compile
    kernel with toolchain without libm support (LIBM_NONE=y) compilation
    fails because code refers math.h
    
    Signed-off-by: Petro Karashchenko <[email protected]>
---
 libs/libc/stdlib/CMakeLists.txt  |  5 ++++-
 libs/libc/stdlib/Make.defs       | 12 ++++++++----
 libs/libc/stream/lib_libvscanf.c | 26 ++++++++++++++++++--------
 3 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/libs/libc/stdlib/CMakeLists.txt b/libs/libc/stdlib/CMakeLists.txt
index 39ee2a80007..28c1fa63843 100644
--- a/libs/libc/stdlib/CMakeLists.txt
+++ b/libs/libc/stdlib/CMakeLists.txt
@@ -48,7 +48,6 @@ set(SRCS
     lib_strtoll.c
     lib_strtoul.c
     lib_strtoull.c
-    lib_strtold.c
     lib_checkbase.c
     lib_mktemp.c
     lib_mkstemp.c
@@ -64,6 +63,10 @@ set(SRCS
     lib_arc4random.c
     lib_atexit.c)
 
+if(NOT CONFIG_LIBM_NONE)
+  list(APPEND SRCS lib_strtold.c)
+endif()
+
 if(CONFIG_PSEUDOTERM)
   list(APPEND SRCS lib_ptsname.c lib_ptsnamer.c lib_unlockpt.c lib_openpty.c)
 endif()
diff --git a/libs/libc/stdlib/Make.defs b/libs/libc/stdlib/Make.defs
index 22b57ccf0e2..50063b2c37c 100644
--- a/libs/libc/stdlib/Make.defs
+++ b/libs/libc/stdlib/Make.defs
@@ -26,12 +26,16 @@ CSRCS += lib_abs.c lib_abort.c lib_atof.c lib_atoi.c 
lib_getprogname.c
 CSRCS += lib_atol.c lib_atoll.c lib_div.c lib_ldiv.c lib_lldiv.c lib_exit.c
 CSRCS += lib_itoa.c lib_labs.c lib_llabs.c lib_realpath.c lib_bsearch.c
 CSRCS += lib_rand.c lib_rand48.c lib_qsort.c lib_srand.c lib_strtol.c
-CSRCS += lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_strtold.c
-CSRCS += lib_checkbase.c lib_mktemp.c lib_mkstemp.c lib_mkdtemp.c
-CSRCS += lib_aligned_alloc.c lib_posix_memalign.c lib_valloc.c lib_mblen.c
-CSRCS += lib_mbtowc.c lib_wctomb.c lib_mbstowcs.c lib_wcstombs.c lib_atexit.c
+CSRCS += lib_strtoll.c lib_strtoul.c lib_strtoull.c lib_checkbase.c
+CSRCS += lib_mktemp.c lib_mkstemp.c lib_mkdtemp.c lib_aligned_alloc.c
+CSRCS += lib_posix_memalign.c lib_valloc.c lib_mblen.c lib_mbtowc.c
+CSRCS += lib_wctomb.c lib_mbstowcs.c lib_wcstombs.c lib_atexit.c
 CSRCS += lib_reallocarray.c lib_arc4random.c
 
+ifneq ($(CONFIG_LIBM_NONE),y)
+CSRCS += lib_strtold.c
+endif
+
 ifeq ($(CONFIG_PSEUDOTERM),y)
 CSRCS += lib_ptsname.c lib_ptsnamer.c lib_unlockpt.c lib_openpty.c
 endif
diff --git a/libs/libc/stream/lib_libvscanf.c b/libs/libc/stream/lib_libvscanf.c
index 05bf2198c7a..c973e3a537f 100644
--- a/libs/libc/stream/lib_libvscanf.c
+++ b/libs/libc/stream/lib_libvscanf.c
@@ -44,6 +44,18 @@
 #  undef CONFIG_LIBC_LONG_LONG
 #endif
 
+#ifdef CONFIG_LIBC_SCANSET
+#  define SCANSET_MODS "["
+#else
+#  define SCANSET_MODS
+#endif
+
+#ifdef CONFIG_LIBC_FLOATINGPOINT
+#  define FLOATINGPOINT_MODS "aAfFeEgG"
+#else
+#  define FLOATINGPOINT_MODS
+#endif
+
 #define MAXLN   128
 
 #define HH_MOD -2
@@ -297,11 +309,10 @@ static int vscanf_internal(FAR struct lib_instream_s 
*stream, FAR int *lastc,
           fmt++;
           for (; fmt_char(fmt); fmt++)
             {
-#ifdef CONFIG_LIBC_SCANSET
-              if (strchr("diboupxXcseEfFgGaAn[%", fmt_char(fmt)))
-#else
-              if (strchr("diboupxXcseEfFgGaAn%", fmt_char(fmt)))
-#endif
+              if (strchr("diboupxXcsn"
+                         FLOATINGPOINT_MODS
+                         SCANSET_MODS
+                         "%", fmt_char(fmt)))
                 {
                   if (fmt_char(fmt) != '%')
                     {
@@ -936,6 +947,7 @@ static int vscanf_internal(FAR struct lib_instream_s 
*stream, FAR int *lastc,
                 }
             }
 
+#ifdef CONFIG_LIBC_FLOATINGPOINT
           /* Process %a, %A, %f, %F, %e, %E, %g, and %G: Floating point
            * conversions.
            */
@@ -977,8 +989,6 @@ static int vscanf_internal(FAR struct lib_instream_s 
*stream, FAR int *lastc,
 #endif
                 }
 
-#ifdef CONFIG_LIBC_FLOATINGPOINT
-
               /* Skip over any white space before the real string */
 
               while (isspace(c))
@@ -1138,8 +1148,8 @@ static int vscanf_internal(FAR struct lib_instream_s 
*stream, FAR int *lastc,
 
                   count++;
                 }
-#endif
             }
+#endif
 
           /* Process %n: Character count */
 

Reply via email to