summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrond Norbye <Trond.Norbye@sun.com>2009-11-04 11:40:56 +0100
committerDustin Sallings <dustin@spy.net>2009-11-04 10:29:24 -0800
commit24869322da6262588d40eb6b12427feed929aede (patch)
tree4dd10ed1302c3deb4b63498c35a0239b4b52c3d6
parente24110a42dcf036f25e38211198c8a1f8f9590da (diff)
downloadmemcached-24869322da6262588d40eb6b12427feed929aede.tar.gz
Allow semi-broken C99 compilers to compile memcached
Some C compilers understand the syntax we use in memcached, but do not ship stdbool.h or stdint.h. According to C99 inttypes.h contains the formatting macros we use (PRInn) and is supposed to include stdint.h. This patch tries to detect stdbool.h and inttypes.h and tries to include them from config.h
-rw-r--r--configure.ac50
-rw-r--r--memcached.h2
-rw-r--r--protocol_binary.h2
-rw-r--r--testapp.c4
4 files changed, 50 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index 670dee4..6298d2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -255,6 +255,52 @@ AC_SEARCH_LIBS(umem_cache_create, umem)
AC_SEARCH_LIBS(gethugepagesizes, hugetlbfs)
AC_HEADER_STDBOOL
+AH_BOTTOM([#if HAVE_STDBOOL_H
+#include <stdbool.h>
+#else
+#define bool char
+#define false 0
+#define true 1
+#endif ])
+
+AC_CHECK_HEADERS([inttypes.h])
+AH_BOTTOM([#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+])
+
+dnl **********************************************************************
+dnl DETECT_UINT64_SUPPORT
+dnl
+dnl check if we can use a uint64_t
+dnl **********************************************************************
+AC_DEFUN([AC_C_DETECT_UINT64_SUPPORT],
+[
+ AC_CACHE_CHECK([for print macros for integers (C99 section 7.8.1)],
+ [ac_cv_c_uint64_support],
+ [AC_TRY_COMPILE(
+ [
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#include <stdio.h>
+ ], [
+ uint64_t val = 0;
+ fprintf(stderr, "%" PRIu64 "\n", val);
+ ],
+ [ ac_cv_c_uint64_support=yes ],
+ [ ac_cv_c_uint64_support=no ])
+ ])
+])
+
+AC_C_DETECT_UINT64_SUPPORT
+AS_IF([test "x$ac_cv_c_uint64_support" = "xno"],
+ [AC_MSG_WARN([
+
+Failed to use print macros (PRIu) as defined in C99 section 7.8.1.
+
+])])
+
AC_C_CONST
dnl From licq: Copyright (c) 2000 Dirk Mueller
@@ -314,7 +360,9 @@ AC_DEFUN([AC_C_HTONLL],
AC_LANG_PROGRAM([
#include <sys/types.h>
#include <netinet/in.h>
-#include <inttypes.h>
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h> */
+#endif
], [
return htonll(0);
])
diff --git a/memcached.h b/memcached.h
index 9b49012..4f07d7c 100644
--- a/memcached.h
+++ b/memcached.h
@@ -15,8 +15,6 @@
#include <netinet/in.h>
#include <event.h>
#include <netdb.h>
-#include <stdbool.h>
-#include <stdint.h>
#include <pthread.h>
#include <unistd.h>
diff --git a/protocol_binary.h b/protocol_binary.h
index e132f00..aa5dcc4 100644
--- a/protocol_binary.h
+++ b/protocol_binary.h
@@ -35,8 +35,6 @@
#ifndef PROTOCOL_BINARY_H
#define PROTOCOL_BINARY_H
-#include <stdint.h>
-
/**
* This file contains definitions of the constants and packet formats
* defined in the binary specification. Please note that you _MUST_ remember
diff --git a/testapp.c b/testapp.c
index b3f6c3f..64a9e02 100644
--- a/testapp.c
+++ b/testapp.c
@@ -14,16 +14,14 @@
#include <errno.h>
#include <assert.h>
#include <string.h>
-#include <inttypes.h>
-#include <stdbool.h>
#include <unistd.h>
#include <netinet/in.h>
#include <fcntl.h>
-#include "protocol_binary.h"
#include "config.h"
#include "cache.h"
#include "util.h"
+#include "protocol_binary.h"
#define TMP_TEMPLATE "/tmp/test_file.XXXXXXX"