diff --git a/WINGs/Makefile.am b/WINGs/Makefile.am index be417dbf..b4b2966c 100644 --- a/WINGs/Makefile.am +++ b/WINGs/Makefile.am @@ -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 diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index 61b19ada..a118f14f 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -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 */ diff --git a/WINGs/string.c b/WINGs/string.c index abf8dcd8..c86970f7 100644 --- a/WINGs/string.c +++ b/WINGs/string.c @@ -4,6 +4,9 @@ #include #include #include +#ifdef HAVE_BSD_STRING_H +#include +#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; diff --git a/configure.ac b/configure.ac index e26dab76..a37f545e 100644 --- a/configure.ac +++ b/configure.ac @@ -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 =================