libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

mhd_limits.h (6685B)


      1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
      2 /*
      3   This file is part of GNU libmicrohttpd.
      4   Copyright (C) 2015-2024 Evgeny Grin (Karlson2k)
      5 
      6   GNU libmicrohttpd is free software; you can redistribute it and/or
      7   modify it under the terms of the GNU Lesser General Public
      8   License as published by the Free Software Foundation; either
      9   version 2.1 of the License, or (at your option) any later version.
     10 
     11   GNU libmicrohttpd is distributed in the hope that it will be useful,
     12   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14   Lesser General Public License for more details.
     15 
     16   Alternatively, you can redistribute GNU libmicrohttpd and/or
     17   modify it under the terms of the GNU General Public License as
     18   published by the Free Software Foundation; either version 2 of
     19   the License, or (at your option) any later version, together
     20   with the eCos exception, as follows:
     21 
     22     As a special exception, if other files instantiate templates or
     23     use macros or inline functions from this file, or you compile this
     24     file and link it with other works to produce a work based on this
     25     file, this file does not by itself cause the resulting work to be
     26     covered by the GNU General Public License. However the source code
     27     for this file must still be made available in accordance with
     28     section (3) of the GNU General Public License v2.
     29 
     30     This exception does not invalidate any other reasons why a work
     31     based on this file might be covered by the GNU General Public
     32     License.
     33 
     34   You should have received copies of the GNU Lesser General Public
     35   License and the GNU General Public License along with this library;
     36   if not, see <https://www.gnu.org/licenses/>.
     37 */
     38 
     39 /**
     40  * @file src/mhd2/mhd_limits.h
     41  * @brief  limits values definitions
     42  * @author Karlson2k (Evgeny Grin)
     43  *
     44  * This file provides maximum types values as macros. Macros may not work
     45  * in preprocessor expressions, while macros always work in compiler
     46  * expressions.
     47  * This file does not include <stdint.h> and other type-definitions files.
     48  * For best portability, make sure that this file is included after required
     49  * type-definitions files.
     50  */
     51 
     52 #ifndef MHD_LIMITS_H
     53 #define MHD_LIMITS_H
     54 
     55 #include "mhd_sys_options.h"
     56 
     57 #ifdef HAVE_LIMITS_H
     58 #  include <limits.h>
     59 #endif /* HAVE_LIMITS_H */
     60 
     61 #define mhd_UNSIGNED_TYPE_MAX(type) ((type) (~((type) 0)))
     62 
     63 /* Assume 8 bits per byte, no padding bits. */
     64 #define mhd_SIGNED_TYPE_MAX(type) \
     65         ( (type) ((( ((type) 1) << (sizeof(type) * 8 - 2)) - 1) * 2 + 1) )
     66 
     67 /* The maximum value for signed type, based on knowledge of unsigned counterpart
     68    type */
     69 #define mhd_SIGNED_TYPE_MAX2(type,utype) \
     70         ((type) (((utype) (~((utype) 0))) >> 1))
     71 
     72 #define mhd_IS_TYPE_SIGNED(type) (((type) 0) > ((type) - 1))
     73 
     74 #if defined(__GNUC__) || defined(__clang__)
     75 #  define mhd_USE_PREDEF_LIMITS
     76 #endif
     77 
     78 #ifndef INT_MAX
     79 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__INT_MAX__)
     80 #    define INT_MAX __INT_MAX__
     81 #  else  /* ! __INT_MAX__ */
     82 #    define INT_MAX mhd_SIGNED_TYPE_MAX2 (int, unsigned int)
     83 #  endif /* ! __INT_MAX__ */
     84 #endif /* ! INT_MAX */
     85 
     86 #ifndef UINT_MAX
     87 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__UINT_MAX__)
     88 #    define UINT_MAX __UINT_MAX__
     89 #  else  /* ! __UINT_MAX__ */
     90 #    define UINT_MAX mhd_UNSIGNED_TYPE_MAX (unsigned int)
     91 #  endif /* ! __UINT_MAX__ */
     92 #endif /* !UINT_MAX */
     93 
     94 #ifndef LONG_MAX
     95 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__LONG_MAX__)
     96 #    define LONG_MAX __LONG_MAX__
     97 #  else  /* ! __LONG_MAX__ */
     98 #    define LONG_MAX mhd_SIGNED_TYPE_MAX2 (long, unsigned long)
     99 #  endif /* ! __LONG_MAX__ */
    100 #endif /* !LONG_MAX */
    101 
    102 #ifndef ULONG_MAX
    103 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__ULONG_MAX__)
    104 #    define ULONG_MAX ULONG_MAX
    105 #  else  /* ! __ULONG_MAX__ */
    106 #    define ULONG_MAX mhd_UNSIGNED_TYPE_MAX (unsigned long)
    107 #  endif /* ! __ULONG_MAX__ */
    108 #endif /* !ULONG_MAX */
    109 
    110 #ifndef ULLONG_MAX
    111 #  ifdef ULONGLONG_MAX
    112 #    define ULLONG_MAX ULONGLONG_MAX
    113 #  else  /* ! ULONGLONG_MAX */
    114 #    define ULLONG_MAX mhd_UNSIGNED_TYPE_MAX (unsigned long long)
    115 #  endif /* ! ULONGLONG_MAX */
    116 #endif /* !ULLONG_MAX */
    117 
    118 #ifndef INT32_MAX
    119 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__INT32_MAX__)
    120 #    define INT32_MAX __INT32_MAX__
    121 #  else  /* ! __INT32_MAX__ */
    122 #    define INT32_MAX ((int32_t) 0x7FFFFFFF)
    123 #  endif /* ! __INT32_MAX__ */
    124 #endif /* !INT32_MAX */
    125 
    126 #ifndef UINT32_MAX
    127 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__UINT32_MAX__)
    128 #    define UINT32_MAX __UINT32_MAX__
    129 #  else  /* ! __UINT32_MAX__ */
    130 #    define UINT32_MAX ((uint32_t) 0xFFFFFFFFU)
    131 #  endif /* ! __UINT32_MAX__ */
    132 #endif /* !UINT32_MAX */
    133 
    134 #ifndef INT64_MAX
    135 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__INT64_MAX__)
    136 #    define INT64_MAX __INT64_MAX__
    137 #  else  /* ! __INT64_MAX__ */
    138 #    define INT64_MAX ((int64_t) 0x7FFFFFFFFFFFFFFF)
    139 #  endif /* ! __UINT64_MAX__ */
    140 #endif /* !INT64_MAX */
    141 
    142 #ifndef UINT64_MAX
    143 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__UINT64_MAX__)
    144 #    define UINT64_MAX __UINT64_MAX__
    145 #  else  /* ! __UINT64_MAX__ */
    146 #    define UINT64_MAX ((uint64_t) 0xFFFFFFFFFFFFFFFFU)
    147 #  endif /* ! __UINT64_MAX__ */
    148 #endif /* !UINT64_MAX */
    149 
    150 #ifndef SIZE_MAX
    151 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__SIZE_MAX__)
    152 #    define SIZE_MAX __SIZE_MAX__
    153 #  else  /* ! __SIZE_MAX__ */
    154 #    define SIZE_MAX mhd_UNSIGNED_TYPE_MAX (size_t)
    155 #  endif /* ! __SIZE_MAX__ */
    156 #endif /* !SIZE_MAX */
    157 
    158 #ifndef SSIZE_MAX
    159 #  if defined(mhd_USE_PREDEF_LIMITS) && defined(__SSIZE_MAX__)
    160 #    define SSIZE_MAX __SSIZE_MAX__
    161 #  else
    162 #    define SSIZE_MAX mhd_SIGNED_TYPE_MAX2 (ssize_t, size_t)
    163 #  endif
    164 #endif /* ! SSIZE_MAX */
    165 
    166 #ifndef OFF_T_MAX
    167 #  ifdef OFF_MAX
    168 #    define OFF_T_MAX OFF_MAX
    169 #  elif defined(OFFT_MAX)
    170 #    define OFF_T_MAX OFFT_MAX
    171 #  elif defined(__APPLE__) && defined(__MACH__)
    172 #    define OFF_T_MAX INT64_MAX
    173 #  else
    174 #    define OFF_T_MAX mhd_SIGNED_TYPE_MAX (off_t)
    175 #  endif
    176 #endif /* !OFF_T_MAX */
    177 
    178 #if defined(_LARGEFILE64_SOURCE) && ! defined(OFF64_T_MAX)
    179 #  define OFF64_T_MAX mhd_SIGNED_TYPE_MAX (off64_t)
    180 #endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */
    181 
    182 #ifndef TIME_T_MAX
    183 #  define TIME_T_MAX ((time_t)                        \
    184                       (mhd_IS_TYPE_SIGNED (time_t) ?  \
    185                        mhd_SIGNED_TYPE_MAX (time_t) : \
    186                        mhd_UNSIGNED_TYPE_MAX (time_t)))
    187 #endif /* !TIME_T_MAX */
    188 
    189 #ifndef TIMEVAL_TV_SEC_MAX
    190 #  ifndef _WIN32
    191 #    define mhd_TIMEVAL_TV_SEC_MAX TIME_T_MAX
    192 #  else  /* _WIN32 */
    193 #    define mhd_TIMEVAL_TV_SEC_MAX LONG_MAX
    194 #  endif /* _WIN32 */
    195 #endif /* !TIMEVAL_TV_SEC_MAX */
    196 
    197 #endif /* MHD_LIMITS_H */