aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_limits.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_limits.h')
-rw-r--r--src/microhttpd/mhd_limits.h25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/microhttpd/mhd_limits.h b/src/microhttpd/mhd_limits.h
index f0f0d577..b0778112 100644
--- a/src/microhttpd/mhd_limits.h
+++ b/src/microhttpd/mhd_limits.h
@@ -32,11 +32,17 @@
32#include <limits.h> 32#include <limits.h>
33#endif /* HAVE_LIMITS_H */ 33#endif /* HAVE_LIMITS_H */
34 34
35#define MHD_UNSIGNED_TYPE_MAX_(type) ((type)-1)
36/* Assume 8 bits per byte, no padding bits. */
37#define MHD_SIGNED_TYPE_MAX_(type) \
38 ( (type)((( ((type)1) << (sizeof(type)*8 - 2)) - 1)*2 + 1) )
39#define MHD_TYPE_IS_SIGNED_(type) (((type)0)>((type)-1))
40
35#ifndef UINT_MAX 41#ifndef UINT_MAX
36#ifdef __UINT_MAX__ 42#ifdef __UINT_MAX__
37#define UINT_MAX __UINT_MAX__ 43#define UINT_MAX __UINT_MAX__
38#else /* ! __UINT_MAX__ */ 44#else /* ! __UINT_MAX__ */
39#define UINT_MAX ((unsigned int) ~((unsigned int)0)) 45#define UINT_MAX MHD_UNSIGNED_TYPE_MAX_(unsigned int)
40#endif /* ! __UINT_MAX__ */ 46#endif /* ! __UINT_MAX__ */
41#endif /* !UINT_MAX */ 47#endif /* !UINT_MAX */
42 48
@@ -44,12 +50,12 @@
44#ifdef __LONG_MAX__ 50#ifdef __LONG_MAX__
45#define LONG_MAX __LONG_MAX__ 51#define LONG_MAX __LONG_MAX__
46#else /* ! __LONG_MAX__ */ 52#else /* ! __LONG_MAX__ */
47#define LONG_MAX ((long) ~(((uint64_t) 1) << (8 * sizeof(long) - 1))) 53#define LONG_MAX MHD_SIGNED_TYPE_MAX(long)
48#endif /* ! __LONG_MAX__ */ 54#endif /* ! __LONG_MAX__ */
49#endif /* !OFF_T_MAX */ 55#endif /* !OFF_T_MAX */
50 56
51#ifndef ULLONG_MAX 57#ifndef ULLONG_MAX
52#define ULLONG_MAX ((MHD_UNSIGNED_LONG_LONG) ~((MHD_UNSIGNED_LONG_LONG)0)) 58#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_(MHD_UNSIGNED_LONG_LONG)
53#endif /* !ULLONG_MAX */ 59#endif /* !ULLONG_MAX */
54 60
55#ifndef INT32_MAX 61#ifndef INT32_MAX
@@ -80,22 +86,23 @@
80#ifdef __SIZE_MAX__ 86#ifdef __SIZE_MAX__
81#define SIZE_MAX __SIZE_MAX__ 87#define SIZE_MAX __SIZE_MAX__
82#else /* ! __SIZE_MAX__ */ 88#else /* ! __SIZE_MAX__ */
83#define SIZE_MAX ((size_t) ~((size_t)0)) 89#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_(size_t)
84#endif /* ! __SIZE_MAX__ */ 90#endif /* ! __SIZE_MAX__ */
85#endif /* !SIZE_MAX */ 91#endif /* !SIZE_MAX */
86 92
87#ifndef OFF_T_MAX 93#ifndef OFF_T_MAX
88#define OFF_T_MAX ((off_t) ~(((uint64_t) 1) << (8 * sizeof(off_t) - 1))) 94#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_(off_t)
89#endif /* !OFF_T_MAX */ 95#endif /* !OFF_T_MAX */
90 96
91#if defined(_LARGEFILE64_SOURCE) && !defined(OFF64_T_MAX) 97#if defined(_LARGEFILE64_SOURCE) && !defined(OFF64_T_MAX)
92#define OFF64_T_MAX ((off64_t) ~(((uint64_t) 1) << (8 * sizeof(off64_t) - 1))) 98#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_(uint64_t)
93#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */ 99#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */
94 100
95#ifndef TIME_T_MAX 101#ifndef TIME_T_MAX
96/* Assume that time_t is signed type. */ 102#define TIME_T_MAX ((time_t) \
97/* Even if time_t is unsigned, TIME_T_MAX will be safe limit */ 103 ( MHD_TYPE_IS_SIGNED_(time_t) ? \
98#define TIME_T_MAX ( (time_t) ~(((uint64_t) 1) << (8 * sizeof(time_t) - 1)) ) 104 MHD_SIGNED_TYPE_MAX_(time_t) : \
105 MHD_UNSIGNED_TYPE_MAX_(time_t)))
99#endif /* !TIME_T_MAX */ 106#endif /* !TIME_T_MAX */
100 107
101#ifndef TIMEVAL_TV_SEC_MAX 108#ifndef TIMEVAL_TV_SEC_MAX