GNU libmicrohttpd 0.9.77
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 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
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 /* !LONG_MAX */
56
57#ifndef ULLONG_MAX
58#ifdef ULONGLONG_MAX
59#define ULLONG_MAX ULONGLONG_MAX
60#else /* ! ULONGLONG_MAX */
61#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_ (MHD_UNSIGNED_LONG_LONG)
62#endif /* ! ULONGLONG_MAX */
63#endif /* !ULLONG_MAX */
64
65#ifndef INT32_MAX
66#ifdef __INT32_MAX__
67#define INT32_MAX __INT32_MAX__
68#else /* ! __INT32_MAX__ */
69#define INT32_MAX ((int32_t) 0x7FFFFFFF)
70#endif /* ! __INT32_MAX__ */
71#endif /* !INT32_MAX */
72
73#ifndef UINT32_MAX
74#ifdef __UINT32_MAX__
75#define UINT32_MAX __UINT32_MAX__
76#else /* ! __UINT32_MAX__ */
77#define UINT32_MAX ((int32_t) 0xFFFFFFFF)
78#endif /* ! __UINT32_MAX__ */
79#endif /* !UINT32_MAX */
80
81#ifndef UINT64_MAX
82#ifdef __UINT64_MAX__
83#define UINT64_MAX __UINT64_MAX__
84#else /* ! __UINT64_MAX__ */
85#define UINT64_MAX ((uint64_t) 0xFFFFFFFFFFFFFFFF)
86#endif /* ! __UINT64_MAX__ */
87#endif /* !UINT64_MAX */
88
89#ifndef INT64_MAX
90#ifdef __INT64_MAX__
91#define INT64_MAX __INT64_MAX__
92#else /* ! __INT64_MAX__ */
93#define INT64_MAX ((int64_t) 0x7FFFFFFFFFFFFFFF)
94#endif /* ! __UINT64_MAX__ */
95#endif /* !INT64_MAX */
96
97#ifndef SIZE_MAX
98#ifdef __SIZE_MAX__
99#define SIZE_MAX __SIZE_MAX__
100#elif defined(UINTPTR_MAX)
101#define SIZE_MAX UINTPTR_MAX
102#else /* ! __SIZE_MAX__ */
103#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_ (size_t)
104#endif /* ! __SIZE_MAX__ */
105#endif /* !SIZE_MAX */
106
107#ifndef SSIZE_MAX
108#ifdef __SSIZE_MAX__
109#define SSIZE_MAX __SSIZE_MAX__
110#elif defined(INTPTR_MAX)
111#define SSIZE_MAX INTPTR_MAX
112#else
113#define SSIZE_MAX MHD_SIGNED_TYPE_MAX_ (ssize_t)
114#endif
115#endif /* ! SSIZE_MAX */
116
117#ifndef OFF_T_MAX
118#ifdef OFF_MAX
119#define OFF_T_MAX OFF_MAX
120#elif defined(OFFT_MAX)
121#define OFF_T_MAX OFFT_MAX
122#elif defined(__APPLE__) && defined(__MACH__)
123#define OFF_T_MAX INT64_MAX
124#else
125#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_ (off_t)
126#endif
127#endif /* !OFF_T_MAX */
128
129#if defined(_LARGEFILE64_SOURCE) && ! defined(OFF64_T_MAX)
130#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_ (uint64_t)
131#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */
132
133#ifndef TIME_T_MAX
134#define TIME_T_MAX ((time_t) \
135 (MHD_TYPE_IS_SIGNED_ (time_t) ? \
136 MHD_SIGNED_TYPE_MAX_ (time_t) : \
137 MHD_UNSIGNED_TYPE_MAX_ (time_t)))
138#endif /* !TIME_T_MAX */
139
140#ifndef TIMEVAL_TV_SEC_MAX
141#ifndef _WIN32
142#define TIMEVAL_TV_SEC_MAX TIME_T_MAX
143#else /* _WIN32 */
144#define TIMEVAL_TV_SEC_MAX LONG_MAX
145#endif /* _WIN32 */
146#endif /* !TIMEVAL_TV_SEC_MAX */
147
148#endif /* MHD_LIMITS_H */
platform-specific includes for libmicrohttpd