Skip to content

Commit

Permalink
Merge pull request #30 from filip-stenstrom/locale_apple
Browse files Browse the repository at this point in the history
Include xlocale.h for __APPLE__
  • Loading branch information
filip-stenstrom authored Apr 27, 2021
2 parents 9387139 + fad9c6d commit b0898de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ endif()
if(FMILIB_BUILD_SHARED_LIB)
add_library(fmilib_shared SHARED ${FMILIB_SHARED_SRC})

if (UNIX)
if (UNIX AND NOT APPLE)
target_compile_definitions(fmilib_shared PRIVATE -D_GNU_SOURCE)
endif()

Expand Down
5 changes: 4 additions & 1 deletion Config.cmake/jmutil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ endif(CYGWIN)

target_link_libraries(jmutils c99snprintf)

if(UNIX)
if(UNIX AND NOT APPLE)
target_compile_definitions(jmutils PRIVATE -D_GNU_SOURCE)
endif()

if(UNIX)
target_link_libraries(jmutils dl)
endif(UNIX)
if(WIN32)
Expand Down
18 changes: 14 additions & 4 deletions src/Util/src/JM/jm_portability.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@

#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#include <string.h>

#include <locale.h>

#if defined(_GNU_SOURCE) || defined(__APPLE__)
#define UNIX_THREAD_LOCALE
#endif

#ifdef __APPLE__
/* Include thread-specific locale functions for OSX. */
#include <xlocale.h>
#endif

#include <fmilib_config.h>

Expand Down Expand Up @@ -357,7 +367,7 @@ int jm_snprintf(char * str, size_t size, const char * fmt, ...) {
}

struct jm_locale_t {
#ifdef _GNU_SOURCE
#ifdef UNIX_THREAD_LOCALE
locale_t locale_old;
#else
char* locale_old;
Expand All @@ -375,7 +385,7 @@ jm_locale_t* jm_setlocale_numeric(jm_callbacks* cb, const char* value) {
return NULL;
}

#ifdef _GNU_SOURCE
#ifdef UNIX_THREAD_LOCALE
{
locale_t nloc = NULL;

Expand Down Expand Up @@ -446,7 +456,7 @@ int jm_resetlocale_numeric(jm_callbacks* cb, jm_locale_t* jmloc) {
return 1; /* impl. error */
}

#ifdef _GNU_SOURCE
#ifdef UNIX_THREAD_LOCALE
{
/* Get current locale, which is expected to have been set with a previous
* call to 'jm_setlocale_numeric'. */
Expand Down

0 comments on commit b0898de

Please sign in to comment.