diff --git a/.travis.yml b/.travis.yml index 325d573ad..62e60194f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ script: s/travis-build addons: apt: packages: + - libbsd-dev - liblua5.1-dev - libtolua-dev - libncurses5-dev diff --git a/CMakeLists.txt b/CMakeLists.txt index 7507bd99f..683757de0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,17 @@ if (MSVC) include(MSVC) endif (MSVC) -INCLUDE (CheckSymbolExists) -CHECK_SYMBOL_EXISTS(strlcat string.h HAVE_STRLCAT) -CHECK_SYMBOL_EXISTS(strdup string.h HAVE_STRDUP) +INCLUDE (CheckIncludeFile) +CHECK_INCLUDE_FILE(bsd/string.h HAVE_LIBBSD) + +INCLUDE (CheckFunctionExists) +CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP) +IF (HAVE_LIBBSD) +INCLUDE (CheckLibraryExists) +CHECK_LIBRARY_EXISTS(bsd strlcat "bsd/string.h" HAVE_STRLCAT) +ELSE (HAVE_LIBBSD) +CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT) +ENDIF(HAVE_LIBBSD) find_package (SQLite3) find_package (BerkeleyDB) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70ef60b87..4708caf6d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -267,14 +267,24 @@ add_test(server test_eressea) install(TARGETS eressea DESTINATION "bin") +if (HAVE_LIBBSD) + add_definitions(-DHAVE_LIBBSD) +endif (HAVE_LIBBSD) + if (HAVE_STRLCAT) add_definitions(-DHAVE_BSDSTRING) -endif(HAVE_STRLCAT) +endif (HAVE_STRLCAT) if (HAVE_STRDUP) add_definitions(-DHAVE_STRDUP) endif(HAVE_STRDUP) +if (HAVE_LIBBSD) +target_link_libraries(test_eressea bsd) +target_link_libraries(eressea bsd) +target_link_libraries(convert bsd) +endif (HAVE_LIBBSD) + if (DB_FOUND) include_directories (${DB_INCLUDE_DIR}) target_link_libraries(convert ${DB_LIBRARIES}) diff --git a/src/util/strings.c b/src/util/strings.c index d3a1b2eec..b33f657ef 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -25,10 +25,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include #include -#include #include #include +#ifdef HAVE_LIBBSD +#include +#else +#include +#endif + size_t str_strlcpy(char *dst, const char *src, size_t len) { #ifdef HAVE_BSDSTRING @@ -232,10 +237,15 @@ unsigned int wang_hash(unsigned int a) } char *str_strdup(const char *s) { -#ifdef _MSC_VER +#ifdef HAVE_STRDUP + return strdup(s); +#elif defined(_MSC_VER) return _strdup(s); #else - return strdup(s); + size_t len = strlen(s); + char *dup = malloc(len+1); + memcpy(dup, s, len+1); + return dup; #endif }