From 5552c447536163774eb3eca67cfe1a72dc39c29b Mon Sep 17 00:00:00 2001
From: Nicolay Korslund <korslund@gmail.com>
Date: Tue, 7 Sep 2010 10:40:00 +0200
Subject: [PATCH] Cleaned up strnlen in esm_reader. Added -Werror switch to
 g++.

---
 CMakeLists.txt                |  2 +-
 components/esm/esm_reader.hpp | 12 +-----------
 libs/platform/string.h        | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 12 deletions(-)
 create mode 100644 libs/platform/string.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index beed45084..a1cc058ce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -247,7 +247,7 @@ endif (APPLE)
 
 # Compiler settings
 if (CMAKE_COMPILER_IS_GNUCC)
-    add_definitions (-Wall)
+    add_definitions (-Wall -Werror)
 endif (CMAKE_COMPILER_IS_GNUCC)
 
 # Apple bundling
diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp
index 76df4b5dc..64e0861b5 100644
--- a/components/esm/esm_reader.hpp
+++ b/components/esm/esm_reader.hpp
@@ -3,10 +3,10 @@
 
 #include <string>
 #include <libs/platform/stdint.h>
+#include <libs/platform/string.h>
 #include <assert.h>
 #include <vector>
 #include <sstream>
-#include <string.h>
 #include <stdexcept>
 
 #include <libs/mangle/stream/stream.hpp>
@@ -15,16 +15,6 @@
 
 #include <components/to_utf8/to_utf8.hpp>
 
-#ifdef __APPLE__
-// need our own implementation of strnlen
-static size_t strnlen(const char *s, size_t n)
-{
-  const char *p = (const char *)memchr(s, 0, n);
-  return(p ? p-s : n);
-}
-
-#endif
-
 namespace ESM {
 
 enum Version
diff --git a/libs/platform/string.h b/libs/platform/string.h
new file mode 100644
index 000000000..dc25279fe
--- /dev/null
+++ b/libs/platform/string.h
@@ -0,0 +1,14 @@
+// Wrapper for string.h on Mac
+#ifndef _STRING_WRAPPER_H
+#define _STRING_WRAPPER_H
+
+#include <string.h>
+#ifdef __APPLE__
+// need our own implementation of strnlen
+static size_t strnlen(const char *s, size_t n)
+{
+  const char *p = (const char *)memchr(s, 0, n);
+  return(p ? p-s : n);
+}
+#endif
+#endif