From c592f1dd795750f36ade845fcd6dcea8d5eaf126 Mon Sep 17 00:00:00 2001
From: Timothy Gu <timothygu99@gmail.com>
Date: Sun, 21 Dec 2014 17:28:56 +0000
Subject: Use stdbool.h and stdint.h if they are present

Fixes building on some exotic platforms like Haiku. Plus it's more
correct any way.

Signed-off-by: Timothy Gu <timothygu99@gmail.com>

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a24952..b638184 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -106,7 +106,9 @@ if (WITH_AVFFT)
 endif ()
 
 check_function_exists (lrint HAVE_LRINT)
-check_include_files (fenv.h HAVE_FENV_H)
+check_include_files (fenv.h    HAVE_FENV_H)
+check_include_files (stdbool.h HAVE_STDBOOL_H)
+check_include_files (stdint.h  HAVE_STDINT_H)
 test_big_endian (WORDS_BIGENDIAN)
 
 macro (make_exist)
diff --git a/examples/examples-common.h b/examples/examples-common.h
index 585fac3..1474cb5 100644
--- a/examples/examples-common.h
+++ b/examples/examples-common.h
@@ -12,6 +12,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "../soxr-config.h"
+
 #ifdef _WIN32
   /* Work-around for broken file-I/O on MS-Windows: */
   #include <io.h>
@@ -25,18 +27,6 @@
   #define USE_STD_STDIO
 #endif
 
-#undef int16_t
-#define int16_t short
-
-#undef int32_t
-#if LONG_MAX > 2147483647L
-  #define int32_t int
-#elif LONG_MAX < 2147483647L
-  #error this programme requires that 'long int' has at least 32-bits
-#else
-  #define int32_t long
-#endif
-
 #undef min
 #undef max
 #define min(x,y) ((x)<(y)?(x):(y))
diff --git a/soxr-config.h.in b/soxr-config.h.in
index 227bcfd..d93987b 100644
--- a/soxr-config.h.in
+++ b/soxr-config.h.in
@@ -10,17 +10,23 @@
 #define HAVE_SIMD             @HAVE_SIMD@
 #define HAVE_FENV_H           @HAVE_FENV_H@
 #define HAVE_LRINT            @HAVE_LRINT@
+#define HAVE_STDBOOL_H        @HAVE_STDBOOL_H@
+#define HAVE_STDINT_H         @HAVE_STDINT_H@
 #define WORDS_BIGENDIAN       @WORDS_BIGENDIAN@
 
-#include <limits.h>
-
+#if !HAVE_STDBOOL_H
 #undef bool
 #undef false
 #undef true
 #define bool int
 #define false 0
 #define true 1
+#else /* HAVE_STDBOOL_H */
+#include <stdbool.h>
+#endif
 
+#if !HAVE_STDINT_H
+#include <limits.h>
 #undef int16_t
 #undef int32_t
 #undef int64_t
@@ -42,5 +48,7 @@
 #endif
 #define uint32_t unsigned int32_t
 #define uint64_t unsigned int64_t
-
+#else /* HAVE_STDINT_H */
+#include <stdint.h>
+#endif
 #endif
-- 
1.8.3.4

