From e37fcfbad830c9bfe7375847f230f69899360444 Mon Sep 17 00:00:00 2001
From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Date: Tue, 20 Dec 2016 12:41:21 -0800
Subject: [PATCH 4/6] Fix build issues pre-Lion due to missing a strnlen
 definition

https://trac.macports.org/ticket/51520
https://llvm.org/bugs/show_bug.cgi?id=27714

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
---
 lib/ObjectYAML/MachOYAML.cpp  | 14 ++++++++++++++
 tools/obj2yaml/macho2yaml.cpp | 16 +++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git llvm_master/lib/ObjectYAML/MachOYAML.cpp macports_master/lib/ObjectYAML/MachOYAML.cpp
index d12f12cf443..57464def3da 100644
--- llvm_master/lib/ObjectYAML/MachOYAML.cpp
+++ macports_master/lib/ObjectYAML/MachOYAML.cpp
@@ -21,6 +21,20 @@
 #include <cstdint>
 #include <cstring>
 
+#ifdef __APPLE__
+#include <Availability.h>
+#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+static size_t strnlen(const char *s, size_t maxlen) {
+  size_t l = 0;
+  while (l < maxlen && *s) {
+    l++;
+    s++;
+  }
+  return l;
+}
+#endif
+#endif
+
 namespace llvm {
 
 MachOYAML::LoadCommand::~LoadCommand() = default;
diff --git llvm_master/tools/obj2yaml/macho2yaml.cpp macports_master/tools/obj2yaml/macho2yaml.cpp
index 63e81686632..3c9b0cf8748 100644
--- llvm_master/tools/obj2yaml/macho2yaml.cpp
+++ macports_master/tools/obj2yaml/macho2yaml.cpp
@@ -14,7 +14,21 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/LEB128.h"
 
-#include <string.h> // for memcpy
+#include <string.h> // for memcpy abd strnlen
+
+#ifdef __APPLE__
+#include <Availability.h>
+#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+static size_t strnlen(const char *s, size_t maxlen) {
+  size_t l = 0;
+  while (l < maxlen && *s) {
+    l++;
+    s++;
+  }
+  return l;
+}
+#endif
+#endif
 
 using namespace llvm;
 
-- 
2.21.0 (Apple Git-120)

