mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-26 06:41:03 +08:00
Problem: internal reimplementation of strlcpy used by default on Linux
Solution: use libbsd by default when available, and the internal implementation only as a fallback, to take advantage of Linux distros maintenance of the string libraries.
This commit is contained in:
parent
246cc77efc
commit
068385c951
@ -138,6 +138,25 @@ if (NOT DISABLE_WS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
find_package(PkgConfig)
|
||||
option(WITH_LIBBSD "Use libbsd instead of builtin strlcpy" ON)
|
||||
if (WITH_LIBBSD)
|
||||
pkg_check_modules(LIBBSD "libbsd")
|
||||
if (LIBBSD_FOUND)
|
||||
message(STATUS "Using libbsd")
|
||||
include_directories(${LIBBSD_INCLUDE_DIRS})
|
||||
set(pkg_config_names_private "${pkg_config_names_private} libbsd")
|
||||
set(ZMQ_HAVE_LIBBSD 1)
|
||||
link_directories(${LIBBSD_LIBRARY_DIRS})
|
||||
set(OPTIONAL_LIBRARIES ${LIBBSD_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
if (NOT WITH_LIBBSD OR NOT LIBBSD_FOUND)
|
||||
check_cxx_symbol_exists(strlcpy string.h ZMQ_HAVE_STRLCPY)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# Select curve encryption library, defaults to tweetnacl
|
||||
# To use libsodium instead, use --with-libsodium(must be installed)
|
||||
@ -460,7 +479,6 @@ if(NOT MSVC)
|
||||
check_cxx_symbol_exists(mkdtemp stdlib.h HAVE_MKDTEMP)
|
||||
check_cxx_symbol_exists(accept4 sys/socket.h HAVE_ACCEPT4)
|
||||
check_cxx_symbol_exists(strnlen string.h HAVE_STRNLEN)
|
||||
check_cxx_symbol_exists(strlcpy string.h ZMQ_HAVE_STRLCPY)
|
||||
else()
|
||||
set(HAVE_STRNLEN 1)
|
||||
endif()
|
||||
@ -661,7 +679,6 @@ else()
|
||||
"Name pkg-config shall use to find openpgm libraries and include paths"
|
||||
FORCE)
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(OPENPGM ${OPENPGM_PKGCONFIG_NAME})
|
||||
|
||||
if(OPENPGM_FOUND)
|
||||
|
12
Makefile.am
12
Makefile.am
@ -344,11 +344,11 @@ if HAVE_VSCRIPT_COMPLEX
|
||||
src_libzmq_la_LDFLAGS += $(VSCRIPT_LDFLAGS),$(srcdir)/src/libzmq.vers
|
||||
endif
|
||||
|
||||
src_libzmq_la_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) $(LIBUNWIND_CFLAGS)
|
||||
src_libzmq_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) $(LIBUNWIND_CFLAGS)
|
||||
src_libzmq_la_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) $(LIBUNWIND_CFLAGS) $(LIBBSD_CFLAGS)
|
||||
src_libzmq_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) $(LIBUNWIND_CFLAGS) $(LIBBSD_CFLAGS)
|
||||
src_libzmq_la_CXXFLAGS = @LIBZMQ_EXTRA_CXXFLAGS@ $(CODE_COVERAGE_CXXFLAGS) \
|
||||
$(LIBUNWIND_CFLAGS)
|
||||
src_libzmq_la_LIBADD = $(CODE_COVERAGE_LDFLAGS) $(LIBUNWIND_LIBS)
|
||||
$(LIBUNWIND_CFLAGS) $(LIBBSD_CFLAGS)
|
||||
src_libzmq_la_LIBADD = $(CODE_COVERAGE_LDFLAGS) $(LIBUNWIND_LIBS) $(LIBBSD_LIBS)
|
||||
|
||||
if USE_NSS
|
||||
src_libzmq_la_CPPFLAGS += ${NSS3_CFLAGS}
|
||||
@ -841,10 +841,10 @@ tests_test_security_curve_SOURCES += \
|
||||
endif
|
||||
|
||||
tests_test_security_curve_LDADD = \
|
||||
${TESTUTIL_LIBS} src/libzmq.la $(LIBUNWIND_LIBS)
|
||||
${TESTUTIL_LIBS} src/libzmq.la $(LIBUNWIND_LIBS) $(LIBBSD_LIBS)
|
||||
tests_test_security_curve_CPPFLAGS = \
|
||||
${TESTUTIL_CPPFLAGS} \
|
||||
${LIBUNWIND_CFLAGS}
|
||||
${LIBUNWIND_CFLAGS} ${LIBBSD_CFLAGS}
|
||||
|
||||
if USE_LIBSODIUM
|
||||
tests_test_security_curve_CPPFLAGS += \
|
||||
|
@ -52,6 +52,7 @@
|
||||
#cmakedefine HAVE_ACCEPT4
|
||||
#cmakedefine HAVE_STRNLEN
|
||||
#cmakedefine ZMQ_HAVE_STRLCPY
|
||||
#cmakedefine ZMQ_HAVE_LIBBSD
|
||||
|
||||
#cmakedefine ZMQ_HAVE_IPC
|
||||
|
||||
|
51
configure.ac
51
configure.ac
@ -751,19 +751,44 @@ AC_COMPILE_IFELSE(
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
|
||||
# string.h doesn't seem to be included by default in Fedora 30
|
||||
AC_MSG_CHECKING([whether strlcpy is available])
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <string.h>]],
|
||||
[[char buf [100]; size_t bar = strlcpy (buf, "foo", 100); (void)bar; return 0;]])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE(ZMQ_HAVE_STRLCPY, [1],
|
||||
[strlcpy is available])
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
AC_ARG_ENABLE([libbsd],
|
||||
[AS_HELP_STRING([--enable-libbsd],
|
||||
[enable libbsd [default=auto]])],
|
||||
[enable_libbsd=$enableval],
|
||||
[enable_libbsd="auto"])
|
||||
|
||||
if test "x$enable_libbsd" != "xno"; then
|
||||
PKG_CHECK_MODULES(LIBBSD, [libbsd],
|
||||
[
|
||||
AC_DEFINE(ZMQ_HAVE_LIBBSD, 1, [The libbsd library is to be used])
|
||||
AC_SUBST([LIBBSD_CFLAGS])
|
||||
AC_SUBST([LIBBSD_LIBS])
|
||||
PKGCFG_NAMES_PRIVATE="$PKGCFG_NAMES_PRIVATE libbsd"
|
||||
found_libbsd="yes"
|
||||
],
|
||||
[
|
||||
found_libbsd="no"
|
||||
if test "x$enable_libbsd" = "xyes"; then
|
||||
AC_MSG_ERROR([Cannot find libbsd])
|
||||
else
|
||||
AC_MSG_WARN([Cannot find libbsd])
|
||||
fi
|
||||
])
|
||||
fi
|
||||
if test "x$found_libbsd" != "xyes"; then
|
||||
AC_MSG_CHECKING([whether strlcpy is available])
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[#include <string.h>]],
|
||||
[[char buf [100]; size_t bar = strlcpy (buf, "foo", 100); (void)bar; return 0;]])
|
||||
],[
|
||||
AC_MSG_RESULT([yes])
|
||||
AC_DEFINE(ZMQ_HAVE_STRLCPY, [1],
|
||||
[strlcpy is available])
|
||||
],[
|
||||
AC_MSG_RESULT([no])
|
||||
])
|
||||
fi
|
||||
|
||||
# pthread_setname is non-posix, and there are at least 4 different implementations
|
||||
AC_MSG_CHECKING([whether signature of pthread_setname_np() has 1 argument])
|
||||
|
@ -11,6 +11,7 @@ Build-Depends: debhelper (>= 9),
|
||||
libunwind-dev | libunwind8-dev | libunwind7-dev,
|
||||
libnss3-dev,
|
||||
libgnutls28-dev | libgnutls-dev,
|
||||
libbsd-dev,
|
||||
pkg-config,
|
||||
asciidoc-base | asciidoc, xmlto,
|
||||
Standards-Version: 3.9.8
|
||||
@ -42,6 +43,7 @@ Depends: libzmq5 (= ${binary:Version}), ${misc:Depends},
|
||||
libunwind-dev | libunwind8-dev | libunwind7-dev,
|
||||
libnss3-dev,
|
||||
libgnutls28-dev | libgnutls-dev,
|
||||
libbsd-dev,
|
||||
Conflicts: libzmq-dev, libzmq5-dev
|
||||
Replaces: libzmq5-dev
|
||||
Provides: libzmq5-dev
|
||||
|
@ -6,7 +6,7 @@ Version: 4.3.3
|
||||
Maintainer: libzmq Developers <zeromq-dev@lists.zeromq.org>
|
||||
Homepage: http://www.zeromq.org/
|
||||
Standards-Version: 3.9.8
|
||||
Build-Depends: debhelper (>= 9), dh-autoreconf, libkrb5-dev, libpgm-dev, libnorm-dev, libsodium-dev, libunwind-dev | libunwind8-dev | libunwind7-dev, libnss3-dev, libgnutls28-dev | libgnutls-dev, pkg-config, asciidoc-base | asciidoc, xmlto
|
||||
Build-Depends: debhelper (>= 9), dh-autoreconf, libkrb5-dev, libpgm-dev, libnorm-dev, libsodium-dev, libunwind-dev | libunwind8-dev | libunwind7-dev, libnss3-dev, libgnutls28-dev | libgnutls-dev, libbsd-dev, pkg-config, asciidoc-base | asciidoc, xmlto
|
||||
Package-List:
|
||||
libzmq3-dev deb libdevel optional arch=any
|
||||
libzmq5 deb libs optional arch=any
|
||||
|
@ -19,7 +19,7 @@ URL: http://www.zeromq.org/
|
||||
Source: http://download.zeromq.org/%{name}-%{version}.tar.gz
|
||||
Prefix: %{_prefix}
|
||||
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root
|
||||
BuildRequires: autoconf automake libtool glib2-devel
|
||||
BuildRequires: autoconf automake libtool glib2-devel libbsd-devel
|
||||
%if ! (0%{?fedora} > 12 || 0%{?rhel} > 5)
|
||||
BuildRequires: e2fsprogs-devel
|
||||
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
|
||||
|
@ -74,7 +74,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
#define strcasecmp _stricmp
|
||||
#else
|
||||
#ifndef ZMQ_HAVE_STRLCPY
|
||||
#ifdef ZMQ_HAVE_LIBBSD
|
||||
#include <bsd/string.h>
|
||||
#elif !defined(ZMQ_HAVE_STRLCPY)
|
||||
static size_t strlcpy (char *dest_, const char *src_, const size_t dest_size_)
|
||||
{
|
||||
size_t remain = dest_size_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user