| 1 | /*
|
|---|
| 2 | * Copyright (c) 2017 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libc
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #ifndef _LIBC_LIMITS_H_
|
|---|
| 36 | #define _LIBC_LIMITS_H_
|
|---|
| 37 |
|
|---|
| 38 | #ifdef __GNUC__
|
|---|
| 39 | /*
|
|---|
| 40 | * Default to compiler's version of limits.h, so we don't have to care about
|
|---|
| 41 | * language version and whatnot.
|
|---|
| 42 | */
|
|---|
| 43 | #include_next <limits.h>
|
|---|
| 44 | #else
|
|---|
| 45 |
|
|---|
| 46 | /* HelenOS requires 8-bit char and two's complement arithmetic. */
|
|---|
| 47 | #define CHAR_BIT 8
|
|---|
| 48 | #define SCHAR_MAX 0x7f
|
|---|
| 49 | #define SCHAR_MIN (-SCHAR_MAX - 1)
|
|---|
| 50 | #define SHRT_MAX 0x7fff
|
|---|
| 51 | #define SHRT_MIN (-SHRT_MAX - 1)
|
|---|
| 52 | #define INT_MAX 0x7fffffff
|
|---|
| 53 | #define INT_MIN (-INT_MAX - 1)
|
|---|
| 54 | #define LLONG_MAX 0x7fffffffffffffffll
|
|---|
| 55 | #define LLONG_MIN (-LLONG_MAX - 1)
|
|---|
| 56 |
|
|---|
| 57 | #define UCHAR_MAX 0xff
|
|---|
| 58 | #define USHRT_MAX 0xffff
|
|---|
| 59 | #define UINT_MAX 0xffffffffu
|
|---|
| 60 | #define ULLONG_MAX 0xffffffffffffffffull
|
|---|
| 61 |
|
|---|
| 62 | #if __STDC_VERSION__ >= 201112L
|
|---|
| 63 | _Static_assert(((char)-1) < 0, "char should be signed");
|
|---|
| 64 | #endif
|
|---|
| 65 |
|
|---|
| 66 | #define CHAR_MAX SCHAR_MAX
|
|---|
| 67 | #define CHAR_MIN SCHAR_MIN
|
|---|
| 68 |
|
|---|
| 69 | #ifdef __32_BITS__
|
|---|
| 70 | #define LONG_MAX 0x7fffffffl
|
|---|
| 71 | #define LONG_MIN (-LONG_MAX - 1)
|
|---|
| 72 | #define ULONG_MAX 0xfffffffful
|
|---|
| 73 | #endif
|
|---|
| 74 |
|
|---|
| 75 | #ifdef __64_BITS__
|
|---|
| 76 | #define LONG_MAX 0x7fffffffffffffffl
|
|---|
| 77 | #define LONG_MIN (-LONG_MAX - 1)
|
|---|
| 78 | #define ULONG_MAX 0xfffffffffffffffful
|
|---|
| 79 | #endif
|
|---|
| 80 |
|
|---|
| 81 | #endif /* !defined(__GNUC__) */
|
|---|
| 82 |
|
|---|
| 83 | #undef MB_LEN_MAX
|
|---|
| 84 | #define MB_LEN_MAX 4
|
|---|
| 85 |
|
|---|
| 86 | #ifdef _HELENOS_SOURCE
|
|---|
| 87 | #define UCHAR_MIN 0
|
|---|
| 88 | #define USHRT_MIN 0
|
|---|
| 89 | #define UINT_MIN (0u)
|
|---|
| 90 | #define ULONG_MIN (0ul)
|
|---|
| 91 | #define ULLONG_MIN (0ull)
|
|---|
| 92 | #define SSIZE_MIN INTPTR_MIN
|
|---|
| 93 | #define UINT8_MIN 0
|
|---|
| 94 | #define UINT16_MIN 0
|
|---|
| 95 | #define UINT32_MIN 0
|
|---|
| 96 | #define UINT64_MIN 0
|
|---|
| 97 | #endif
|
|---|
| 98 |
|
|---|
| 99 | #if defined(_HELENOS_SOURCE) || defined(_POSIX_SOURCE) || \
|
|---|
| 100 | defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
|
|---|
| 101 | defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
|---|
| 102 |
|
|---|
| 103 | #define SSIZE_MAX INTPTR_MAX
|
|---|
| 104 | #define NAME_MAX 255
|
|---|
| 105 |
|
|---|
| 106 | #endif
|
|---|
| 107 |
|
|---|
| 108 | /* GCC's <limits.h> doesn't define these for C++11, even though it should. */
|
|---|
| 109 | #if __cplusplus >= 201103L
|
|---|
| 110 | #ifndef LLONG_MAX
|
|---|
| 111 | #define LLONG_MAX 0x7fffffffffffffffll
|
|---|
| 112 | #endif
|
|---|
| 113 | #ifndef LLONG_MIN
|
|---|
| 114 | #define LLONG_MIN (-LLONG_MAX - 1)
|
|---|
| 115 | #endif
|
|---|
| 116 | #ifndef ULLONG_MAX
|
|---|
| 117 | #define ULLONG_MAX 0xffffffffffffffffull
|
|---|
| 118 | #endif
|
|---|
| 119 | #endif
|
|---|
| 120 |
|
|---|
| 121 | #endif
|
|---|
| 122 |
|
|---|
| 123 | /** @}
|
|---|
| 124 | */
|
|---|