kusano 7d535a
/**
kusano 7d535a
 * This file has no copyright assigned and is placed in the Public Domain.
kusano 7d535a
 * This file was originally part of the w64 mingw-runtime package.
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
/* ISO C9x  7.18  Integer types <stdint.h></stdint.h>
kusano 7d535a
 * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
kusano 7d535a
 *
kusano 7d535a
 *  THIS SOFTWARE IS NOT COPYRIGHTED
kusano 7d535a
 *
kusano 7d535a
 *  Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz></danny_r_smith_2001@yahoo.co.nz>
kusano 7d535a
 *  Modified for libusb/MSVC: Pete Batard <pbatard@gmail.com></pbatard@gmail.com>
kusano 7d535a
 *
kusano 7d535a
 *  This source code is offered for use in the public domain. You may
kusano 7d535a
 *  use, modify or distribute it freely.
kusano 7d535a
 *
kusano 7d535a
 *  This code is distributed in the hope that it will be useful but
kusano 7d535a
 *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
kusano 7d535a
 *  DISCLAIMED. This includes but is not limited to warranties of
kusano 7d535a
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
kusano 7d535a
 *
kusano 7d535a
 *  Date: 2010-04-02
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
#ifndef _MSC_VER
kusano 7d535a
#error This header should only be used with Microsoft compilers
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifndef _STDINT_H
kusano 7d535a
#define _STDINT_H
kusano 7d535a
kusano 7d535a
#ifndef _INTPTR_T_DEFINED
kusano 7d535a
#define _INTPTR_T_DEFINED
kusano 7d535a
#ifndef __intptr_t_defined
kusano 7d535a
#define __intptr_t_defined
kusano 7d535a
#undef intptr_t
kusano 7d535a
#ifdef _WIN64
kusano 7d535a
  typedef __int64 intptr_t;
kusano 7d535a
#else
kusano 7d535a
  typedef int intptr_t;
kusano 7d535a
#endif /* _WIN64 */
kusano 7d535a
#endif /* __intptr_t_defined */
kusano 7d535a
#endif /* _INTPTR_T_DEFINED */
kusano 7d535a
kusano 7d535a
#ifndef _UINTPTR_T_DEFINED
kusano 7d535a
#define _UINTPTR_T_DEFINED
kusano 7d535a
#ifndef __uintptr_t_defined
kusano 7d535a
#define __uintptr_t_defined
kusano 7d535a
#undef uintptr_t
kusano 7d535a
#ifdef _WIN64
kusano 7d535a
  typedef unsigned __int64 uintptr_t;
kusano 7d535a
#else
kusano 7d535a
  typedef unsigned int uintptr_t;
kusano 7d535a
#endif /* _WIN64 */
kusano 7d535a
#endif /* __uintptr_t_defined */
kusano 7d535a
#endif /* _UINTPTR_T_DEFINED */
kusano 7d535a
kusano 7d535a
#ifndef _PTRDIFF_T_DEFINED
kusano 7d535a
#define _PTRDIFF_T_DEFINED
kusano 7d535a
#ifndef _PTRDIFF_T_
kusano 7d535a
#define _PTRDIFF_T_
kusano 7d535a
#undef ptrdiff_t
kusano 7d535a
#ifdef _WIN64
kusano 7d535a
  typedef __int64 ptrdiff_t;
kusano 7d535a
#else
kusano 7d535a
  typedef int ptrdiff_t;
kusano 7d535a
#endif /* _WIN64 */
kusano 7d535a
#endif /* _PTRDIFF_T_ */
kusano 7d535a
#endif /* _PTRDIFF_T_DEFINED */
kusano 7d535a
kusano 7d535a
#ifndef _WCHAR_T_DEFINED
kusano 7d535a
#define _WCHAR_T_DEFINED
kusano 7d535a
#ifndef __cplusplus
kusano 7d535a
  typedef unsigned short wchar_t;
kusano 7d535a
#endif /* C++ */
kusano 7d535a
#endif /* _WCHAR_T_DEFINED */
kusano 7d535a
kusano 7d535a
#ifndef _WCTYPE_T_DEFINED
kusano 7d535a
#define _WCTYPE_T_DEFINED
kusano 7d535a
#ifndef _WINT_T
kusano 7d535a
#define _WINT_T
kusano 7d535a
  typedef unsigned short wint_t;
kusano 7d535a
  typedef unsigned short wctype_t;
kusano 7d535a
#endif /* _WINT_T */
kusano 7d535a
#endif /* _WCTYPE_T_DEFINED */
kusano 7d535a
kusano 7d535a
/* 7.18.1.1  Exact-width integer types */
kusano 7d535a
typedef __int8 int8_t;
kusano 7d535a
typedef unsigned __int8   uint8_t;
kusano 7d535a
typedef __int16  int16_t;
kusano 7d535a
typedef unsigned __int16  uint16_t;
kusano 7d535a
typedef __int32  int32_t;
kusano 7d535a
typedef unsigned __int32  uint32_t;
kusano 7d535a
typedef __int64  int64_t;
kusano 7d535a
typedef unsigned __int64   uint64_t;
kusano 7d535a
kusano 7d535a
/* 7.18.1.2  Minimum-width integer types */
kusano 7d535a
typedef signed char int_least8_t;
kusano 7d535a
typedef unsigned char   uint_least8_t;
kusano 7d535a
typedef short  int_least16_t;
kusano 7d535a
typedef unsigned short  uint_least16_t;
kusano 7d535a
typedef int  int_least32_t;
kusano 7d535a
typedef unsigned   uint_least32_t;
kusano 7d535a
typedef __int64  int_least64_t;
kusano 7d535a
typedef unsigned __int64   uint_least64_t;
kusano 7d535a
kusano 7d535a
/*  7.18.1.3  Fastest minimum-width integer types
kusano 7d535a
 *  Not actually guaranteed to be fastest for all purposes
kusano 7d535a
 *  Here we use the exact-width types for 8 and 16-bit ints.
kusano 7d535a
 */
kusano 7d535a
typedef __int8 int_fast8_t;
kusano 7d535a
typedef unsigned __int8 uint_fast8_t;
kusano 7d535a
typedef __int16  int_fast16_t;
kusano 7d535a
typedef unsigned __int16  uint_fast16_t;
kusano 7d535a
typedef __int32  int_fast32_t;
kusano 7d535a
typedef unsigned  __int32  uint_fast32_t;
kusano 7d535a
typedef __int64  int_fast64_t;
kusano 7d535a
typedef unsigned __int64   uint_fast64_t;
kusano 7d535a
kusano 7d535a
/* 7.18.1.5  Greatest-width integer types */
kusano 7d535a
typedef __int64  intmax_t;
kusano 7d535a
typedef unsigned __int64   uintmax_t;
kusano 7d535a
kusano 7d535a
/* 7.18.2  Limits of specified-width integer types */
kusano 7d535a
kusano 7d535a
/* 7.18.2.1  Limits of exact-width integer types */
kusano 7d535a
#define INT8_MIN (-128)
kusano 7d535a
#define INT16_MIN (-32768)
kusano 7d535a
#define INT32_MIN (-2147483647 - 1)
kusano 7d535a
#define INT64_MIN  (-9223372036854775807LL - 1)
kusano 7d535a
kusano 7d535a
#define INT8_MAX 127
kusano 7d535a
#define INT16_MAX 32767
kusano 7d535a
#define INT32_MAX 2147483647
kusano 7d535a
#define INT64_MAX 9223372036854775807LL
kusano 7d535a
kusano 7d535a
#define UINT8_MAX 255
kusano 7d535a
#define UINT16_MAX 65535
kusano 7d535a
#define UINT32_MAX 0xffffffffU  /* 4294967295U */
kusano 7d535a
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
kusano 7d535a
kusano 7d535a
/* 7.18.2.2  Limits of minimum-width integer types */
kusano 7d535a
#define INT_LEAST8_MIN INT8_MIN
kusano 7d535a
#define INT_LEAST16_MIN INT16_MIN
kusano 7d535a
#define INT_LEAST32_MIN INT32_MIN
kusano 7d535a
#define INT_LEAST64_MIN INT64_MIN
kusano 7d535a
kusano 7d535a
#define INT_LEAST8_MAX INT8_MAX
kusano 7d535a
#define INT_LEAST16_MAX INT16_MAX
kusano 7d535a
#define INT_LEAST32_MAX INT32_MAX
kusano 7d535a
#define INT_LEAST64_MAX INT64_MAX
kusano 7d535a
kusano 7d535a
#define UINT_LEAST8_MAX UINT8_MAX
kusano 7d535a
#define UINT_LEAST16_MAX UINT16_MAX
kusano 7d535a
#define UINT_LEAST32_MAX UINT32_MAX
kusano 7d535a
#define UINT_LEAST64_MAX UINT64_MAX
kusano 7d535a
kusano 7d535a
/* 7.18.2.3  Limits of fastest minimum-width integer types */
kusano 7d535a
#define INT_FAST8_MIN INT8_MIN
kusano 7d535a
#define INT_FAST16_MIN INT16_MIN
kusano 7d535a
#define INT_FAST32_MIN INT32_MIN
kusano 7d535a
#define INT_FAST64_MIN INT64_MIN
kusano 7d535a
kusano 7d535a
#define INT_FAST8_MAX INT8_MAX
kusano 7d535a
#define INT_FAST16_MAX INT16_MAX
kusano 7d535a
#define INT_FAST32_MAX INT32_MAX
kusano 7d535a
#define INT_FAST64_MAX INT64_MAX
kusano 7d535a
kusano 7d535a
#define UINT_FAST8_MAX UINT8_MAX
kusano 7d535a
#define UINT_FAST16_MAX UINT16_MAX
kusano 7d535a
#define UINT_FAST32_MAX UINT32_MAX
kusano 7d535a
#define UINT_FAST64_MAX UINT64_MAX
kusano 7d535a
kusano 7d535a
/* 7.18.2.4  Limits of integer types capable of holding
kusano 7d535a
    object pointers */
kusano 7d535a
#ifdef _WIN64
kusano 7d535a
#define INTPTR_MIN INT64_MIN
kusano 7d535a
#define INTPTR_MAX INT64_MAX
kusano 7d535a
#define UINTPTR_MAX UINT64_MAX
kusano 7d535a
#else
kusano 7d535a
#define INTPTR_MIN INT32_MIN
kusano 7d535a
#define INTPTR_MAX INT32_MAX
kusano 7d535a
#define UINTPTR_MAX UINT32_MAX
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
/* 7.18.2.5  Limits of greatest-width integer types */
kusano 7d535a
#define INTMAX_MIN INT64_MIN
kusano 7d535a
#define INTMAX_MAX INT64_MAX
kusano 7d535a
#define UINTMAX_MAX UINT64_MAX
kusano 7d535a
kusano 7d535a
/* 7.18.3  Limits of other integer types */
kusano 7d535a
#ifdef _WIN64
kusano 7d535a
#define PTRDIFF_MIN INT64_MIN
kusano 7d535a
#define PTRDIFF_MAX INT64_MAX
kusano 7d535a
#else
kusano 7d535a
#define PTRDIFF_MIN INT32_MIN
kusano 7d535a
#define PTRDIFF_MAX INT32_MAX
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#define SIG_ATOMIC_MIN INT32_MIN
kusano 7d535a
#define SIG_ATOMIC_MAX INT32_MAX
kusano 7d535a
kusano 7d535a
#ifndef SIZE_MAX
kusano 7d535a
#ifdef _WIN64
kusano 7d535a
#define SIZE_MAX UINT64_MAX
kusano 7d535a
#else
kusano 7d535a
#define SIZE_MAX UINT32_MAX
kusano 7d535a
#endif
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#ifndef WCHAR_MIN  /* also in wchar.h */
kusano 7d535a
#define WCHAR_MIN 0U
kusano 7d535a
#define WCHAR_MAX 0xffffU
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
 * wint_t is unsigned short for compatibility with MS runtime
kusano 7d535a
 */
kusano 7d535a
#define WINT_MIN 0U
kusano 7d535a
#define WINT_MAX 0xffffU
kusano 7d535a
kusano 7d535a
kusano 7d535a
/* 7.18.4  Macros for integer constants */
kusano 7d535a
kusano 7d535a
/* 7.18.4.1  Macros for minimum-width integer constants
kusano 7d535a
kusano 7d535a
    Accoding to Douglas Gwyn <gwyn@arl.mil>:</gwyn@arl.mil>
kusano 7d535a
	"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
kusano 7d535a
	9899:1999 as initially published, the expansion was required
kusano 7d535a
	to be an integer constant of precisely matching type, which
kusano 7d535a
	is impossible to accomplish for the shorter types on most
kusano 7d535a
	platforms, because C99 provides no standard way to designate
kusano 7d535a
	an integer constant with width less than that of type int.
kusano 7d535a
	TC1 changed this to require just an integer constant
kusano 7d535a
	*expression* with *promoted* type."
kusano 7d535a
kusano 7d535a
	The trick used here is from Clive D W Feather.
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val))
kusano 7d535a
#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val))
kusano 7d535a
#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val))
kusano 7d535a
/*  The 'trick' doesn't work in C89 for long long because, without
kusano 7d535a
    suffix, (val) will be evaluated as int, not intmax_t */
kusano 7d535a
#define INT64_C(val) val##i64
kusano 7d535a
kusano 7d535a
#define UINT8_C(val) (val)
kusano 7d535a
#define UINT16_C(val) (val)
kusano 7d535a
#define UINT32_C(val) (val##i32)
kusano 7d535a
#define UINT64_C(val) val##ui64
kusano 7d535a
kusano 7d535a
/* 7.18.4.2  Macros for greatest-width integer constants */
kusano 7d535a
#define INTMAX_C(val) val##i64
kusano 7d535a
#define UINTMAX_C(val) val##ui64
kusano 7d535a
kusano 7d535a
#endif