1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 21:08:08 +01:00

Use -lbsd for strlcat/strlcpy, if needed and available

On BSD systems, strlcat and strlcpy are included in the C library and
nothing special is needed. On Linux systems they are not, but libbsd may
be available to provide them. Use it if so.

This also adds wstrlcat and wstrlcpy instead of trying to maybe-provide
strlcat and strlcpy themselves, as that way there is no risk of symbol
conflicts. Not bumping the library version at this time, that should be
done (if necessary) before release.

Signed-off-by: Brad Jorsch <anomie@users.sourceforge.net>
This commit is contained in:
Brad Jorsch
2010-09-24 14:37:57 -04:00
committed by Carlos R. Mafra
parent f206c15fea
commit 8ca05fd4be
4 changed files with 49 additions and 17 deletions

View File

@@ -13,7 +13,8 @@ lib_LTLIBRARIES = libWUtil.la libWINGs.la
LDADD= libWUtil.la libWINGs.la $(top_builddir)/wrlib/libwraster.la @INTLIBS@
libWINGs_la_LIBADD = libWUtil.la $(top_builddir)/wrlib/libwraster.la @XFTLIBS@ @FCLIBS@ @LIBM@
libWINGs_la_LIBADD = libWUtil.la $(top_builddir)/wrlib/libwraster.la @XFTLIBS@ @FCLIBS@ @LIBM@ @LIBBSD@
libWUtil_la_LIBADD = @LIBBSD@
EXTRA_DIST = BUGS make-rgb Examples Extras Tests

View File

@@ -222,6 +222,9 @@ char* wstrconcat(char *str1, char *str2);
* so always assign the returned address to avoid dangling pointers. */
char* wstrappend(char *dst, char *src);
size_t wstrlcpy(char *, const char *, size_t);
size_t wstrlcat(char *, const char *, size_t);
void wtokensplit(char *command, char ***argv, int *argc);
@@ -849,13 +852,6 @@ extern int WCErrorCode;
/*-------------------------------------------------------------------------*/
#ifndef HAVE_STRLCPY
size_t strlcpy(char *, const char *, size_t);
#endif
#ifndef HAVE_STRLCAT
size_t strlcat(char *, const char *, size_t);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@@ -4,6 +4,9 @@
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#ifdef HAVE_BSD_STRING_H
#include <bsd/string.h>
#endif
#include "WUtil.h"
@@ -209,7 +212,13 @@ char *wstrappend(char *dst, char *src)
}
#ifndef HAVE_STRLCAT
#ifdef HAVE_STRLCAT
size_t
wstrlcat(char *dst, const char *src, size_t siz)
{
return strlcat(dst, src, siz);
}
#else
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
/*
@@ -236,7 +245,7 @@ char *wstrappend(char *dst, char *src)
* If retval >= siz, truncation occurred.
*/
size_t
strlcat(char *dst, const char *src, size_t siz)
wstrlcat(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
@@ -264,7 +273,13 @@ strlcat(char *dst, const char *src, size_t siz)
}
#endif /* HAVE_STRLCAT */
#ifndef HAVE_STRLCPY
#ifdef HAVE_STRLCPY
size_t
wstrlcpy(char *dst, const char *src, size_t siz)
{
return strlcpy(dst, src, siz);
}
#else
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
@@ -290,7 +305,7 @@ strlcat(char *dst, const char *src, size_t siz)
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
strlcpy(char *dst, const char *src, size_t siz)
wstrlcpy(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;

View File

@@ -168,11 +168,31 @@ AC_CHECK_FUNCS(gethostname select poll strcasecmp strncasecmp \
dnl Check for strlcat/strlcpy
dnl =========================
dnl XXX: A clean way to use libbsd-supplied equivalents should be come up
dnl with. This is a tricky-ish problem, as it will require a conditional
dnl inclusion of an extra header everywhere there is string.h included.
AC_CHECK_FUNC(strlcat, AC_DEFINE(HAVE_STRLCAT, 1, Check for strlcat))
AC_CHECK_FUNC(strlcpy, AC_DEFINE(HAVE_STRLCPY, 1, Check for strlcpy))
AC_ARG_WITH([libbsd],
[AS_HELP_STRING([--without-libbsd], [do not use libbsd for strlcat and strlcpy [default=check]])],
[AS_IF([test "x$with_libbsd" != "xno"],
[with_libbsd=bsd]
[with_libbsd=]
)],
[with_libbsd=bsd])
tmp_libs=$LIBS
AC_SEARCH_LIBS([strlcat],[$with_libbsd],
[AC_DEFINE(HAVE_STRLCAT, 1, [Define if strlcat is available])],
[]
)
AC_SEARCH_LIBS([strlcpy],[$with_libbsd],
[AC_DEFINE(HAVE_STRLCAT, 1, [Define if strlcpy is available])],
[]
)
LIBS=$tmp_libs
LIBBSD=
AS_IF([test "x$ac_cv_search_strlcat" = "x-lbsd" -o "x$ac_cv_search_strlcpy" = "x-lbsd"],
[LIBBSD=-lbsd
AC_CHECK_HEADERS([bsd/string.h])]
)
AC_SUBST(LIBBSD)
dnl Check for inotify
dnl =================