Detect strlcpy() and strlcat() via cmake

This commit is contained in:
Zeex 2015-04-04 23:21:06 +06:00
parent 6e8319d4f4
commit b57210fe80
3 changed files with 27 additions and 3 deletions

View File

@ -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()

View File

@ -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 */

View File

@ -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);