aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2013-07-25 18:47:34 -0400
committerJosh Blum <josh@joshknows.com>2013-07-25 18:47:34 -0400
commitcd9763f94f4664df87b93e777bc69b34598f5793 (patch)
treedd396659d0977c26158d81b3c135f7a6076d56d1 /host/lib
parentd3ce83e1042267cf5c3802005232e77ad1613f69 (diff)
downloaduhd-cd9763f94f4664df87b93e777bc69b34598f5793.tar.gz
uhd-cd9763f94f4664df87b93e777bc69b34598f5793.tar.bz2
uhd-cd9763f94f4664df87b93e777bc69b34598f5793.zip
uhd: strnlen for platforms w/o it
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/usrp/common/ad9361_ctrl.cpp10
1 files changed, 9 insertions, 1 deletions
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 <boost/format.hpp>
#include <cstring>
+//! 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);