0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-14 01:37:56 +08:00

Problem: strnlen may not be available

Solution: Provide an implementation
This commit is contained in:
Jacques Germishuys 2019-03-18 10:27:45 +00:00
parent bd6fa4bbb3
commit b26542bbfc
4 changed files with 18 additions and 1 deletions

View File

@ -417,6 +417,10 @@ if(NOT MSVC)
set(CMAKE_REQUIRED_INCLUDES sys/socket.h)
check_function_exists(accept4 HAVE_ACCEPT4)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_INCLUDES string.h)
check_function_exists(strnlen HAVE_STRNLEN)
set(CMAKE_REQUIRED_INCLUDES)
endif()
add_definitions(-D_REENTRANT -D_THREAD_SAFE)

View File

@ -49,6 +49,7 @@
#cmakedefine ZMQ_HAVE_PTHREAD_SETNAME_3
#cmakedefine ZMQ_HAVE_PTHREAD_SET_NAME
#cmakedefine HAVE_ACCEPT4
#cmakedefine HAVE_STRNLEN
#cmakedefine ZMQ_HAVE_OPENPGM
#cmakedefine ZMQ_MAKE_VALGRIND_HAPPY

View File

@ -675,7 +675,7 @@ AC_LANG_POP([C++])
# Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(perror gettimeofday clock_gettime memset socket getifaddrs freeifaddrs fork mkdtemp accept4)
AC_CHECK_FUNCS(perror gettimeofday clock_gettime memset socket getifaddrs freeifaddrs fork mkdtemp accept4 strnlen)
AC_CHECK_HEADERS([alloca.h])
# pthread_setname is non-posix, and there are at least 4 different implementations

View File

@ -37,6 +37,18 @@
#include <string>
#ifndef HAVE_STRNLEN
static size_t strnlen (const char *s, size_t len)
{
for (size_t i = 0; i < len; i++) {
if (s[i] == '\0')
return i + 1;
}
return len;
}
#endif
zmq::ipc_address_t::ipc_address_t ()
{
memset (&_address, 0, sizeof _address);