From 8220549315f342f5f0321293e041be6c9bc54dbb Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Sat, 20 Jul 2013 18:41:40 -0700 Subject: [PATCH] inttypes: detect and define missing integer types Working around missing integer types is pretty easy. For example, the __u32 family are Linux-specific types, and using these in Ceph internally is fine because we can typedef them. Signed-off-by: Noah Watkins --- configure.ac | 8 ++++++++ src/crush/builder.c | 2 ++ src/crush/crush.c | 1 + src/crush/mapper.c | 1 + src/include/int_types.h | 37 ++++++++++++++++++++++++++++++------- src/include/linux_fiemap.h | 2 ++ 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 8ed663dc1b83..fde34ee05abb 100644 --- a/configure.ac +++ b/configure.ac @@ -676,6 +676,14 @@ AC_CHECK_FUNC([pthread_spin_init], LIBS="$saved_LIBS" CFLAGS="$saved_CFLAGS" +AC_CHECK_TYPES([int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, + int64_t, uint64_t]) + +dnl check for Linux types +AC_CHECK_HEADERS([linux/types.h]) +AC_CHECK_TYPES([__u8, __s8, __u16, __s16, __u32, __s32, __u64, __s64, __le16, + __be16, __le32, __be32, __le64, __be64], [], [], [[#include ]]) + # Checks for typedefs, structures, and compiler characteristics. #AC_HEADER_STDBOOL #AC_C_CONST diff --git a/src/crush/builder.c b/src/crush/builder.c index 9bfde0bd8e25..c524cfcf1e2e 100644 --- a/src/crush/builder.c +++ b/src/crush/builder.c @@ -6,6 +6,8 @@ #include #include +#include "include/int_types.h" + #include "builder.h" #include "hash.h" diff --git a/src/crush/crush.c b/src/crush/crush.c index ec7072d24c88..519793a02166 100644 --- a/src/crush/crush.c +++ b/src/crush/crush.c @@ -6,6 +6,7 @@ # include # define kfree(x) do { if (x) free(x); } while (0) # define BUG_ON(x) assert(!(x)) +# include "include/int_types.h" #endif #include "crush.h" diff --git a/src/crush/mapper.c b/src/crush/mapper.c index 76c3b62d0da8..9baa231d12b7 100644 --- a/src/crush/mapper.c +++ b/src/crush/mapper.c @@ -17,6 +17,7 @@ # define kmalloc(x, f) malloc(x) # define kfree(x) free(x) /*# define DEBUG_INDEP*/ +# include "include/int_types.h" #endif #include "crush.h" diff --git a/src/include/int_types.h b/src/include/int_types.h index f290f9d8d235..98220e9a52e5 100644 --- a/src/include/int_types.h +++ b/src/include/int_types.h @@ -3,7 +3,7 @@ #include "acconfig.h" -#if defined(__linux__) +#ifdef HAVE_LINUX_TYPES_H #include #endif @@ -50,17 +50,41 @@ # endif #endif -#if defined(__FreeBSD__) +#ifdef HAVE_SYS_TYPES_H #include +#endif -typedef int8_t __s8; +#ifndef HAVE___U8 typedef uint8_t __u8; -typedef int16_t __s16; +#endif + +#ifndef HAVE___S8 +typedef int8_t __s8; +#endif + +#ifndef HAVE___U16 typedef uint16_t __u16; -typedef int32_t __s32; +#endif + +#ifndef HAVE___S16 +typedef int16_t __s16; +#endif + +#ifndef HAVE___U32 typedef uint32_t __u32; -typedef int64_t __s64; +#endif + +#ifndef HAVE___S32 +typedef int32_t __s32; +#endif + +#ifndef HAVE___U64 typedef uint64_t __u64; +#endif + +#ifndef HAVE___S64 +typedef int64_t __s64; +#endif #define __bitwise__ @@ -72,4 +96,3 @@ typedef __u64 __bitwise__ __le64; typedef __u64 __bitwise__ __be64; #endif -#endif diff --git a/src/include/linux_fiemap.h b/src/include/linux_fiemap.h index 352208b22078..181104875041 100644 --- a/src/include/linux_fiemap.h +++ b/src/include/linux_fiemap.h @@ -18,6 +18,8 @@ #include #endif +#include "include/int_types.h" + struct fiemap_extent { __u64 fe_logical; /* logical offset in bytes for the start of * the extent from the beginning of the file */ -- 2.47.3