From 29a0aee44c0955d4344598e9ca5eefe2b10bb8ba Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 24 Aug 2015 17:51:39 -0400 Subject: [PATCH] Implement strnlen on OS X <= 10.6 Fixes #182 --- library/LuaTypes.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp index 0904ff8f9..fa9445a81 100644 --- a/library/LuaTypes.cpp +++ b/library/LuaTypes.cpp @@ -49,6 +49,16 @@ distribution. using namespace DFHack; using namespace DFHack::LuaWrapper; +#ifdef _DARWIN +#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_6 +size_t strnlen (const char *str, size_t max) +{ + const char *end = (const char*)memchr(str, 0, max); + return end ? (size_t)(end - str) : max; +} +#endif +#endif + /************************************** * Identity object read/write methods * **************************************/