1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mfbt/MSIntTypes.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,198 @@ 1.4 +// ISO C9x compliant inttypes.h for Microsoft Visual Studio 1.5 +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 1.6 +// 1.7 +// Copyright (c) 2006 Alexander Chemeris 1.8 +// 1.9 +// Redistribution and use in source and binary forms, with or without 1.10 +// modification, are permitted provided that the following conditions are met: 1.11 +// 1.12 +// 1. Redistributions of source code must retain the above copyright notice, 1.13 +// this list of conditions and the following disclaimer. 1.14 +// 1.15 +// 2. Redistributions in binary form must reproduce the above copyright 1.16 +// notice, this list of conditions and the following disclaimer in the 1.17 +// documentation and/or other materials provided with the distribution. 1.18 +// 1.19 +// 3. The name of the author may be used to endorse or promote products 1.20 +// derived from this software without specific prior written permission. 1.21 +// 1.22 +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 1.23 +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1.24 +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 1.25 +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.27 +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 1.28 +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 1.29 +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 1.30 +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 1.31 +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.32 +// 1.33 +/////////////////////////////////////////////////////////////////////////////// 1.34 + 1.35 +#ifndef _MSC_VER // [ 1.36 +#error "Use this header only with Microsoft Visual C++ compilers!" 1.37 +#endif // _MSC_VER ] 1.38 + 1.39 +#ifndef _MSC_INTTYPES_H_ // [ 1.40 +#define _MSC_INTTYPES_H_ 1.41 + 1.42 +#if _MSC_VER > 1000 1.43 +#pragma once 1.44 +#endif 1.45 + 1.46 +#include <stdint.h> 1.47 + 1.48 +// 7.8 Format conversion of integer types 1.49 + 1.50 +typedef struct { 1.51 + intmax_t quot; 1.52 + intmax_t rem; 1.53 +} imaxdiv_t; 1.54 + 1.55 +// 7.8.1 Macros for format specifiers 1.56 + 1.57 +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 1.58 + 1.59 +// The fprintf macros for signed integers are: 1.60 +#define PRId8 "d" 1.61 +#define PRIi8 "i" 1.62 +#define PRIdLEAST8 "d" 1.63 +#define PRIiLEAST8 "i" 1.64 +#define PRIdFAST8 "d" 1.65 +#define PRIiFAST8 "i" 1.66 + 1.67 +#define PRId16 "hd" 1.68 +#define PRIi16 "hi" 1.69 +#define PRIdLEAST16 "hd" 1.70 +#define PRIiLEAST16 "hi" 1.71 +#define PRIdFAST16 "hd" 1.72 +#define PRIiFAST16 "hi" 1.73 + 1.74 +#define PRId32 "I32d" 1.75 +#define PRIi32 "I32i" 1.76 +#define PRIdLEAST32 "I32d" 1.77 +#define PRIiLEAST32 "I32i" 1.78 +#define PRIdFAST32 "I32d" 1.79 +#define PRIiFAST32 "I32i" 1.80 + 1.81 +#define PRId64 "I64d" 1.82 +#define PRIi64 "I64i" 1.83 +#define PRIdLEAST64 "I64d" 1.84 +#define PRIiLEAST64 "I64i" 1.85 +#define PRIdFAST64 "I64d" 1.86 +#define PRIiFAST64 "I64i" 1.87 + 1.88 +#define PRIdMAX "I64d" 1.89 +#define PRIiMAX "I64i" 1.90 + 1.91 +#define PRIdPTR "Id" 1.92 +#define PRIiPTR "Ii" 1.93 + 1.94 +// The fprintf macros for unsigned integers are: 1.95 +#define PRIo8 "o" 1.96 +#define PRIu8 "u" 1.97 +#define PRIx8 "x" 1.98 +#define PRIX8 "X" 1.99 +#define PRIoLEAST8 "o" 1.100 +#define PRIuLEAST8 "u" 1.101 +#define PRIxLEAST8 "x" 1.102 +#define PRIXLEAST8 "X" 1.103 +#define PRIoFAST8 "o" 1.104 +#define PRIuFAST8 "u" 1.105 +#define PRIxFAST8 "x" 1.106 +#define PRIXFAST8 "X" 1.107 + 1.108 +#define PRIo16 "ho" 1.109 +#define PRIu16 "hu" 1.110 +#define PRIx16 "hx" 1.111 +#define PRIX16 "hX" 1.112 +#define PRIoLEAST16 "ho" 1.113 +#define PRIuLEAST16 "hu" 1.114 +#define PRIxLEAST16 "hx" 1.115 +#define PRIXLEAST16 "hX" 1.116 +#define PRIoFAST16 "ho" 1.117 +#define PRIuFAST16 "hu" 1.118 +#define PRIxFAST16 "hx" 1.119 +#define PRIXFAST16 "hX" 1.120 + 1.121 +#define PRIo32 "I32o" 1.122 +#define PRIu32 "I32u" 1.123 +#define PRIx32 "I32x" 1.124 +#define PRIX32 "I32X" 1.125 +#define PRIoLEAST32 "I32o" 1.126 +#define PRIuLEAST32 "I32u" 1.127 +#define PRIxLEAST32 "I32x" 1.128 +#define PRIXLEAST32 "I32X" 1.129 +#define PRIoFAST32 "I32o" 1.130 +#define PRIuFAST32 "I32u" 1.131 +#define PRIxFAST32 "I32x" 1.132 +#define PRIXFAST32 "I32X" 1.133 + 1.134 +#define PRIo64 "I64o" 1.135 +#define PRIu64 "I64u" 1.136 +#define PRIx64 "I64x" 1.137 +#define PRIX64 "I64X" 1.138 +#define PRIoLEAST64 "I64o" 1.139 +#define PRIuLEAST64 "I64u" 1.140 +#define PRIxLEAST64 "I64x" 1.141 +#define PRIXLEAST64 "I64X" 1.142 +#define PRIoFAST64 "I64o" 1.143 +#define PRIuFAST64 "I64u" 1.144 +#define PRIxFAST64 "I64x" 1.145 +#define PRIXFAST64 "I64X" 1.146 + 1.147 +#define PRIoMAX "I64o" 1.148 +#define PRIuMAX "I64u" 1.149 +#define PRIxMAX "I64x" 1.150 +#define PRIXMAX "I64X" 1.151 + 1.152 +#define PRIoPTR "Io" 1.153 +#define PRIuPTR "Iu" 1.154 +#define PRIxPTR "Ix" 1.155 +#define PRIXPTR "IX" 1.156 + 1.157 +// DO NOT SUPPORT THE scanf MACROS! See the comment at the top of 1.158 +// IntegerPrintfMacros.h. 1.159 + 1.160 +#endif // __STDC_FORMAT_MACROS ] 1.161 + 1.162 +// 7.8.2 Functions for greatest-width integer types 1.163 + 1.164 +// 7.8.2.1 The imaxabs function 1.165 +#define imaxabs _abs64 1.166 + 1.167 +// 7.8.2.2 The imaxdiv function 1.168 + 1.169 +// This is modified version of div() function from Microsoft's div.c found 1.170 +// in %MSVC.NET%\crt\src\div.c 1.171 +#ifdef STATIC_IMAXDIV // [ 1.172 +static 1.173 +#else // STATIC_IMAXDIV ][ 1.174 +_inline 1.175 +#endif // STATIC_IMAXDIV ] 1.176 +imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) 1.177 +{ 1.178 + imaxdiv_t result; 1.179 + 1.180 + result.quot = numer / denom; 1.181 + result.rem = numer % denom; 1.182 + 1.183 + if (numer < 0 && result.rem > 0) { 1.184 + // did division wrong; must fix up 1.185 + ++result.quot; 1.186 + result.rem -= denom; 1.187 + } 1.188 + 1.189 + return result; 1.190 +} 1.191 + 1.192 +// 7.8.2.3 The strtoimax and strtoumax functions 1.193 +#define strtoimax _strtoi64 1.194 +#define strtoumax _strtoui64 1.195 + 1.196 +// 7.8.2.4 The wcstoimax and wcstoumax functions 1.197 +#define wcstoimax _wcstoi64 1.198 +#define wcstoumax _wcstoui64 1.199 + 1.200 + 1.201 +#endif // _MSC_INTTYPES_H_ ]