From eac66d76b3ca9a0a9d05b54169af8f2579b63442 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 1 Jun 2020 14:19:26 +0800 Subject: [PATCH] lib/stdlib: Change some macro to inline function to avoid the build break for "using ::xxx" Signed-off-by: Xiang Xiao Change-Id: Ib5d861a6c2b9e6ba585df83b3cdff8a3e1495bce --- include/stdlib.h | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/include/stdlib.h b/include/stdlib.h index 004fe01f59..388cb858db 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -158,7 +158,15 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg); /* _Exit() is a stdlib.h equivalent to the unistd.h _exit() function */ void _exit(int status); /* See unistd.h */ -#define _Exit(s) _exit(s) + +#ifdef __cplusplus +inline void _Exit(int s) +{ + _exit(s); +} +#else +#define _Exit(s) _exit(s) +#endif /* System() command is not implemented in the NuttX libc because it is so * entangled with shell logic. There is an experimental version at @@ -187,13 +195,44 @@ double strtod(FAR const char *str, FAR char **endptr); long double strtold(FAR const char *str, FAR char **endptr); #endif -#define atoi(nptr) ((int)strtol((nptr), NULL, 10)) -#define atol(nptr) strtol((nptr), NULL, 10) +#ifdef __cplusplus +inline int atoi(FAR const char *nptr) +{ + return (int)strtol(nptr, NULL, 10); +} +#else +#define atoi(nptr) ((int)strtol((nptr), NULL, 10)) +#endif + +#ifdef __cplusplus +inline int atol(FAR const char *nptr) +{ + return strtol(nptr, NULL, 10); +} +#else +#define atol(nptr) strtol((nptr), NULL, 10) +#endif + #ifdef CONFIG_HAVE_LONG_LONG +#ifdef __cplusplus +inline long long atoll(FAR const char *nptr) +{ + return strtoll(nptr, NULL, 10); +} +#else #define atoll(nptr) strtoll((nptr), NULL, 10) #endif +#endif + #ifdef CONFIG_HAVE_DOUBLE -#define atof(nptr) strtod((nptr), NULL) +#ifdef __cplusplus +inline double atof(FAR const char *nptr) +{ + return strtod(nptr, NULL); +} +#else +#define atof(nptr) strtod((nptr), NULL) +#endif #endif /* Binary to string conversions */