Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 24869322da6262588d40eb6b12427feed929aede 1 parent e24110a
Trond Norbye authored dustin committed
Showing with 50 additions and 8 deletions.
  1. +49 −1 configure.ac
  2. +0 −2  memcached.h
  3. +0 −2  protocol_binary.h
  4. +1 −3 testapp.c
View
50 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);
])
View
2  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>
View
2  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
View
4 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"
Please sign in to comment.
Something went wrong with that request. Please try again.