1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2014 Garrett D'Amore <garrett@damore.org> 24 * 25 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 #ifndef _SYS_INT_LIMITS_H 30 #define _SYS_INT_LIMITS_H 31 32 /* 33 * This file, <sys/int_limits.h>, is part of the Sun Microsystems implementation 34 * of <inttypes.h> as defined in the ISO C standard, ISO/IEC 9899:1999 35 * Programming language - C. 36 * 37 * Programs/Modules should not directly include this file. Access to the 38 * types defined in this file should be through the inclusion of one of the 39 * following files: 40 * 41 * <limits.h> This nested inclusion is disabled for strictly 42 * ANSI-C conforming compilations. The *_MIN 43 * definitions are not visible to POSIX or XPG 44 * conforming applications (due to what may be 45 * a bug in the specification - this is under 46 * investigation) 47 * 48 * <sys/inttypes.h> Provides the Kernel and Driver appropriate 49 * components of <inttypes.h>. 50 * 51 * <inttypes.h> For use by applications. 52 * 53 * See these files for more details. 54 */ 55 56 #include <sys/feature_tests.h> 57 58 #ifdef __cplusplus 59 extern "C" { 60 #endif 61 62 /* 63 * Limits 64 * 65 * The following define the limits for the types defined in <sys/int_types.h>. 66 * 67 * INTMAX_MIN (minimum value of the largest supported signed integer type), 68 * INTMAX_MAX (maximum value of the largest supported signed integer type), 69 * and UINTMAX_MAX (maximum value of the largest supported unsigned integer 70 * type) can be set to implementation defined limits. 71 * 72 * NOTE : A programmer can test to see whether an implementation supports 73 * a particular size of integer by testing if the macro that gives the 74 * maximum for that datatype is defined. For example, if #ifdef UINT64_MAX 75 * tests false, the implementation does not support unsigned 64 bit integers. 76 * 77 * The type of these macros is intentionally unspecified. 78 * 79 * The types int8_t, int_least8_t, and int_fast8_t are not defined for ISAs 80 * where the ABI specifies "char" as unsigned when the translation mode is 81 * not ANSI-C. 82 */ 83 #define INT8_MAX (127) 84 #define INT16_MAX (32767) 85 #define INT32_MAX (2147483647) 86 #if defined(_LP64) 87 #define INT64_MAX (9223372036854775807L) 88 #elif defined(_LONGLONG_TYPE) 89 #define INT64_MAX (9223372036854775807LL) 90 #endif 91 92 #define UINT8_MAX (255U) 93 #define UINT16_MAX (65535U) 94 #define UINT32_MAX (4294967295U) 95 #if defined(_LP64) 96 #define UINT64_MAX (18446744073709551615UL) 97 #elif defined(_LONGLONG_TYPE) 98 #define UINT64_MAX (18446744073709551615ULL) 99 #endif 100 101 #ifdef INT64_MAX 102 #define INTMAX_MAX INT64_MAX 103 #else 104 #define INTMAX_MAX INT32_MAX 105 #endif 106 107 #ifdef UINT64_MAX 108 #define UINTMAX_MAX UINT64_MAX 109 #else 110 #define UINTMAX_MAX UINT32_MAX 111 #endif 112 113 #define INT_LEAST8_MAX INT8_MAX 114 #define INT_LEAST16_MAX INT16_MAX 115 #define INT_LEAST32_MAX INT32_MAX 116 #ifdef INT64_MAX 117 #define INT_LEAST64_MAX INT64_MAX 118 #endif 119 120 #define UINT_LEAST8_MAX UINT8_MAX 121 #define UINT_LEAST16_MAX UINT16_MAX 122 #define UINT_LEAST32_MAX UINT32_MAX 123 #ifdef UINT64_MAX 124 #define UINT_LEAST64_MAX UINT64_MAX 125 #endif 126 127 #define INT_FAST8_MAX INT8_MAX 128 #define INT_FAST16_MAX INT16_MAX 129 #define INT_FAST32_MAX INT32_MAX 130 #ifdef INT64_MAX 131 #define INT_FAST64_MAX INT64_MAX 132 #endif 133 134 #define UINT_FAST8_MAX UINT8_MAX 135 #define UINT_FAST16_MAX UINT16_MAX 136 #define UINT_FAST32_MAX UINT32_MAX 137 #ifdef UINT64_MAX 138 #define UINT_FAST64_MAX UINT64_MAX 139 #endif 140 141 /* 142 * The following 2 macros are provided for testing whether the types 143 * intptr_t and uintptr_t (integers large enough to hold a void *) are 144 * defined in this header. They are needed in case the architecture can't 145 * represent a pointer in any standard integral type. 146 */ 147 #if defined(_LP64) || defined(_I32LPx) 148 #define INTPTR_MAX INT64_MAX 149 #define UINTPTR_MAX UINT64_MAX 150 #else 151 #define INTPTR_MAX INT32_MAX 152 #define UINTPTR_MAX UINT32_MAX 153 #endif 154 155 /* Maximum limits of ptrdiff_t defined in <sys/types.h> */ 156 #if defined(_LP64) || defined(_I32LPx) 157 #define PTRDIFF_MAX 9223372036854775807L 158 #else 159 #define PTRDIFF_MAX 2147483647 160 #endif 161 162 /* 163 * Maximum value of a "size_t". SIZE_MAX was previously defined 164 * in <limits.h>, however, the standards specify it be defined 165 * in <stdint.h>. The <stdint.h> headers includes this header as 166 * does <limits.h>. The value of SIZE_MAX should not deviate 167 * from the value of ULONG_MAX defined <sys/types.h>. 168 */ 169 #if defined(_LP64) 170 #define SIZE_MAX 18446744073709551615UL 171 #else 172 #define SIZE_MAX 4294967295UL 173 #endif 174 175 /* Maximum limit of sig_atomic_t defined in <sys/types.h> */ 176 #ifndef SIG_ATOMIC_MAX 177 #define SIG_ATOMIC_MAX 2147483647 178 #endif 179 180 /* 181 * Maximum limit of wchar_t. The WCHAR_* macros are also 182 * defined in <iso/wchar_iso.h>, but inclusion of that header 183 * will break ISO/IEC C namespace. 184 */ 185 #ifndef WCHAR_MAX 186 #define WCHAR_MAX 2147483647 187 #endif 188 189 /* Maximum limit of wint_t */ 190 #ifndef WINT_MAX 191 #define WINT_MAX 2147483647 192 #endif 193 194 /* 195 * It is probably a bug in the POSIX specification (IEEE-1003.1-1990) that 196 * when including <limits.h> that the suffix _MAX is reserved but not the 197 * suffix _MIN. However, until that issue is resolved.... 198 */ 199 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG6) 200 201 #define INT8_MIN (-128) 202 #define INT16_MIN (-32767-1) 203 #define INT32_MIN (-2147483647-1) 204 #if defined(_LP64) 205 #define INT64_MIN (-9223372036854775807L-1) 206 #elif defined(_LONGLONG_TYPE) 207 #define INT64_MIN (-9223372036854775807LL-1) 208 #endif 209 210 #ifdef INT64_MIN 211 #define INTMAX_MIN INT64_MIN 212 #else 213 #define INTMAX_MIN INT32_MIN 214 #endif 215 216 #define INT_LEAST8_MIN INT8_MIN 217 #define INT_LEAST16_MIN INT16_MIN 218 #define INT_LEAST32_MIN INT32_MIN 219 #ifdef INT64_MIN 220 #define INT_LEAST64_MIN INT64_MIN 221 #endif 222 223 #define INT_FAST8_MIN INT8_MIN 224 #define INT_FAST16_MIN INT16_MIN 225 #define INT_FAST32_MIN INT32_MIN 226 #ifdef INT64_MIN 227 #define INT_FAST64_MIN INT64_MIN 228 #endif 229 230 /* Minimum value of a pointer-holding signed integer type */ 231 #if defined(_LP64) || defined(_I32LPx) 232 #define INTPTR_MIN INT64_MIN 233 #else 234 #define INTPTR_MIN INT32_MIN 235 #endif 236 237 /* Minimum limits of ptrdiff_t defined in <sys/types.h> */ 238 #if defined(_LP64) || defined(_I32LPx) 239 #define PTRDIFF_MIN (-9223372036854775807L-1L) 240 #else 241 #define PTRDIFF_MIN (-2147483647-1) 242 #endif 243 244 /* Minimum limit of sig_atomic_t defined in <sys/types.h> */ 245 #ifndef SIG_ATOMIC_MIN 246 #define SIG_ATOMIC_MIN (-2147483647-1) 247 #endif 248 249 /* 250 * Minimum limit of wchar_t. The WCHAR_* macros are also 251 * defined in <iso/wchar_iso.h>, but inclusion of that header 252 * will break ISO/IEC C namespace. 253 */ 254 #ifndef WCHAR_MIN 255 #define WCHAR_MIN (-2147483647-1) 256 #endif 257 258 /* Minimum limit of wint_t */ 259 #ifndef WINT_MIN 260 #define WINT_MIN (-2147483647-1) 261 #endif 262 263 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) ... */ 264 265 #ifdef __cplusplus 266 } 267 #endif 268 269 #endif /* _SYS_INT_LIMITS_H */