Skip to content

Commit 70f9e33

Browse files
committed
Merge pull request #5340
c8ed613 Include missing config/bitcoin-config.h. (Pavel Janík) 494f6e7 Check for strnlen and provide it if it is not found. (Pavel Janík)
2 parents ac0b239 + c8ed613 commit 70f9e33

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#ifndef BITCOIN_COMPAT_H
77
#define BITCOIN_COMPAT_H
88

9+
#if defined(HAVE_CONFIG_H)
10+
#include "config/bitcoin-config.h"
11+
#endif
12+
913
#ifdef WIN32
1014
#ifdef _WIN32_WINNT
1115
#undef _WIN32_WINNT
@@ -84,4 +88,8 @@ typedef u_int SOCKET;
8488
#define THREAD_PRIORITY_ABOVE_NORMAL (-2)
8589
#endif
8690

91+
#if HAVE_DECL_STRNLEN == 0
92+
size_t strnlen( const char *start, size_t max_len);
93+
#endif // HAVE_DECL_STRNLEN
94+
8795
#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)