From cd9763f94f4664df87b93e777bc69b34598f5793 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 25 Jul 2013 18:47:34 -0400 Subject: uhd: strnlen for platforms w/o it --- host/lib/usrp/common/ad9361_ctrl.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'host/lib') diff --git a/host/lib/usrp/common/ad9361_ctrl.cpp b/host/lib/usrp/common/ad9361_ctrl.cpp index eaac3c82f..1afa2fbb7 100644 --- a/host/lib/usrp/common/ad9361_ctrl.cpp +++ b/host/lib/usrp/common/ad9361_ctrl.cpp @@ -24,6 +24,14 @@ #include #include +//! compat strnlen for platforms that dont have it +static size_t my_strnlen(const char *str, size_t max) +{ + const char *end = (const char *)std::memchr((const void *)str, 0, max); + if (end == NULL) return max; + return (size_t)(end - str); +} + using namespace uhd; struct ad9361_ctrl_impl : public ad9361_ctrl @@ -141,7 +149,7 @@ struct ad9361_ctrl_impl : public ad9361_ctrl UHD_ASSERT_THROW(out->sequence == in->sequence); //handle errors - const size_t len = strnlen(out->error_msg, AD9361_TRANSACTION_MAX_ERROR_MSG); + const size_t len = my_strnlen(out->error_msg, AD9361_TRANSACTION_MAX_ERROR_MSG); const std::string error_msg(out->error_msg, len); if (not error_msg.empty()) throw uhd::runtime_error("ad9361 do transaction: " + error_msg); -- cgit v1.2.3