/* Metrowerks Standard Library
 * Copyright  1995-2004 Metrowerks Corporation.  All rights reserved.
 *
 * $Date: 2004/04/06 18:34:25 $
 * $Revision: 1.43 $
 */

#ifndef _MSL_CLIMITS
#define _MSL_CLIMITS

#include <ansi_parms.h>

#if !_MSL_USING_MW_C_HEADERS
	#include <limits.h>
#else

#ifndef RC_INVOKED  						/*- hh 971230 -*/

#if __dest_os == __mac_os_x
	#include <machine/limits.h>
	
	#undef CHAR_BIT
	#undef MB_LEN_MAX
	#undef SCHAR_MAX
	#undef SCHAR_MIN
	#undef UCHAR_MAX
	#undef CHAR_MAX
	#undef CHAR_MIN
	#undef USHRT_MAX
	#undef SHRT_MAX
	#undef SHRT_MIN
	#undef UINT_MAX
	#undef INT_MAX
	#undef INT_MIN
	#undef ULONG_MAX
	#undef LONG_MAX
	#undef LONG_MIN
	#undef ULLONG_MAX
	#undef LLONG_MAX
	#undef LLONG_MIN
#endif

/* Default configuration */

#ifndef _CHAR_BIT
	#define _CHAR_BIT				8
#endif

#ifndef _SIZEOF_SHRT
	#define _SIZEOF_SHRT			2
#endif

#ifndef _SIZEOF_INT
	#define _SIZEOF_INT				4
#endif

#ifndef _SIZEOF_LONG
	#define _SIZEOF_LONG			4
#endif

#ifndef _MSL_MB_LEN_MAX
	#define _MSL_MB_LEN_MAX			3
#endif

#if _MSL_LONGLONG
	#ifndef _SIZEOF_LONG_LONG
		#define _SIZEOF_LONG_LONG	8
	#endif
#endif

#ifndef _MSL_UNSIGNED_CHAR
	#ifdef __MWERKS__
		#if __option(unsigned_char)
			#define _MSL_UNSIGNED_CHAR 1
		#else
			#define _MSL_UNSIGNED_CHAR 0
		#endif
	#else
		#define _MSL_UNSIGNED_CHAR 0
	#endif
#endif

/* Build macros based  on platform configuration */

#define MB_LEN_MAX					_MSL_MB_LEN_MAX
#define CHAR_BIT					_CHAR_BIT

#if CHAR_BIT == 8
	#define SCHAR_MAX				0x7f
	#define UCHAR_MAX				0xff
#elif CHAR_BIT == 16
	#define SCHAR_MAX				0x7fff
	#define UCHAR_MAX				0xffff
#elif CHAR_BIT == 24
	#define SCHAR_MAX				0x7fffff
	#define UCHAR_MAX				0xffffff
#else
	#error unsupported size for CHAR_BIT
#endif

#define SCHAR_MIN					(~SCHAR_MAX)

#if _MSL_UNSIGNED_CHAR
	#define CHAR_MIN				0
	#define CHAR_MAX				UCHAR_MAX
#else
	#define CHAR_MIN				SCHAR_MIN
	#define CHAR_MAX				SCHAR_MAX
#endif

#if _SIZEOF_SHRT*CHAR_BIT == 16
	#define SHRT_MAX				0x7fff
	#define USHRT_MAX				0xffff
#elif _SIZEOF_SHRT*CHAR_BIT == 24
	#define SHRT_MAX				0x7fffff
	#define USHRT_MAX				0xffffff
#else
	#error unsupported size for sizeof short
#endif

#define SHRT_MIN					(~SHRT_MAX)

#if _SIZEOF_INT*CHAR_BIT == 16
	#define INT_MAX					0x7fff
	#define UINT_MAX				0xffffU
#elif _SIZEOF_INT*CHAR_BIT == 24
	#define INT_MAX					0x7fffff
	#define UINT_MAX				0xffffffU
#elif _SIZEOF_INT*CHAR_BIT == 32
	#define INT_MAX					0x7fffffff
	#define UINT_MAX				0xffffffffU
#else
	#error unsupported size for sizeof int
#endif

#define INT_MIN						(~INT_MAX)

#if _SIZEOF_LONG*CHAR_BIT == 24
	#define LONG_MAX				0x7fffffL
	#define ULONG_MAX				0xffffffUL
#elif _SIZEOF_LONG*CHAR_BIT == 32
	#define LONG_MAX				0x7fffffffL
	#define ULONG_MAX				0xffffffffUL
#else
	#error unsupported size for sizeof long
#endif

#define LONG_MIN					(~LONG_MAX)

#if _MSL_LONGLONG && _MSL_C99
	#if _SIZEOF_LONG_LONG*CHAR_BIT == 24
		#define LLONG_MAX			0x7fffffLL
		#define ULLONG_MAX			0xffffffULL
	#elif _SIZEOF_LONG_LONG*CHAR_BIT == 32
		#define LLONG_MAX			0x7fffffffLL
		#define ULLONG_MAX			0xffffffffULL
	#elif _SIZEOF_LONG_LONG*CHAR_BIT == 64
		#define LLONG_MAX			0x7fffffffffffffffLL
		#define ULLONG_MAX			0xffffffffffffffffULL
	#else
		#error unsupported size for sizeof long long
	#endif
	
	#define LLONG_MIN				(~LLONG_MAX)
#endif

#endif /* RC_INVOKED */

#endif /* _MSL_USING_MW_C_HEADERS */

#endif /* _MSL_CLIMITS */

/* Change record: 
 * bkoz961216 line 49 added long long typedefs
 * bkoz970214 added default __dest_os __mac_os
 * mm  970804 Added include of ansi_parms.h to ensure __mac_os, __be_os, etc are defined.
 * hh  971206 Changed filename from limits.h to climits and added namespace support
 * hh  971230 added RC_INVOKED wrapper
 * hh  980107 changed names of long long macros to support standard
 * mm  981014 Added specifications for DSP568
 * mm  981029 Changed __DSP568 to __m56800__
 * mm  981104 Added definition of ints for mc568000
 * mm  000201 Corrected CHAR_MAX and CHAR_MIN to allow for "use unsigned char" option
 * JWW 001208 Added case for targeting Mach-O
 * mm  010303 Added missing integer suffixes WB1-20337
 * cc  000326 removed dest_os to be_os 
 * hh  010402 Rewrite
 * mm  010523 UTF-8 implementation
 * JWW 011027 Use _MSL_USING_MW_C_HEADERS as generic header test instead of specific Mach-O test
 * hh  021014 Removed U suffix from CHAR_MIN, UCHAR_MAX and USHRT_MAX
 * JWW 030224 Changed __MSL_LONGLONG_SUPPORT__ flag into the new more configurable _MSL_LONGLONG
 * mm  030225 Added _MSL_C99 wrappers for LLONG_MAX, ULLONG_MAX and LLONG_MIN
 * cc  030414 Added check for __MWERKS__
 */