Check for predefined strlcpy (as in newer gcc versions)

This commit is contained in:
Stefan Ritt 2013-11-06 09:29:55 +01:00
parent 19a939ec26
commit 6531dc4ae2
3 changed files with 11 additions and 6 deletions

2
mxml.h
View File

@ -5,8 +5,6 @@
Contents: Header file for mxml.c Contents: Header file for mxml.c
$Id$
\********************************************************************/ \********************************************************************/
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/

View File

@ -6,8 +6,6 @@
Contents: Contains strlcpy and strlcat which are versions of Contents: Contains strlcpy and strlcat which are versions of
strcpy and strcat, but which avoid buffer overflows strcpy and strcat, but which avoid buffer overflows
$Id:$
\********************************************************************/ \********************************************************************/
#include <stdio.h> #include <stdio.h>
@ -19,6 +17,8 @@
* will be copied. Always NUL terminates (unless size == 0). * will be copied. Always NUL terminates (unless size == 0).
* Returns strlen(src); if retval >= siz, truncation occurred. * Returns strlen(src); if retval >= siz, truncation occurred.
*/ */
#ifndef STRLCPY_DEFINED
size_t strlcpy(char *dst, const char *src, size_t size) size_t strlcpy(char *dst, const char *src, size_t size)
{ {
char *d = dst; char *d = dst;
@ -80,3 +80,5 @@ size_t strlcat(char *dst, const char *src, size_t size)
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
#endif // STRLCPY_DEFINED

View File

@ -5,13 +5,16 @@
Contents: Header file for strlcpy.c Contents: Header file for strlcpy.c
$Id$
\********************************************************************/ \********************************************************************/
#ifndef _STRLCPY_H_ #ifndef _STRLCPY_H_
#define _STRLCPY_H_ #define _STRLCPY_H_
// some version of gcc have a built-in strlcpy
#ifdef strlcpy
#define STRLCPY_DEFINED
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -24,8 +27,10 @@ extern "C" {
#endif #endif
#endif #endif
#ifndef STRLCPY_DEFINED
size_t EXPRT strlcpy(char *dst, const char *src, size_t size); size_t EXPRT strlcpy(char *dst, const char *src, size_t size);
size_t EXPRT strlcat(char *dst, const char *src, size_t size); size_t EXPRT strlcat(char *dst, const char *src, size_t size);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }