]> granicus.if.org Git - curl/commitdiff
setup_once: use enum type for 'bool' on non-C99 platforms
authorTor Arntsen <tor@spacetec.no>
Thu, 27 May 2010 14:58:15 +0000 (16:58 +0200)
committerKamil Dudka <kdudka@redhat.com>
Thu, 27 May 2010 16:15:17 +0000 (18:15 +0200)
An enum will catch non-bool assignments to bool on platforms with
a strict compiler, e.g MIPSPro.

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
CHANGES
lib/setup_once.h

diff --git a/CHANGES b/CHANGES
index a62ca57aebada915d946a4b553ddac58a9527cf9..efea35ca5c4fefa2be3711fbad0494c7a1f13a93 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,13 +6,17 @@
 
                                   Changelog
 
+Kamil Dudka (27 May 2010)
+- Tor Arntsen changed the alternative definition of bool to use enum instead
+  of unsigned char.
+
+Daniel Stenberg (25 May 2010)
 - Julien Chaffraix fixed the warning seen when compiling lib/rtmp.c: one
   unused variables, several unused arguments and some missing #include.
 
 - Julien Chaffraix fixed 2 OOM errors: a missing NULL-check in
   lib/http_negociate.c and a potential NULL dereferencing in lib/splay.c
 
-Daniel Stenberg (25 May 2010)
 - Howard Chu brought a patch that makes the LDAP code much cleaner, nicer and
   in general being a better libcurl citizen. If a new enough OpenLDAP version
   is detect, the new and shiny lib/openldap.c code is then used instead of the
index cdc0ecf6479a9a1125969ea6d2da232f04091303..fff115b8fa66fcd3e3f34f0f82ea18f82905154f 100644 (file)
@@ -261,24 +261,42 @@ struct timeval {
 
 
 /*
- * Typedef to 'unsigned char' if bool is not an available 'typedefed' type.
+ * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms.
+ * On non-C99 platforms there's no bool, so define an enum for that.
+ * On C99 platforms 'false' and 'true' also exist. Enum uses a
+ * global namespace though, so use bool_false and bool_true.
  */
 
 #ifndef HAVE_BOOL_T
-typedef unsigned char bool;
-#define HAVE_BOOL_T
+  typedef enum {
+      bool_false = 0,
+      bool_true  = 1
+  } bool;
+
+/*
+ * Use a define to let 'true' and 'false' use those enums.  There
+ * are currently no use of true and false in libcurl proper, but
+ * there are some in the examples. This will cater for any later
+ * code happening to use true and false.
+ */
+#  define false bool_false
+#  define true  bool_true
+#  define HAVE_BOOL_T
 #endif
 
 
 /*
- * Default definition of uppercase TRUE and FALSE.
+ * Redefine TRUE and FALSE too, to catch current use. With this
+ * change, 'bool found = 1' will give a warning on MIPSPro, but
+ * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro,
+ * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too.
  */
 
 #ifndef TRUE
-#define TRUE 1
+#define TRUE true
 #endif
 #ifndef FALSE
-#define FALSE 0
+#define FALSE false
 #endif