From a697301c44702ee3a8eb7eda67e495cc40d09bb9 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 18 Jun 2014 20:47:06 +0800 Subject: [PATCH] strndup polyfill for cmake --- CMakeLists.txt | 4 +++- include/r3_str.h | 13 +++++++++++++ src/CMakeLists.txt | 2 +- src/str.c | 4 ++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f0c404..0960676 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,9 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ) -include_directories(. "${PROJECT_SOURCE_DIR}/include" ${INCLUDE_DIRECTORIES} /opt/local/include) +include_directories(. ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/3rdparty /opt/local/include) +# include_directories(. ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/3rdparty ${PROJECT_SOURCE_DIR}) + link_directories(${LINK_DIRECTORIES} /opt/local/lib) find_package(PCRE REQUIRED) find_package(Judy REQUIRED) diff --git a/include/r3_str.h b/include/r3_str.h index 8dc5a64..6771dde 100644 --- a/include/r3_str.h +++ b/include/r3_str.h @@ -22,6 +22,19 @@ void str_repeat(char *s, const char *c, int len); void print_indent(int level); + +#if _GNU_SOURCE || POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700 || __DARWIN_C_LEVEL >= 200809L +#define HAVE_STRNDUP +#endif + +#if _SVID_SOURCE || _BSD_SOURCE \ + || _XOPEN_SOURCE >= 500 \ + || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED \ + || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L \ + || __DARWIN_C_LEVEL >= 200809L +#define HAVE_STRDUP +#endif + #ifndef HAVE_STRDUP char *strdup(const char *s); #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a000e5..fb41a55 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories("${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}") +include_directories("${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/3rdparty ${PROJECT_SOURCE_DIR}") # install(TARGETS swiftnav-static DESTINATION lib${LIB_SUFFIX}) set(libr3_SRCS node.c edge.c list.c slug.c str.c token.c) diff --git a/src/str.c b/src/str.c index 4f1b188..7bf5099 100644 --- a/src/str.c +++ b/src/str.c @@ -207,6 +207,8 @@ void print_indent(int level) { } } + + #ifndef HAVE_STRDUP char *zstrdup(const char *s) { char *out; @@ -222,6 +224,8 @@ char *zstrdup(const char *s) { } #endif + + #ifndef HAVE_STRNDUP char *zstrndup(const char *s, int n) { char *out;