>From 2f668c5361e3e992fe902daf31b138d6db325817 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Fri, 7 Feb 2014 21:42:31 +0100 Subject: [PATCH] Move C_strlcat/C_strlcpy definitions up in chicken.h This is needed so that the uses of C_strlcat and C_strcpy in the PRIVATE_REPOSITORY block's inline functions aren't interpreted as implicit forward declarations of external functions by the C compiler, thereby preventing our definitions from being inlined. --- chicken.h | 70 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/chicken.h b/chicken.h index b2cccf4..90fbeff 100644 --- a/chicken.h +++ b/chicken.h @@ -2889,6 +2889,41 @@ C_inline C_word C_a_i_record8(C_word **ptr, int n, C_word x1, C_word x2, C_word return (C_word)p0; } +/* These strl* functions are based on public domain code by C.B. Falconer */ +#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; + + if (sz--) { + while ((*dst++ = *src)) + if (sz--) src++; + else { + *(--dst) = '\0'; + break; + } + } + while (*src++) continue; + return src - start - 1; +} +#endif + +#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 + C_strlcpy(dst, src, sz); +} +#endif + #ifdef C_PRIVATE_REPOSITORY # if defined(C_MACOSX) && defined(C_GUI) @@ -3052,41 +3087,6 @@ C_path_to_executable(C_char *fname) } #endif -/* These strl* functions are based on public domain code by C.B. Falconer */ -#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; - - if (sz--) { - while ((*dst++ = *src)) - if (sz--) src++; - else { - *(--dst) = '\0'; - break; - } - } - while (*src++) continue; - return src - start - 1; -} -#endif - -#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 + C_strlcpy(dst, src, sz); -} -#endif - C_END_C_DECLS #endif /* ___CHICKEN */ -- 1.7.10.4