GNU libmicrohttpd 1.0.1
Loading...
Searching...
No Matches
mhd_limits.h
Go to the documentation of this file.
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2015-2022 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
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 INT_MAX
42#ifdef __INT_MAX__
43#define INT_MAX __INT_MAX__
44#else /* ! __UINT_MAX__ */
45#define INT_MAX MHD_SIGNED_TYPE_MAX_ (int)
46#endif /* ! __UINT_MAX__ */
47#endif /* !UINT_MAX */
48
49#ifndef UINT_MAX
50#ifdef __UINT_MAX__
51#define UINT_MAX __UINT_MAX__
52#else /* ! __UINT_MAX__ */
53#define UINT_MAX MHD_UNSIGNED_TYPE_MAX_ (unsigned int)
54#endif /* ! __UINT_MAX__ */
55#endif /* !UINT_MAX */
56
57#ifndef LONG_MAX
58#ifdef __LONG_MAX__
59#define LONG_MAX __LONG_MAX__
60#else /* ! __LONG_MAX__ */
61#define LONG_MAX MHD_SIGNED_TYPE_MAX (long)
62#endif /* ! __LONG_MAX__ */
63#endif /* !LONG_MAX */
64
65#ifndef ULLONG_MAX
66#ifdef ULONGLONG_MAX
67#define ULLONG_MAX ULONGLONG_MAX
68#else /* ! ULONGLONG_MAX */
69#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_ (MHD_UNSIGNED_LONG_LONG)
70#endif /* ! ULONGLONG_MAX */
71#endif /* !ULLONG_MAX */
72
73#ifndef INT32_MAX
74#ifdef __INT32_MAX__
75#define INT32_MAX __INT32_MAX__
76#else /* ! __INT32_MAX__ */
77#define INT32_MAX ((int32_t) 0x7FFFFFFF)
78#endif /* ! __INT32_MAX__ */
79#endif /* !INT32_MAX */
80
81#ifndef UINT32_MAX
82#ifdef __UINT32_MAX__
83#define UINT32_MAX __UINT32_MAX__
84#else /* ! __UINT32_MAX__ */
85#define UINT32_MAX ((int32_t) 0xFFFFFFFF)
86#endif /* ! __UINT32_MAX__ */
87#endif /* !UINT32_MAX */
88
89#ifndef UINT64_MAX
90#ifdef __UINT64_MAX__
91#define UINT64_MAX __UINT64_MAX__
92#else /* ! __UINT64_MAX__ */
93#define UINT64_MAX ((uint64_t) 0xFFFFFFFFFFFFFFFF)
94#endif /* ! __UINT64_MAX__ */
95#endif /* !UINT64_MAX */
96
97#ifndef INT64_MAX
98#ifdef __INT64_MAX__
99#define INT64_MAX __INT64_MAX__
100#else /* ! __INT64_MAX__ */
101#define INT64_MAX ((int64_t) 0x7FFFFFFFFFFFFFFF)
102#endif /* ! __UINT64_MAX__ */
103#endif /* !INT64_MAX */
104
105#ifndef SIZE_MAX
106#ifdef __SIZE_MAX__
107#define SIZE_MAX __SIZE_MAX__
108#elif defined(UINTPTR_MAX)
109#define SIZE_MAX UINTPTR_MAX
110#else /* ! __SIZE_MAX__ */
111#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_ (size_t)
112#endif /* ! __SIZE_MAX__ */
113#endif /* !SIZE_MAX */
114
115#ifndef SSIZE_MAX
116#ifdef __SSIZE_MAX__
117#define SSIZE_MAX __SSIZE_MAX__
118#elif defined(INTPTR_MAX)
119#define SSIZE_MAX INTPTR_MAX
120#else
121#define SSIZE_MAX MHD_SIGNED_TYPE_MAX_ (ssize_t)
122#endif
123#endif /* ! SSIZE_MAX */
124
125#ifndef OFF_T_MAX
126#ifdef OFF_MAX
127#define OFF_T_MAX OFF_MAX
128#elif defined(OFFT_MAX)
129#define OFF_T_MAX OFFT_MAX
130#elif defined(__APPLE__) && defined(__MACH__)
131#define OFF_T_MAX INT64_MAX
132#else
133#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_ (off_t)
134#endif
135#endif /* !OFF_T_MAX */
136
137#if defined(_LARGEFILE64_SOURCE) && ! defined(OFF64_T_MAX)
138#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_ (uint64_t)
139#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */
140
141#ifndef TIME_T_MAX
142#define TIME_T_MAX ((time_t) \
143 (MHD_TYPE_IS_SIGNED_ (time_t) ? \
144 MHD_SIGNED_TYPE_MAX_ (time_t) : \
145 MHD_UNSIGNED_TYPE_MAX_ (time_t)))
146#endif /* !TIME_T_MAX */
147
148#ifndef TIMEVAL_TV_SEC_MAX
149#ifndef _WIN32
150#define TIMEVAL_TV_SEC_MAX TIME_T_MAX
151#else /* _WIN32 */
152#define TIMEVAL_TV_SEC_MAX LONG_MAX
153#endif /* _WIN32 */
154#endif /* !TIMEVAL_TV_SEC_MAX */
155
156#endif /* MHD_LIMITS_H */
platform-specific includes for libmicrohttpd