Skip to content

Commit

Permalink
Merge pull request #3452 from jacquesg/strnlen
Browse files Browse the repository at this point in the history
Problem: strnlen may not be available
  • Loading branch information
bluca authored Mar 18, 2019
2 parents c1d2e71 + b26542b commit 17c47da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions builds/cmake/platform.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/ipc_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 17c47da

Please sign in to comment.