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
This commit is contained in:
casperinous 2017-10-08 21:55:58 +03:00
parent afd5d186b7
commit 4f9e9dfc30
3 changed files with 11 additions and 0 deletions

View File

@ -186,5 +186,11 @@ if(ENABLE_CJSON_TEST)
DEPENDS ${TEST_CJSON}) DEPENDS ${TEST_CJSON})
endif() 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(tests)
add_subdirectory(fuzzing) add_subdirectory(fuzzing)

View File

@ -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) * `-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) * `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default)
* `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation. * `-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: If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example:
``` ```

View File

@ -193,8 +193,12 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item)
/* get the decimal point character of the current locale */ /* get the decimal point character of the current locale */
static unsigned char get_decimal_point(void) static unsigned char get_decimal_point(void)
{ {
#ifdef ENABLE_LOCALES
struct lconv *lconv = localeconv(); struct lconv *lconv = localeconv();
return (unsigned char) lconv->decimal_point[0]; return (unsigned char) lconv->decimal_point[0];
#else
return '.';
#endif
} }
typedef struct typedef struct