1 From 8cb5708829df9eacd58e1215ce7a1c135eb912b1 Mon Sep 17 00:00:00 2001
3 Date: Mon, 2 Nov 2020 00:04:14 +0100
4 Subject: [PATCH] src/compat.hpp: fix build with libbsd and strlcpy
6 Don't include bsd/string.h if strlcpy is also defined in string.h to
7 avoid the following build failure on uclibc:
9 In file included from src/compat.hpp:41:0,
10 from src/ipc_address.cpp:31:
11 /tmp/instance-0/output-1/host/mips64el-buildroot-linux-uclibc/sysroot/usr/include/bsd/string.h:44:54: error: declaration of 'size_t strlcpy(char*, const char*, size_t)' has a different exception specifier
12 size_t strlcpy(char *dst, const char *src, size_t siz);
14 In file included from src/compat.hpp:34:0,
15 from src/ipc_address.cpp:31:
16 /tmp/instance-0/output-1/host/mips64el-buildroot-linux-uclibc/sysroot/usr/include/string.h:424:15: error: from previous declaration 'size_t strlcpy(char*, const char*, size_t) throw ()'
17 extern size_t strlcpy(char *__restrict dst, const char *__restrict src,
21 - http://autobuild.buildroot.org/results/51220b1b82774e8f6f6ed8593c58d2e3c31a1531
25 https://github.com/zeromq/libzmq/commit/b2a0842063aaa464ca2d182f9d3fefc6493906d0]
27 CMakeLists.txt | 4 +---
28 configure.ac | 26 ++++++++++++--------------
29 src/compat.hpp | 4 +++-
30 3 files changed, 16 insertions(+), 18 deletions(-)
32 diff --git a/CMakeLists.txt b/CMakeLists.txt
33 index 85747f626..74dd99ae0 100644
36 @@ -250,9 +250,7 @@ if(NOT MSVC)
37 set(ZMQ_HAVE_LIBBSD 1)
40 - if(NOT WITH_LIBBSD OR NOT LIBBSD_FOUND)
41 - check_cxx_symbol_exists(strlcpy string.h ZMQ_HAVE_STRLCPY)
43 + check_cxx_symbol_exists(strlcpy string.h ZMQ_HAVE_STRLCPY)
46 # Select curve encryption library, defaults to tweetnacl To use libsodium instead, use --with-libsodium(must be
47 diff --git a/configure.ac b/configure.ac
48 index 58a78e75e..a7a1609af 100644
51 @@ -812,20 +812,18 @@ if test "x$enable_libbsd" != "xno"; then
55 -if test "x$found_libbsd" != "xyes"; then
56 - AC_MSG_CHECKING([whether strlcpy is available])
59 - [[#include <string.h>]],
60 - [[char buf [100]; size_t bar = strlcpy (buf, "foo", 100); (void)bar; return 0;]])
62 - AC_MSG_RESULT([yes])
63 - AC_DEFINE(ZMQ_HAVE_STRLCPY, [1],
64 - [strlcpy is available])
69 +AC_MSG_CHECKING([whether strlcpy is available])
72 + [[#include <string.h>]],
73 + [[char buf [100]; size_t bar = strlcpy (buf, "foo", 100); (void)bar; return 0;]])
75 + AC_MSG_RESULT([yes])
76 + AC_DEFINE(ZMQ_HAVE_STRLCPY, [1],
77 + [strlcpy is available])
82 # pthread_setname is non-posix, and there are at least 4 different implementations
83 AC_MSG_CHECKING([whether signature of pthread_setname_np() has 1 argument])
84 diff --git a/src/compat.hpp b/src/compat.hpp
85 index 7c7a89275..47744b98e 100644
89 #define strcasecmp _stricmp
90 #define strtok_r strtok_s
92 +#ifndef ZMQ_HAVE_STRLCPY
93 #ifdef ZMQ_HAVE_LIBBSD
94 #include <bsd/string.h>
95 -#elif !defined(ZMQ_HAVE_STRLCPY)
98 strlcpy (char *dest_, const char *src_, const size_t dest_size_)
100 @@ -50,6 +51,7 @@ strlcpy (char *dest_, const char *src_, const size_t dest_size_)
101 return dest_size_ - remain;
105 template <size_t size>
106 static inline int strcpy_s (char (&dest_)[size], const char *const src_)