summaryrefslogtreecommitdiff
path: root/src/include/c.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/c.h')
-rw-r--r--src/include/c.h101
1 files changed, 37 insertions, 64 deletions
diff --git a/src/include/c.h b/src/include/c.h
index 304dff27e34..734626e75a8 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -48,14 +48,12 @@
#include "postgres_ext.h"
-/* Must undef pg_config_ext.h symbols before including pg_config.h */
-#undef PG_INT64_TYPE
-
#include "pg_config.h"
#include "pg_config_manual.h" /* must be after pg_config.h */
#include "pg_config_os.h" /* must be before any system header files */
/* System header files that should be available everywhere in Postgres */
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -471,25 +469,15 @@ typedef void (*pg_funcptr_t) (void);
*/
typedef char *Pointer;
-/*
- * intN
- * Signed integer, EXACTLY N BITS IN SIZE,
- * used for numerical computations and the
- * frontend/backend protocol.
- */
-typedef signed char int8; /* == 8 bits */
-typedef signed short int16; /* == 16 bits */
-typedef signed int int32; /* == 32 bits */
-
-/*
- * uintN
- * Unsigned integer, EXACTLY N BITS IN SIZE,
- * used for numerical computations and the
- * frontend/backend protocol.
- */
-typedef unsigned char uint8; /* == 8 bits */
-typedef unsigned short uint16; /* == 16 bits */
-typedef unsigned int uint32; /* == 32 bits */
+/* Historical names for types in <stdint.h>. */
+typedef int8_t int8;
+typedef int16_t int16;
+typedef int32_t int32;
+typedef int64_t int64;
+typedef uint8_t uint8;
+typedef uint16_t uint16;
+typedef uint32_t uint32;
+typedef uint64_t uint64;
/*
* bitsN
@@ -502,30 +490,14 @@ typedef uint32 bits32; /* >= 32 bits */
/*
* 64-bit integers
*/
-#ifdef HAVE_LONG_INT_64
-/* Plain "long int" fits, use it */
-
-typedef long int int64;
-typedef unsigned long int uint64;
-#define INT64CONST(x) (x##L)
-#define UINT64CONST(x) (x##UL)
-#elif defined(HAVE_LONG_LONG_INT_64)
-/* We have working support for "long long int", use that */
-
-typedef long long int int64;
-typedef unsigned long long int uint64;
-#define INT64CONST(x) (x##LL)
-#define UINT64CONST(x) (x##ULL)
-#else
-/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
-#error must have a working 64-bit integer datatype
-#endif
+#define INT64CONST(x) INT64_C(x)
+#define UINT64CONST(x) UINT64_C(x)
/* snprintf format strings to use for 64-bit integers */
-#define INT64_FORMAT "%" INT64_MODIFIER "d"
-#define UINT64_FORMAT "%" INT64_MODIFIER "u"
-#define INT64_HEX_FORMAT "%" INT64_MODIFIER "x"
-#define UINT64_HEX_FORMAT "%" INT64_MODIFIER "x"
+#define INT64_FORMAT "%" PRId64
+#define UINT64_FORMAT "%" PRIu64
+#define INT64_HEX_FORMAT "%" PRIx64
+#define UINT64_HEX_FORMAT "%" PRIx64
/*
* 128-bit signed and unsigned integers
@@ -554,22 +526,19 @@ typedef unsigned PG_INT128_TYPE uint128
#endif
#endif
-/*
- * stdint.h limits aren't guaranteed to have compatible types with our fixed
- * width types. So just define our own.
- */
-#define PG_INT8_MIN (-0x7F-1)
-#define PG_INT8_MAX (0x7F)
-#define PG_UINT8_MAX (0xFF)
-#define PG_INT16_MIN (-0x7FFF-1)
-#define PG_INT16_MAX (0x7FFF)
-#define PG_UINT16_MAX (0xFFFF)
-#define PG_INT32_MIN (-0x7FFFFFFF-1)
-#define PG_INT32_MAX (0x7FFFFFFF)
-#define PG_UINT32_MAX (0xFFFFFFFFU)
-#define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
-#define PG_INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
-#define PG_UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF)
+/* Historical names for limits in <stdint.h>. */
+#define PG_INT8_MIN INT8_MIN
+#define PG_INT8_MAX INT8_MAX
+#define PG_UINT8_MAX UINT8_MAX
+#define PG_INT16_MIN INT16_MIN
+#define PG_INT16_MAX INT16_MAX
+#define PG_UINT16_MAX UINT16_MAX
+#define PG_INT32_MIN INT32_MIN
+#define PG_INT32_MAX INT32_MAX
+#define PG_UINT32_MAX UINT32_MAX
+#define PG_INT64_MIN INT64_MIN
+#define PG_INT64_MAX INT64_MAX
+#define PG_UINT64_MAX UINT64_MAX
/*
* We now always use int64 timestamps, but keep this symbol defined for the
@@ -1272,21 +1241,25 @@ extern int fdatasync(int fildes);
* definition of int64. (For the naming, compare that POSIX has
* strtoimax()/strtoumax() which return intmax_t/uintmax_t.)
*/
-#ifdef HAVE_LONG_INT_64
+#if SIZEOF_LONG == 8
#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
#define strtou64(str, endptr, base) ((uint64) strtoul(str, endptr, base))
-#else
+#elif SIZEOF_LONG_LONG == 8
#define strtoi64(str, endptr, base) ((int64) strtoll(str, endptr, base))
#define strtou64(str, endptr, base) ((uint64) strtoull(str, endptr, base))
+#else
+#error "cannot find integer type of the same size as int64_t"
#endif
/*
* Similarly, wrappers around labs()/llabs() matching our int64.
*/
-#ifdef HAVE_LONG_INT_64
+#if SIZEOF_LONG == 8
#define i64abs(i) labs(i)
-#else
+#elif SIZEOF_LONG_LONG == 8
#define i64abs(i) llabs(i)
+#else
+#error "cannot find integer type of the same size as int64_t"
#endif
/*