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