aboutsummaryrefslogtreecommitdiff
path: root/src/lib/mhd_limits.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/mhd_limits.h')
-rw-r--r--src/lib/mhd_limits.h146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/lib/mhd_limits.h b/src/lib/mhd_limits.h
new file mode 100644
index 00000000..1b0f5d7d
--- /dev/null
+++ b/src/lib/mhd_limits.h
@@ -0,0 +1,146 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2015 Karlson2k (Evgeny Grin)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20/**
21 * @file microhttpd/mhd_limits.h
22 * @brief limits values definitions
23 * @author Karlson2k (Evgeny Grin)
24 */
25
26#ifndef MHD_LIMITS_H
27#define MHD_LIMITS_H
28
29#include "platform.h"
30
31#ifdef HAVE_LIMITS_H
32#include <limits.h>
33#endif /* HAVE_LIMITS_H */
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
41#ifndef UINT_MAX
42#ifdef __UINT_MAX__
43#define UINT_MAX __UINT_MAX__
44#else /* ! __UINT_MAX__ */
45#define UINT_MAX MHD_UNSIGNED_TYPE_MAX_(unsigned int)
46#endif /* ! __UINT_MAX__ */
47#endif /* !UINT_MAX */
48
49#ifndef LONG_MAX
50#ifdef __LONG_MAX__
51#define LONG_MAX __LONG_MAX__
52#else /* ! __LONG_MAX__ */
53#define LONG_MAX MHD_SIGNED_TYPE_MAX(long)
54#endif /* ! __LONG_MAX__ */
55#endif /* !OFF_T_MAX */
56
57#ifndef ULLONG_MAX
58#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_(MHD_UNSIGNED_LONG_LONG)
59#endif /* !ULLONG_MAX */
60
61#ifndef INT32_MAX
62#ifdef __INT32_MAX__
63#define INT32_MAX __INT32_MAX__
64#else /* ! __INT32_MAX__ */
65#define INT32_MAX ((int32_t)0x7FFFFFFF)
66#endif /* ! __INT32_MAX__ */
67#endif /* !INT32_MAX */
68
69#ifndef UINT32_MAX
70#ifdef __UINT32_MAX__
71#define UINT32_MAX __UINT32_MAX__
72#else /* ! __UINT32_MAX__ */
73#define UINT32_MAX ((int32_t)0xFFFFFFFF)
74#endif /* ! __UINT32_MAX__ */
75#endif /* !UINT32_MAX */
76
77#ifndef UINT64_MAX
78#ifdef __UINT64_MAX__
79#define UINT64_MAX __UINT64_MAX__
80#else /* ! __UINT64_MAX__ */
81#define UINT64_MAX ((uint64_t)0xFFFFFFFFFFFFFFFF)
82#endif /* ! __UINT64_MAX__ */
83#endif /* !UINT64_MAX */
84
85#ifndef INT64_MAX
86#ifdef __INT64_MAX__
87#define INT64_MAX __INT64_MAX__
88#else /* ! __INT64_MAX__ */
89#define INT64_MAX ((int64_t)0x7FFFFFFFFFFFFFFF)
90#endif /* ! __UINT64_MAX__ */
91#endif /* !INT64_MAX */
92
93#ifndef SIZE_MAX
94#ifdef __SIZE_MAX__
95#define SIZE_MAX __SIZE_MAX__
96#elif defined(UINTPTR_MAX)
97#define SIZE_MAX UINTPTR_MAX
98#else /* ! __SIZE_MAX__ */
99#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_(size_t)
100#endif /* ! __SIZE_MAX__ */
101#endif /* !SIZE_MAX */
102
103#ifndef SSIZE_MAX
104#ifdef __SSIZE_MAX__
105#define SSIZE_MAX __SSIZE_MAX__
106#elif defined(PTRDIFF_MAX)
107#define SSIZE_MAX PTRDIFF_MAX
108#elif defined(INTPTR_MAX)
109#define SSIZE_MAX INTPTR_MAX
110#else
111#define SSIZE_MAN MHD_SIGNED_TYPE_MAX_(ssize_t)
112#endif
113#endif /* ! SSIZE_MAX */
114
115#ifndef OFF_T_MAX
116#ifdef OFF_MAX
117#define OFF_T_MAX OFF_MAX
118#elif defined(OFFT_MAX)
119#define OFF_T_MAX OFFT_MAX
120#elif defined(__APPLE__) && defined(__MACH__)
121#define OFF_T_MAX INT64_MAX
122#else
123#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_(off_t)
124#endif
125#endif /* !OFF_T_MAX */
126
127#if defined(_LARGEFILE64_SOURCE) && !defined(OFF64_T_MAX)
128#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_(uint64_t)
129#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */
130
131#ifndef TIME_T_MAX
132#define TIME_T_MAX ((time_t) \
133 ( MHD_TYPE_IS_SIGNED_(time_t) ? \
134 MHD_SIGNED_TYPE_MAX_(time_t) : \
135 MHD_UNSIGNED_TYPE_MAX_(time_t)))
136#endif /* !TIME_T_MAX */
137
138#ifndef TIMEVAL_TV_SEC_MAX
139#ifndef _WIN32
140#define TIMEVAL_TV_SEC_MAX TIME_T_MAX
141#else /* _WIN32 */
142#define TIMEVAL_TV_SEC_MAX LONG_MAX
143#endif /* _WIN32 */
144#endif /* !TIMEVAL_TV_SEC_MAX */
145
146#endif /* MHD_LIMITS_H */