Skip to content

Commit 494f6e7

Browse files
committed
Check for strnlen and provide it if it is not found.
1 parent c24d075 commit 494f6e7

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ AC_CHECK_HEADERS([endian.h stdio.h stdlib.h unistd.h strings.h sys/types.h sys/s
421421
AC_SEARCH_LIBS([getaddrinfo_a], [anl], [AC_DEFINE(HAVE_GETADDRINFO_A, 1, [Define this symbol if you have getaddrinfo_a])])
422422
AC_SEARCH_LIBS([inet_pton], [nsl resolv], [AC_DEFINE(HAVE_INET_PTON, 1, [Define this symbol if you have inet_pton])])
423423

424+
AC_CHECK_DECLS([strnlen])
425+
424426
AC_CHECK_DECLS([le32toh, le64toh, htole32, htole64, be32toh, be64toh, htobe32, htobe64],,,
425427
[#if HAVE_ENDIAN_H
426428
#include <endian.h>

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ libbitcoin_common_a_SOURCES = \
251251
# backward-compatibility objects and their sanity checks are linked.
252252
libbitcoin_util_a_CPPFLAGS = $(BITCOIN_INCLUDES)
253253
libbitcoin_util_a_SOURCES = \
254+
compat/strnlen.cpp \
254255
compat/glibc_sanity.cpp \
255256
compat/glibcxx_sanity.cpp \
256257
chainparamsbase.cpp \

src/compat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,8 @@ typedef u_int SOCKET;
8484
#define THREAD_PRIORITY_ABOVE_NORMAL (-2)
8585
#endif
8686

87+
#if HAVE_DECL_STRNLEN == 0
88+
size_t strnlen( const char *start, size_t max_len);
89+
#endif // HAVE_DECL_STRNLEN
90+
8791
#endif // BITCOIN_COMPAT_H

src/compat/strnlen.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2009-2014 The Bitcoin developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#if defined(HAVE_CONFIG_H)
6+
#include "config/bitcoin-config.h"
7+
#endif
8+
9+
#include <cstring>
10+
11+
#if HAVE_DECL_STRNLEN == 0
12+
size_t strnlen( const char *start, size_t max_len)
13+
{
14+
const char *end = (const char *)memchr(start, '\0', max_len);
15+
16+
return end ? (size_t)(end - start) : max_len;
17+
}
18+
#endif // HAVE_DECL_STRNLEN

0 commit comments

Comments
 (0)