From 6531dc4ae259e1279adcb73318b413a2c9f0a200 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Wed, 6 Nov 2013 09:29:55 +0100 Subject: [PATCH] Check for predefined strlcpy (as in newer gcc versions) --- mxml.h | 2 -- strlcpy.c | 6 ++++-- strlcpy.h | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mxml.h b/mxml.h index 67c5920..168df0e 100644 --- a/mxml.h +++ b/mxml.h @@ -5,8 +5,6 @@ Contents: Header file for mxml.c - $Id$ - \********************************************************************/ /*------------------------------------------------------------------*/ diff --git a/strlcpy.c b/strlcpy.c index 5aee762..7b5fb74 100644 --- a/strlcpy.c +++ b/strlcpy.c @@ -6,8 +6,6 @@ Contents: Contains strlcpy and strlcat which are versions of strcpy and strcat, but which avoid buffer overflows - $Id:$ - \********************************************************************/ #include @@ -19,6 +17,8 @@ * will be copied. Always NUL terminates (unless size == 0). * Returns strlen(src); if retval >= siz, truncation occurred. */ +#ifndef STRLCPY_DEFINED + size_t strlcpy(char *dst, const char *src, size_t size) { char *d = dst; @@ -80,3 +80,5 @@ size_t strlcat(char *dst, const char *src, size_t size) } /*-------------------------------------------------------------------*/ + +#endif // STRLCPY_DEFINED diff --git a/strlcpy.h b/strlcpy.h index 8c4720b..cc7f09f 100644 --- a/strlcpy.h +++ b/strlcpy.h @@ -5,13 +5,16 @@ Contents: Header file for strlcpy.c - $Id$ - \********************************************************************/ #ifndef _STRLCPY_H_ #define _STRLCPY_H_ +// some version of gcc have a built-in strlcpy +#ifdef strlcpy +#define STRLCPY_DEFINED +#endif + #ifdef __cplusplus extern "C" { #endif @@ -24,8 +27,10 @@ extern "C" { #endif #endif +#ifndef STRLCPY_DEFINED size_t EXPRT strlcpy(char *dst, const char *src, size_t size); size_t EXPRT strlcat(char *dst, const char *src, size_t size); +#endif #ifdef __cplusplus }