From 4f9e9dfc3089896079d42115fcff354d1565baac Mon Sep 17 00:00:00 2001 From: casperinous Date: Sun, 8 Oct 2017 21:55:58 +0300 Subject: [PATCH 1/2] Fix for issue #202, regarding the lack of implementation of the localeconv method in some SDK's. A macro named `ENABLE_LOCALES` was added and an option with the same name too in the CMakeLists.txt --- CMakeLists.txt | 6 ++++++ README.md | 1 + cJSON.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68f3c5d..e3b8d7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,5 +186,11 @@ if(ENABLE_CJSON_TEST) DEPENDS ${TEST_CJSON}) endif() +# Enable the use of locales +option(ENABLE_LOCALES "Enable the use of locales" ON) +if(ENABLE_LOCALES) + add_definitions(-DENABLE_LOCALES) +endif() + add_subdirectory(tests) add_subdirectory(fuzzing) diff --git a/README.md b/README.md index 4dba514..121e730 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ You can change the build process with a list of different options that you can p * `-DENABLE_SANITIZERS=On`: Compile cJSON with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) enabled (if possible). (off by default) * `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default) * `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation. +* `-DENABLE_LOCALES=On`: Enable the usage of localeconv method. ( on by default ) If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example: ``` diff --git a/cJSON.c b/cJSON.c index 306bb5b..18b52b5 100644 --- a/cJSON.c +++ b/cJSON.c @@ -193,8 +193,12 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) /* get the decimal point character of the current locale */ static unsigned char get_decimal_point(void) { +#ifdef ENABLE_LOCALES struct lconv *lconv = localeconv(); return (unsigned char) lconv->decimal_point[0]; +#else + return '.'; +#endif } typedef struct From 9b960fa870f3f7d754ccb048e51780f7150f970b Mon Sep 17 00:00:00 2001 From: casperinous Date: Sun, 8 Oct 2017 22:02:52 +0300 Subject: [PATCH 2/2] Small indentation fix in order to follow the contribution rules. --- cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 18b52b5..fa143cc 100644 --- a/cJSON.c +++ b/cJSON.c @@ -197,7 +197,7 @@ static unsigned char get_decimal_point(void) struct lconv *lconv = localeconv(); return (unsigned char) lconv->decimal_point[0]; #else - return '.'; + return '.'; #endif }