diff --git a/source/compiler/CMakeLists.txt b/source/compiler/CMakeLists.txt index a2eb8a9..ab7d9fe 100644 --- a/source/compiler/CMakeLists.txt +++ b/source/compiler/CMakeLists.txt @@ -22,6 +22,17 @@ if(HAVE_ALLOCA_H) add_definitions(-DHAVE_ALLOCA_H) endif() +# check for optional library functions +include(CheckFunctionExists) +check_function_exists(strlcpy HAVE_STRLCPY) +if(HAVE_STRLCPY) + add_definitions(-DHAVE_STRLCPY) +endif() +check_function_exists(strlcat HAVE_STRLCAT) +if(HAVE_STRLCAT) + add_definitions(-DHAVE_STRLCAT) +endif() + if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS /J) endif() diff --git a/source/compiler/lstring.c b/source/compiler/lstring.c index b21f352..bbd359f 100644 --- a/source/compiler/lstring.c +++ b/source/compiler/lstring.c @@ -7,7 +7,7 @@ #include "lstring.h" -#if !defined HAVE_SAFESTR +#if !defined HAVE_STRLCPY /* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */ @@ -63,6 +63,10 @@ strlcpy(char *dst, const char *src, size_t siz) return(s - src - 1); /* count does not include NUL */ } +#endif /* if !defined HAVE_STRLCPY */ + +#if !defined HAVE_STRLCAT + /* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ /* @@ -121,4 +125,4 @@ strlcat(char *dst, const char *src, size_t siz) return(dlen + (s - src)); /* count does not include NUL */ } -#endif /* #if !defined HAVE_SAFESTR */ +#endif /* #if !defined HAVE_STRLCAT */ diff --git a/source/compiler/lstring.h b/source/compiler/lstring.h index 1e7e048..25c0873 100644 --- a/source/compiler/lstring.h +++ b/source/compiler/lstring.h @@ -7,11 +7,20 @@ #define HAVE_SAFESTR #endif -#if !defined HAVE_SAFESTR +#if defined HAVE_SAFESTR + #define HAVE_STRLCPY + #define HAVE_STRLCAT +#endif + +#if !defined HAVE_STRLCPY size_t strlcpy(char *dst, const char *src, size_t siz); +#endif + +#if !defined HAVE_STRLCAT + size_t strlcat(char *dst, const char *src, size_t siz);