From 93aba2cb8c8e5bd481f1d9597a7db019efc05d6e Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Mon, 30 May 2016 12:52:48 +0100
Subject: [PATCH] FreeBSD fixes from Ganael LAPLANCHE

---
 simgear/io/DNSClient.hxx  |  2 ++
 simgear/misc/sha1.c       | 17 ++++++++---------
 simgear/misc/strutils.cxx |  2 +-
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/simgear/io/DNSClient.hxx b/simgear/io/DNSClient.hxx
index b23e6dc5..7cabd41c 100644
--- a/simgear/io/DNSClient.hxx
+++ b/simgear/io/DNSClient.hxx
@@ -27,6 +27,8 @@
 #include <memory> // for std::auto_ptr
 #include <string>
 #include <vector>
+#include <ctime> // for time_t
+
 #include <simgear/structure/SGReferenced.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 
diff --git a/simgear/misc/sha1.c b/simgear/misc/sha1.c
index 3fce9047..d4221f17 100644
--- a/simgear/misc/sha1.c
+++ b/simgear/misc/sha1.c
@@ -6,25 +6,24 @@
 //#include <stdint.h>
 //#include <string.h>
 
+#if defined(__FreeBSD__) || defined(__APPLE__)
+# include <machine/endian.h>
+#elif !defined(_WIN32)
+# include <endian.h>
+#endif
 
 #ifdef __BIG_ENDIAN__
 # define SHA_BIG_ENDIAN
-#elif defined __LITTLE_ENDIAN__
-/* override */
 #elif defined __BYTE_ORDER
 # if __BYTE_ORDER__ ==  __ORDER_BIG_ENDIAN__
 # define SHA_BIG_ENDIAN
 # endif
-#elif defined _WIN32
-/* assume little-endian, there is no endian.h on MSVC */
-#else // ! defined __LITTLE_ENDIAN__
-# include <endian.h> // machine/endian.h
-# if __BYTE_ORDER__ ==  __ORDER_BIG_ENDIAN__
-#  define SHA_BIG_ENDIAN
+#elif defined BYTE_ORDER
+# if BYTE_ORDER == BIG_ENDIAN
+# define SHA_BIG_ENDIAN
 # endif
 #endif
 
-
 /* code */
 #define SHA1_K0  0x5a827999
 #define SHA1_K20 0x6ed9eba1
diff --git a/simgear/misc/strutils.cxx b/simgear/misc/strutils.cxx
index fd3b148e..867005a9 100644
--- a/simgear/misc/strutils.cxx
+++ b/simgear/misc/strutils.cxx
@@ -615,7 +615,7 @@ std::string error_string(int errnum)
   retcode = strerror_s(buf, sizeof(buf), errnum);
 #elif defined(_GNU_SOURCE)
   return std::string(strerror_r(errnum, buf, sizeof(buf)));
-#elif (_POSIX_C_SOURCE >= 200112L) || defined(SG_MAC)
+#elif (_POSIX_C_SOURCE >= 200112L) || defined(SG_MAC) || defined(__FreeBSD__)
   int retcode;
   // POSIX.1-2001 and POSIX.1-2008
   retcode = strerror_r(errnum, buf, sizeof(buf));
-- 
2.39.5