1/* $OpenBSD: limits.h,v 1.10 2012/06/30 20:21:10 guenther Exp $ */ 2/* 3 * Copyright (c) 2002 Marc Espie. 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 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS 15 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD 18 * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26#ifndef _SYS_LIMITS_H_ 27#define _SYS_LIMITS_H_ 28 29#include <sys/cdefs.h> 30 31/* Common definitions for limits.h. */ 32 33/* Legacy */ 34#include <machine/limits.h> 35 36#define CHAR_BIT 8 /* number of bits in a char */ 37 38#define SCHAR_MAX 0x7f /* max value for a signed char */ 39#define SCHAR_MIN (-0x7f-1) /* min value for a signed char */ 40 41#define UCHAR_MAX 0xff /* max value for an unsigned char */ 42#ifdef __CHAR_UNSIGNED__ 43# define CHAR_MIN 0 /* min value for a char */ 44# define CHAR_MAX 0xff /* max value for a char */ 45#else 46# define CHAR_MAX 0x7f 47# define CHAR_MIN (-0x7f-1) 48#endif 49 50#define MB_LEN_MAX 4 /* Allow UTF-8 (RFC 3629) */ 51 52#define USHRT_MAX 0xffff /* max value for an unsigned short */ 53#define SHRT_MAX 0x7fff /* max value for a short */ 54#define SHRT_MIN (-0x7fff-1) /* min value for a short */ 55 56#define UINT_MAX 0xffffffffU /* max value for an unsigned int */ 57#define INT_MAX 0x7fffffff /* max value for an int */ 58#define INT_MIN (-0x7fffffff-1) /* min value for an int */ 59 60#ifdef __LP64__ 61# define ULONG_MAX 0xffffffffffffffffUL 62 /* max value for unsigned long */ 63# define LONG_MAX 0x7fffffffffffffffL 64 /* max value for a signed long */ 65# define LONG_MIN (-0x7fffffffffffffffL-1) 66 /* min value for a signed long */ 67#else 68# define ULONG_MAX 0xffffffffUL /* max value for an unsigned long */ 69# define LONG_MAX 0x7fffffffL /* max value for a long */ 70# define LONG_MIN (-0x7fffffffL-1)/* min value for a long */ 71#endif 72 73#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 74# define ULLONG_MAX 0xffffffffffffffffULL 75 /* max value for unsigned long long */ 76# define LLONG_MAX 0x7fffffffffffffffLL 77 /* max value for a signed long long */ 78# define LLONG_MIN (-0x7fffffffffffffffLL-1) 79 /* min value for a signed long long */ 80#endif 81 82#if __BSD_VISIBLE 83# define UID_MAX UINT_MAX /* max value for a uid_t */ 84# define GID_MAX UINT_MAX /* max value for a gid_t */ 85#endif 86 87#if __XPG_VISIBLE || __POSIX_VISIBLE >= 200809 88# ifdef __LP64__ 89# define LONG_BIT 64 90# else 91# define LONG_BIT 32 92# endif 93# define WORD_BIT 32 94#endif 95 96#if __XPG_VISIBLE < 600 97# include <machine/_float.h> 98 99/* XSI defines marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001 */ 100# ifndef FLT_DIG 101# define FLT_DIG __FLT_DIG 102# endif 103# ifndef FLT_MAX 104# define FLT_MAX __FLT_MAX 105# endif 106# ifndef DBL_DIG 107# define DBL_DIG __DBL_DIG 108# endif 109# ifndef DBL_MAX 110# define DBL_MAX __DBL_MAX 111# endif 112 113/* XSI defines marked LEGACY in XPG4v2 and removed in XPG5 */ 114# if __XPG_VISIBLE < 500 115# ifndef FLT_MIN 116# define FLT_MIN __FLT_MIN 117# endif 118# ifndef DBL_MIN 119# define DBL_MIN __DBL_MIN 120# endif 121# endif 122 123#endif /* __XPG_VISIBLE < 600 */ 124 125#endif 126