From 13da6d288e94a2331f2efde2bd850202ee9286c0 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 4 Sep 2023 19:57:41 +0000 Subject: [PATCH] Use autoconf to check for stdbool.h Committer: Dave Cramer --- configure.ac | 14 ++++++++++++++ psqlodbc.h | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/configure.ac b/configure.ac index 6fd91cc..c20ffc4 100644 --- a/configure.ac +++ b/configure.ac @@ -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 +#endif]) + +dnl We use 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 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.) diff --git a/psqlodbc.h b/psqlodbc.h index ca8bab5..1677d0a 100644 --- a/psqlodbc.h +++ b/psqlodbc.h @@ -253,6 +253,28 @@ typedef double SDOUBLE; #endif /* CALLBACK */ #endif /* WIN32 */ +#ifndef __cplusplus + +#ifdef PG_USE_STDBOOL +#include +#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 -- 2.34.1