aboutsummaryrefslogtreecommitdiff
path: root/src/lib/mhd_limits.h
blob: 87b414474b5bace3e75b514904ee88700613d23b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
  This file is part of libmicrohttpd
  Copyright (C) 2015 Karlson2k (Evgeny Grin)

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

/**
 * @file microhttpd/mhd_limits.h
 * @brief  limits values definitions
 * @author Karlson2k (Evgeny Grin)
 */

#ifndef MHD_LIMITS_H
#define MHD_LIMITS_H

#include "platform.h"

#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif /* HAVE_LIMITS_H */

#define MHD_UNSIGNED_TYPE_MAX_(type) ((type) - 1)
/* Assume 8 bits per byte, no padding bits. */
#define MHD_SIGNED_TYPE_MAX_(type) \
  ( (type) ((( ((type) 1) << (sizeof(type) * 8 - 2)) - 1) * 2 + 1) )
#define MHD_TYPE_IS_SIGNED_(type) (((type) 0)>((type) - 1))

#ifndef UINT_MAX
#ifdef __UINT_MAX__
#define UINT_MAX __UINT_MAX__
#else  /* ! __UINT_MAX__ */
#define UINT_MAX MHD_UNSIGNED_TYPE_MAX_ (unsigned int)
#endif /* ! __UINT_MAX__ */
#endif /* !UINT_MAX */

#ifndef LONG_MAX
#ifdef __LONG_MAX__
#define LONG_MAX __LONG_MAX__
#else  /* ! __LONG_MAX__ */
#define LONG_MAX MHD_SIGNED_TYPE_MAX (long)
#endif /* ! __LONG_MAX__ */
#endif /* !OFF_T_MAX */

#ifndef ULLONG_MAX
#define ULLONG_MAX MHD_UNSIGNED_TYPE_MAX_ (MHD_UNSIGNED_LONG_LONG)
#endif /* !ULLONG_MAX */

#ifndef INT32_MAX
#ifdef __INT32_MAX__
#define INT32_MAX __INT32_MAX__
#else  /* ! __INT32_MAX__ */
#define INT32_MAX ((int32_t) 0x7FFFFFFF)
#endif /* ! __INT32_MAX__ */
#endif /* !INT32_MAX */

#ifndef UINT32_MAX
#ifdef __UINT32_MAX__
#define UINT32_MAX __UINT32_MAX__
#else  /* ! __UINT32_MAX__ */
#define UINT32_MAX ((int32_t) 0xFFFFFFFF)
#endif /* ! __UINT32_MAX__ */
#endif /* !UINT32_MAX */

#ifndef UINT64_MAX
#ifdef __UINT64_MAX__
#define UINT64_MAX __UINT64_MAX__
#else  /* ! __UINT64_MAX__ */
#define UINT64_MAX ((uint64_t) 0xFFFFFFFFFFFFFFFF)
#endif /* ! __UINT64_MAX__ */
#endif /* !UINT64_MAX */

#ifndef INT64_MAX
#ifdef __INT64_MAX__
#define INT64_MAX __INT64_MAX__
#else  /* ! __INT64_MAX__ */
#define INT64_MAX ((int64_t) 0x7FFFFFFFFFFFFFFF)
#endif /* ! __UINT64_MAX__ */
#endif /* !INT64_MAX */

#ifndef SIZE_MAX
#ifdef __SIZE_MAX__
#define SIZE_MAX __SIZE_MAX__
#elif defined(UINTPTR_MAX)
#define SIZE_MAX UINTPTR_MAX
#else  /* ! __SIZE_MAX__ */
#define SIZE_MAX MHD_UNSIGNED_TYPE_MAX_ (size_t)
#endif /* ! __SIZE_MAX__ */
#endif /* !SIZE_MAX */

#ifndef SSIZE_MAX
#ifdef __SSIZE_MAX__
#define SSIZE_MAX __SSIZE_MAX__
#elif defined(PTRDIFF_MAX)
#define SSIZE_MAX PTRDIFF_MAX
#elif defined(INTPTR_MAX)
#define SSIZE_MAX INTPTR_MAX
#else
#define SSIZE_MAN MHD_SIGNED_TYPE_MAX_ (ssize_t)
#endif
#endif /* ! SSIZE_MAX */

#ifndef OFF_T_MAX
#ifdef OFF_MAX
#define OFF_T_MAX OFF_MAX
#elif defined(OFFT_MAX)
#define OFF_T_MAX OFFT_MAX
#elif defined(__APPLE__) && defined(__MACH__)
#define OFF_T_MAX INT64_MAX
#else
#define OFF_T_MAX MHD_SIGNED_TYPE_MAX_ (off_t)
#endif
#endif /* !OFF_T_MAX */

#if defined(_LARGEFILE64_SOURCE) && ! defined(OFF64_T_MAX)
#define OFF64_T_MAX MHD_SIGNED_TYPE_MAX_ (uint64_t)
#endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */

#ifndef TIME_T_MAX
#define TIME_T_MAX ((time_t)              \
                    (MHD_TYPE_IS_SIGNED_ (time_t) ?    \
                     MHD_SIGNED_TYPE_MAX_ (time_t) : \
                     MHD_UNSIGNED_TYPE_MAX_ (time_t)))
#endif /* !TIME_T_MAX */

#ifndef TIMEVAL_TV_SEC_MAX
#ifndef _WIN32
#define TIMEVAL_TV_SEC_MAX TIME_T_MAX
#else  /* _WIN32 */
#define TIMEVAL_TV_SEC_MAX LONG_MAX
#endif /* _WIN32 */
#endif /* !TIMEVAL_TV_SEC_MAX */

#ifndef MHD_FD_BLOCK_SIZE
#ifdef _WIN32
#define MHD_FD_BLOCK_SIZE 16384 /* 16k */
#else /* _WIN32 */
#define MHD_FD_BLOCK_SIZE 4096 /* 4k */
#endif /* _WIN32 */
#endif /* !MHD_FD_BLOCK_SIZE */

#endif /* MHD_LIMITS_H */