>From e129a57462391398b2ad469ab792cd084a161c04 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Thu, 6 Feb 2014 09:56:48 +0100 Subject: [PATCH 1/2] Prevent problems when the host system does provide strlcpy/strlcat. Defining strlcat/strlcopy causes trouble if HAVE_STRLCAT/HAVE_STRLCPY is not set and the host system does offer these functions. This could also happen on systems that don't offer these functions but bsd/string.h is being included by user code on Linux, for example. Instead of defining strlcat and defining C_strlcat to point to that, we define the replacement function directly under the name C_strlcat. On systems which do have strlcat, we define C_strlcat as an alias of strlcat. --- chicken.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/chicken.h b/chicken.h index 6b8fc6a..b2cccf4 100644 --- a/chicken.h +++ b/chicken.h @@ -923,12 +923,10 @@ DECL_C_PROC_p0 (128, 1,0,0,0,0,0,0,0) # define C_memcpy memcpy # define C_memcmp memcmp -# define C_strlcpy strlcpy # define C_strncpy strncpy # define C_strcmp strcmp # define C_strncmp strncmp # define C_strlen strlen -# define C_strlcat strlcat # define C_memset memset # define C_memmove memmove # define C_strncasecmp strncasecmp @@ -3055,8 +3053,10 @@ C_path_to_executable(C_char *fname) #endif /* These strl* functions are based on public domain code by C.B. Falconer */ -#ifndef HAVE_STRLCPY -C_inline size_t strlcpy(char *dst, const char *src, size_t sz) +#ifdef HAVE_STRLCPY +# define C_strlcpy strlcpy +#else +C_inline size_t C_strlcpy(char *dst, const char *src, size_t sz) { const char *start = src; @@ -3073,15 +3073,17 @@ C_inline size_t strlcpy(char *dst, const char *src, size_t sz) } #endif -#ifndef HAVE_STRLCAT -C_inline size_t strlcat(char *dst, const char *src, size_t sz) +#ifdef HAVE_STRLCAT +# define C_strlcat strlcat +#else +C_inline size_t C_strlcat(char *dst, const char *src, size_t sz) { char *start = dst; while (*dst++) /* assumes sz >= strlen(dst) */ if (sz) sz--; /* i.e. well formed string */ dst--; - return dst - start + strlcpy(dst, src, sz); + return dst - start + C_strlcpy(dst, src, sz); } #endif -- 1.7.10.4