common_limits.h revision 1.4 1 1.4 riastrad /* $NetBSD: common_limits.h,v 1.4 2024/10/30 15:56:12 riastradh Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Matt Thomas of 3am Software Foundry.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt *
19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.1 matt */
31 1.1 matt
32 1.1 matt #ifndef _SYS_COMMON_LIMITS_H_
33 1.1 matt #define _SYS_COMMON_LIMITS_H_
34 1.1 matt
35 1.4 riastrad #include <sys/featuretest.h>
36 1.4 riastrad
37 1.1 matt #define CHAR_BIT __CHAR_BIT__ /* number of bits in a char */
38 1.1 matt
39 1.2 matt #define SCHAR_MIN (-__SCHAR_MAX__-1) /* min value for a signed char */
40 1.1 matt #define SCHAR_MAX __SCHAR_MAX__ /* max value for a signed char */
41 1.2 matt #define UCHAR_MAX (2*SCHAR_MAX+1) /* max value for an unsigned char */
42 1.1 matt
43 1.2 matt #define SHRT_MIN (-__SHRT_MAX__-1) /* min value for a short */
44 1.1 matt #define SHRT_MAX __SHRT_MAX__ /* max value for a short */
45 1.2 matt #define USHRT_MAX (2*SHRT_MAX+1) /* max value for an unsigned short */
46 1.1 matt
47 1.2 matt #define INT_MIN (-__INT_MAX__-1) /* min value for an int */
48 1.1 matt #define INT_MAX __INT_MAX__ /* max value for an int */
49 1.2 matt #define UINT_MAX (2U*INT_MAX+1U) /* max value for an unsigned int */
50 1.1 matt
51 1.2 matt #define LONG_MIN (-__LONG_MAX__-1L) /* min value for a long */
52 1.2 matt #define LONG_MAX __LONG_MAX__ /* max value for a long */
53 1.2 matt #define ULONG_MAX (2UL*LONG_MAX+1UL) /* max unsigned long */
54 1.1 matt
55 1.1 matt #if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
56 1.1 matt defined(_NETBSD_SOURCE)
57 1.2 matt #define LLONG_MIN (-__LONG_LONG_MAX__-1LL) /* min signed long long */
58 1.1 matt #define LLONG_MAX __LONG_LONG_MAX__ /* max signed long long */
59 1.2 matt #define ULLONG_MAX (2ULL*LLONG_MAX+1ULL) /* max unsigned long long */
60 1.1 matt #endif
61 1.1 matt
62 1.3 dholland #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
63 1.3 dholland defined(_NETBSD_SOURCE)
64 1.3 dholland #define SSIZE_MAX LONG_MAX /* max value for a ssize_t */
65 1.3 dholland
66 1.1 matt #if defined(_NETBSD_SOURCE)
67 1.1 matt #define SSIZE_MIN LONG_MIN /* min value for a ssize_t */
68 1.1 matt #define SIZE_T_MAX ULONG_MAX /* max value for a size_t */
69 1.1 matt
70 1.1 matt #define UQUAD_MAX ULLONG_MAX /* max unsigned quad */
71 1.1 matt #define QUAD_MAX LLONG_MAX /* max signed quad */
72 1.1 matt #define QUAD_MIN LLONG_MIN /* min signed quad */
73 1.1 matt
74 1.1 matt #endif /* _NETBSD_SOURCE */
75 1.1 matt #endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
76 1.1 matt
77 1.1 matt #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
78 1.1 matt #define LONG_BIT (__SIZEOF_LONG__ * 8)
79 1.1 matt #define WORD_BIT (__SIZEOF_INT__ * 8)
80 1.1 matt
81 1.1 matt #define DBL_DIG __DBL_DIG__
82 1.1 matt #define DBL_MAX __DBL_MAX__
83 1.1 matt #define DBL_MIN __DBL_MIN__
84 1.1 matt
85 1.1 matt #define FLT_DIG __FLT_DIG__
86 1.1 matt #define FLT_MAX __FLT_MAX__
87 1.1 matt #define FLT_MIN __FLT_MIN__
88 1.1 matt
89 1.1 matt #ifdef __LDBL_DIG__
90 1.1 matt #define LDBL_DIG __LDBL_DIG__
91 1.1 matt #define LDBL_MAX __LDBL_MAX__
92 1.1 matt #define LDBL_MIN __LDBL_MIN__
93 1.1 matt #endif
94 1.1 matt
95 1.1 matt #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
96 1.1 matt
97 1.1 matt #endif /* _SYS_COMMON_LIMITS_H_ */
98