mfbt/MSIntTypes.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 // ISO C9x compliant inttypes.h for Microsoft Visual Studio
michael@0 2 // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
michael@0 3 //
michael@0 4 // Copyright (c) 2006 Alexander Chemeris
michael@0 5 //
michael@0 6 // Redistribution and use in source and binary forms, with or without
michael@0 7 // modification, are permitted provided that the following conditions are met:
michael@0 8 //
michael@0 9 // 1. Redistributions of source code must retain the above copyright notice,
michael@0 10 // this list of conditions and the following disclaimer.
michael@0 11 //
michael@0 12 // 2. Redistributions in binary form must reproduce the above copyright
michael@0 13 // notice, this list of conditions and the following disclaimer in the
michael@0 14 // documentation and/or other materials provided with the distribution.
michael@0 15 //
michael@0 16 // 3. The name of the author may be used to endorse or promote products
michael@0 17 // derived from this software without specific prior written permission.
michael@0 18 //
michael@0 19 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
michael@0 20 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@0 21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
michael@0 22 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
michael@0 25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
michael@0 26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
michael@0 27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
michael@0 28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29 //
michael@0 30 ///////////////////////////////////////////////////////////////////////////////
michael@0 31
michael@0 32 #ifndef _MSC_VER // [
michael@0 33 #error "Use this header only with Microsoft Visual C++ compilers!"
michael@0 34 #endif // _MSC_VER ]
michael@0 35
michael@0 36 #ifndef _MSC_INTTYPES_H_ // [
michael@0 37 #define _MSC_INTTYPES_H_
michael@0 38
michael@0 39 #if _MSC_VER > 1000
michael@0 40 #pragma once
michael@0 41 #endif
michael@0 42
michael@0 43 #include <stdint.h>
michael@0 44
michael@0 45 // 7.8 Format conversion of integer types
michael@0 46
michael@0 47 typedef struct {
michael@0 48 intmax_t quot;
michael@0 49 intmax_t rem;
michael@0 50 } imaxdiv_t;
michael@0 51
michael@0 52 // 7.8.1 Macros for format specifiers
michael@0 53
michael@0 54 #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
michael@0 55
michael@0 56 // The fprintf macros for signed integers are:
michael@0 57 #define PRId8 "d"
michael@0 58 #define PRIi8 "i"
michael@0 59 #define PRIdLEAST8 "d"
michael@0 60 #define PRIiLEAST8 "i"
michael@0 61 #define PRIdFAST8 "d"
michael@0 62 #define PRIiFAST8 "i"
michael@0 63
michael@0 64 #define PRId16 "hd"
michael@0 65 #define PRIi16 "hi"
michael@0 66 #define PRIdLEAST16 "hd"
michael@0 67 #define PRIiLEAST16 "hi"
michael@0 68 #define PRIdFAST16 "hd"
michael@0 69 #define PRIiFAST16 "hi"
michael@0 70
michael@0 71 #define PRId32 "I32d"
michael@0 72 #define PRIi32 "I32i"
michael@0 73 #define PRIdLEAST32 "I32d"
michael@0 74 #define PRIiLEAST32 "I32i"
michael@0 75 #define PRIdFAST32 "I32d"
michael@0 76 #define PRIiFAST32 "I32i"
michael@0 77
michael@0 78 #define PRId64 "I64d"
michael@0 79 #define PRIi64 "I64i"
michael@0 80 #define PRIdLEAST64 "I64d"
michael@0 81 #define PRIiLEAST64 "I64i"
michael@0 82 #define PRIdFAST64 "I64d"
michael@0 83 #define PRIiFAST64 "I64i"
michael@0 84
michael@0 85 #define PRIdMAX "I64d"
michael@0 86 #define PRIiMAX "I64i"
michael@0 87
michael@0 88 #define PRIdPTR "Id"
michael@0 89 #define PRIiPTR "Ii"
michael@0 90
michael@0 91 // The fprintf macros for unsigned integers are:
michael@0 92 #define PRIo8 "o"
michael@0 93 #define PRIu8 "u"
michael@0 94 #define PRIx8 "x"
michael@0 95 #define PRIX8 "X"
michael@0 96 #define PRIoLEAST8 "o"
michael@0 97 #define PRIuLEAST8 "u"
michael@0 98 #define PRIxLEAST8 "x"
michael@0 99 #define PRIXLEAST8 "X"
michael@0 100 #define PRIoFAST8 "o"
michael@0 101 #define PRIuFAST8 "u"
michael@0 102 #define PRIxFAST8 "x"
michael@0 103 #define PRIXFAST8 "X"
michael@0 104
michael@0 105 #define PRIo16 "ho"
michael@0 106 #define PRIu16 "hu"
michael@0 107 #define PRIx16 "hx"
michael@0 108 #define PRIX16 "hX"
michael@0 109 #define PRIoLEAST16 "ho"
michael@0 110 #define PRIuLEAST16 "hu"
michael@0 111 #define PRIxLEAST16 "hx"
michael@0 112 #define PRIXLEAST16 "hX"
michael@0 113 #define PRIoFAST16 "ho"
michael@0 114 #define PRIuFAST16 "hu"
michael@0 115 #define PRIxFAST16 "hx"
michael@0 116 #define PRIXFAST16 "hX"
michael@0 117
michael@0 118 #define PRIo32 "I32o"
michael@0 119 #define PRIu32 "I32u"
michael@0 120 #define PRIx32 "I32x"
michael@0 121 #define PRIX32 "I32X"
michael@0 122 #define PRIoLEAST32 "I32o"
michael@0 123 #define PRIuLEAST32 "I32u"
michael@0 124 #define PRIxLEAST32 "I32x"
michael@0 125 #define PRIXLEAST32 "I32X"
michael@0 126 #define PRIoFAST32 "I32o"
michael@0 127 #define PRIuFAST32 "I32u"
michael@0 128 #define PRIxFAST32 "I32x"
michael@0 129 #define PRIXFAST32 "I32X"
michael@0 130
michael@0 131 #define PRIo64 "I64o"
michael@0 132 #define PRIu64 "I64u"
michael@0 133 #define PRIx64 "I64x"
michael@0 134 #define PRIX64 "I64X"
michael@0 135 #define PRIoLEAST64 "I64o"
michael@0 136 #define PRIuLEAST64 "I64u"
michael@0 137 #define PRIxLEAST64 "I64x"
michael@0 138 #define PRIXLEAST64 "I64X"
michael@0 139 #define PRIoFAST64 "I64o"
michael@0 140 #define PRIuFAST64 "I64u"
michael@0 141 #define PRIxFAST64 "I64x"
michael@0 142 #define PRIXFAST64 "I64X"
michael@0 143
michael@0 144 #define PRIoMAX "I64o"
michael@0 145 #define PRIuMAX "I64u"
michael@0 146 #define PRIxMAX "I64x"
michael@0 147 #define PRIXMAX "I64X"
michael@0 148
michael@0 149 #define PRIoPTR "Io"
michael@0 150 #define PRIuPTR "Iu"
michael@0 151 #define PRIxPTR "Ix"
michael@0 152 #define PRIXPTR "IX"
michael@0 153
michael@0 154 // DO NOT SUPPORT THE scanf MACROS! See the comment at the top of
michael@0 155 // IntegerPrintfMacros.h.
michael@0 156
michael@0 157 #endif // __STDC_FORMAT_MACROS ]
michael@0 158
michael@0 159 // 7.8.2 Functions for greatest-width integer types
michael@0 160
michael@0 161 // 7.8.2.1 The imaxabs function
michael@0 162 #define imaxabs _abs64
michael@0 163
michael@0 164 // 7.8.2.2 The imaxdiv function
michael@0 165
michael@0 166 // This is modified version of div() function from Microsoft's div.c found
michael@0 167 // in %MSVC.NET%\crt\src\div.c
michael@0 168 #ifdef STATIC_IMAXDIV // [
michael@0 169 static
michael@0 170 #else // STATIC_IMAXDIV ][
michael@0 171 _inline
michael@0 172 #endif // STATIC_IMAXDIV ]
michael@0 173 imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
michael@0 174 {
michael@0 175 imaxdiv_t result;
michael@0 176
michael@0 177 result.quot = numer / denom;
michael@0 178 result.rem = numer % denom;
michael@0 179
michael@0 180 if (numer < 0 && result.rem > 0) {
michael@0 181 // did division wrong; must fix up
michael@0 182 ++result.quot;
michael@0 183 result.rem -= denom;
michael@0 184 }
michael@0 185
michael@0 186 return result;
michael@0 187 }
michael@0 188
michael@0 189 // 7.8.2.3 The strtoimax and strtoumax functions
michael@0 190 #define strtoimax _strtoi64
michael@0 191 #define strtoumax _strtoui64
michael@0 192
michael@0 193 // 7.8.2.4 The wcstoimax and wcstoumax functions
michael@0 194 #define wcstoimax _wcstoi64
michael@0 195 #define wcstoumax _wcstoui64
michael@0 196
michael@0 197
michael@0 198 #endif // _MSC_INTTYPES_H_ ]

mercurial