Use autoconf to check for stdbool.h Committer: Dave Cramer <davecramer@gmail.com>
authorUbuntu <ubuntu@ip-172-30-5-130.ec2.internal>
Mon, 4 Sep 2023 19:57:41 +0000 (19:57 +0000)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Fri, 8 Sep 2023 01:44:04 +0000 (10:44 +0900)
configure.ac
psqlodbc.h

index 6fd91cc1fc62de235db97f5c33818f45ff5cc270..c20ffc400e7c5e6fe465a317e003d01e7001859d 100644 (file)
@@ -22,6 +22,19 @@ AC_CHECK_SIZEOF(void *)
 AC_CHECK_TYPES([long long])
 AC_CHECK_TYPES([signed char])
 AC_CHECK_TYPES([ssize_t])
+
+AC_CHECK_SIZEOF([bool], [],
+[#ifdef HAVE_STDBOOL_H
+#include <stdbool.h>
+#endif])
+
+dnl We use <stdbool.h> if we have it and it declares type bool as having
+dnl size 1.  Otherwise, c.h will fall back to declaring bool as unsigned char.
+if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
+  AC_DEFINE([PG_USE_STDBOOL], 1,
+            [Define to 1 to use <stdbool.h> to define type bool.])
+fi
+
 AC_TYPE_SIZE_T
 
 # Check if "-Wall" is valid
@@ -240,6 +253,7 @@ AC_CHECK_LIB(pq, PQsetSingleRowMode, [],
 AC_CHECK_HEADERS(locale.h sys/time.h uchar.h)
 AC_CHECK_HEADER(libpq-fe.h,,[AC_MSG_ERROR([libpq header not found])])
 AC_HEADER_TIME
+AC_HEADER_STDBOOL
 
 
 # 4. Types(all members were moved to 0.)
index ca8bab55a2855aa62ca64c8f1eea2f0e48bdcce8..1677d0a48723e413be622ece83ee00e7c3056f9c 100644 (file)
@@ -253,6 +253,28 @@ typedef double SDOUBLE;
 #endif /* CALLBACK */
 #endif /* WIN32 */
 
+#ifndef __cplusplus
+
+#ifdef PG_USE_STDBOOL
+#include <stdbool.h>
+#else
+
+#ifndef bool
+typedef unsigned char bool;
+#endif
+
+#ifndef true
+#define true   ((bool) 1)
+#endif
+
+#ifndef false
+#define false  ((bool) 0)
+#endif
+
+#endif                         /* not PG_USE_STDBOOL */
+#endif                         /* not C++ */
+
+
 #ifndef WIN32
 #define stricmp strcasecmp
 #define strnicmp strncasecmp