Home | History | Annotate | Line # | Download | only in sys
common_limits.h revision 1.3
      1  1.3  dholland /*	$NetBSD: common_limits.h,v 1.3 2019/01/21 20:29:27 dholland 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.1      matt #define	CHAR_BIT	__CHAR_BIT__	/* number of bits in a char */
     36  1.1      matt 
     37  1.2      matt #define SCHAR_MIN	(-__SCHAR_MAX__-1) /* min value for a signed char */
     38  1.1      matt #define	SCHAR_MAX	__SCHAR_MAX__	/* max value for a signed char */
     39  1.2      matt #define	UCHAR_MAX	(2*SCHAR_MAX+1)	/* max value for an unsigned char */
     40  1.1      matt 
     41  1.2      matt #define	SHRT_MIN	(-__SHRT_MAX__-1) /* min value for a short */
     42  1.1      matt #define	SHRT_MAX	__SHRT_MAX__	/* max value for a short */
     43  1.2      matt #define	USHRT_MAX	(2*SHRT_MAX+1)	/* max value for an unsigned short */
     44  1.1      matt 
     45  1.2      matt #define	INT_MIN		(-__INT_MAX__-1) /* min value for an int */
     46  1.1      matt #define	INT_MAX		__INT_MAX__	/* max value for an int */
     47  1.2      matt #define	UINT_MAX	(2U*INT_MAX+1U)	/* max value for an unsigned int */
     48  1.1      matt 
     49  1.2      matt #define	LONG_MIN	(-__LONG_MAX__-1L)	/* min value for a long */
     50  1.2      matt #define	LONG_MAX	__LONG_MAX__		/* max value for a long */
     51  1.2      matt #define	ULONG_MAX	(2UL*LONG_MAX+1UL)	/* max unsigned long */
     52  1.1      matt 
     53  1.1      matt #if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
     54  1.1      matt     defined(_NETBSD_SOURCE)
     55  1.2      matt #define	LLONG_MIN	(-__LONG_LONG_MAX__-1LL) /* min signed long long */
     56  1.1      matt #define	LLONG_MAX	__LONG_LONG_MAX__	/* max signed long long */
     57  1.2      matt #define	ULLONG_MAX	(2ULL*LLONG_MAX+1ULL)	/* max unsigned long long */
     58  1.1      matt #endif
     59  1.1      matt 
     60  1.3  dholland #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
     61  1.3  dholland     defined(_NETBSD_SOURCE)
     62  1.3  dholland #define	SSIZE_MAX	LONG_MAX	/* max value for a ssize_t */
     63  1.3  dholland 
     64  1.1      matt #if defined(_NETBSD_SOURCE)
     65  1.1      matt #define	SSIZE_MIN	LONG_MIN	/* min value for a ssize_t */
     66  1.1      matt #define	SIZE_T_MAX	ULONG_MAX	/* max value for a size_t */
     67  1.1      matt 
     68  1.1      matt #define	UQUAD_MAX	ULLONG_MAX	/* max unsigned quad */
     69  1.1      matt #define	QUAD_MAX	LLONG_MAX	/* max signed quad */
     70  1.1      matt #define	QUAD_MIN	LLONG_MIN	/* min signed quad */
     71  1.1      matt 
     72  1.1      matt #endif /* _NETBSD_SOURCE */
     73  1.1      matt #endif /* _POSIX_C_SOURCE || _XOPEN_SOURCE || _NETBSD_SOURCE */
     74  1.1      matt 
     75  1.1      matt #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
     76  1.1      matt #define LONG_BIT	(__SIZEOF_LONG__ * 8)
     77  1.1      matt #define WORD_BIT	(__SIZEOF_INT__ * 8)
     78  1.1      matt 
     79  1.1      matt #define DBL_DIG		__DBL_DIG__
     80  1.1      matt #define DBL_MAX		__DBL_MAX__
     81  1.1      matt #define DBL_MIN		__DBL_MIN__
     82  1.1      matt 
     83  1.1      matt #define FLT_DIG		__FLT_DIG__
     84  1.1      matt #define FLT_MAX		__FLT_MAX__
     85  1.1      matt #define FLT_MIN		__FLT_MIN__
     86  1.1      matt 
     87  1.1      matt #ifdef __LDBL_DIG__
     88  1.1      matt #define LDBL_DIG	__LDBL_DIG__
     89  1.1      matt #define LDBL_MAX	__LDBL_MAX__
     90  1.1      matt #define LDBL_MIN	__LDBL_MIN__
     91  1.1      matt #endif
     92  1.1      matt 
     93  1.1      matt #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
     94  1.1      matt 
     95  1.1      matt #endif /* _SYS_COMMON_LIMITS_H_ */
     96