CPPMyth
Library to interoperate with MythTV server
msc_inttypes.h
1 // ISO C9x compliant inttypes.h for Microsoft Visual Studio
2 // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
3 //
4 // Copyright (c) 2006 Alexander Chemeris
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // 3. The name of the author may be used to endorse or promote products
17 // derived from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
22 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
31 
32 #ifndef _MSC_VER // [
33 #error "Use this header only with Microsoft Visual C++ compilers!"
34 #endif // _MSC_VER ]
35 
36 #ifndef _MSC_INTTYPES_H_ // [
37 #define _MSC_INTTYPES_H_
38 
39 #include "stdint.h"
40 
41 // 7.8 Format conversion of integer types
42 
43 typedef struct {
44  intmax_t quot;
45  intmax_t rem;
46 } imaxdiv_t;
47 
48 // 7.8.1 Macros for format specifiers
49 
50 #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
51 
52 // The fprintf macros for signed integers are:
53 #define PRId8 "d"
54 #define PRIi8 "i"
55 #define PRIdLEAST8 "d"
56 #define PRIiLEAST8 "i"
57 #define PRIdFAST8 "d"
58 #define PRIiFAST8 "i"
59 
60 #define PRId16 "hd"
61 #define PRIi16 "hi"
62 #define PRIdLEAST16 "hd"
63 #define PRIiLEAST16 "hi"
64 #define PRIdFAST16 "hd"
65 #define PRIiFAST16 "hi"
66 
67 #define PRId32 "I32d"
68 #define PRIi32 "I32i"
69 #define PRIdLEAST32 "I32d"
70 #define PRIiLEAST32 "I32i"
71 #define PRIdFAST32 "I32d"
72 #define PRIiFAST32 "I32i"
73 
74 #define PRId64 "I64d"
75 #define PRIi64 "I64i"
76 #define PRIdLEAST64 "I64d"
77 #define PRIiLEAST64 "I64i"
78 #define PRIdFAST64 "I64d"
79 #define PRIiFAST64 "I64i"
80 
81 #define PRIdMAX "I64d"
82 #define PRIiMAX "I64i"
83 
84 #define PRIdPTR "Id"
85 #define PRIiPTR "Ii"
86 
87 // The fprintf macros for unsigned integers are:
88 #define PRIo8 "o"
89 #define PRIu8 "u"
90 #define PRIx8 "x"
91 #define PRIX8 "X"
92 #define PRIoLEAST8 "o"
93 #define PRIuLEAST8 "u"
94 #define PRIxLEAST8 "x"
95 #define PRIXLEAST8 "X"
96 #define PRIoFAST8 "o"
97 #define PRIuFAST8 "u"
98 #define PRIxFAST8 "x"
99 #define PRIXFAST8 "X"
100 
101 #define PRIo16 "ho"
102 #define PRIu16 "hu"
103 #define PRIx16 "hx"
104 #define PRIX16 "hX"
105 #define PRIoLEAST16 "ho"
106 #define PRIuLEAST16 "hu"
107 #define PRIxLEAST16 "hx"
108 #define PRIXLEAST16 "hX"
109 #define PRIoFAST16 "ho"
110 #define PRIuFAST16 "hu"
111 #define PRIxFAST16 "hx"
112 #define PRIXFAST16 "hX"
113 
114 #define PRIo32 "I32o"
115 #define PRIu32 "I32u"
116 #define PRIx32 "I32x"
117 #define PRIX32 "I32X"
118 #define PRIoLEAST32 "I32o"
119 #define PRIuLEAST32 "I32u"
120 #define PRIxLEAST32 "I32x"
121 #define PRIXLEAST32 "I32X"
122 #define PRIoFAST32 "I32o"
123 #define PRIuFAST32 "I32u"
124 #define PRIxFAST32 "I32x"
125 #define PRIXFAST32 "I32X"
126 
127 #define PRIo64 "I64o"
128 #define PRIu64 "I64u"
129 #define PRIx64 "I64x"
130 #define PRIX64 "I64X"
131 #define PRIoLEAST64 "I64o"
132 #define PRIuLEAST64 "I64u"
133 #define PRIxLEAST64 "I64x"
134 #define PRIXLEAST64 "I64X"
135 #define PRIoFAST64 "I64o"
136 #define PRIuFAST64 "I64u"
137 #define PRIxFAST64 "I64x"
138 #define PRIXFAST64 "I64X"
139 
140 #define PRIoMAX "I64o"
141 #define PRIuMAX "I64u"
142 #define PRIxMAX "I64x"
143 #define PRIXMAX "I64X"
144 
145 #define PRIoPTR "Io"
146 #define PRIuPTR "Iu"
147 #define PRIxPTR "Ix"
148 #define PRIXPTR "IX"
149 
150 #define PRIdS "Id"
151 #define PRIuS "Iu"
152 
153 // The fscanf macros for signed integers are:
154 #define SCNd8 "d"
155 #define SCNi8 "i"
156 #define SCNdLEAST8 "d"
157 #define SCNiLEAST8 "i"
158 #define SCNdFAST8 "d"
159 #define SCNiFAST8 "i"
160 
161 #define SCNd16 "hd"
162 #define SCNi16 "hi"
163 #define SCNdLEAST16 "hd"
164 #define SCNiLEAST16 "hi"
165 #define SCNdFAST16 "hd"
166 #define SCNiFAST16 "hi"
167 
168 #define SCNd32 "ld"
169 #define SCNi32 "li"
170 #define SCNdLEAST32 "ld"
171 #define SCNiLEAST32 "li"
172 #define SCNdFAST32 "ld"
173 #define SCNiFAST32 "li"
174 
175 #define SCNd64 "I64d"
176 #define SCNi64 "I64i"
177 #define SCNdLEAST64 "I64d"
178 #define SCNiLEAST64 "I64i"
179 #define SCNdFAST64 "I64d"
180 #define SCNiFAST64 "I64i"
181 
182 #define SCNdMAX "I64d"
183 #define SCNiMAX "I64i"
184 
185 #ifdef _WIN64 // [
186 # define SCNdPTR "I64d"
187 # define SCNiPTR "I64i"
188 #else // _WIN64 ][
189 # define SCNdPTR "ld"
190 # define SCNiPTR "li"
191 #endif // _WIN64 ]
192 
193 // The fscanf macros for unsigned integers are:
194 #define SCNo8 "o"
195 #define SCNu8 "u"
196 #define SCNx8 "x"
197 #define SCNX8 "X"
198 #define SCNoLEAST8 "o"
199 #define SCNuLEAST8 "u"
200 #define SCNxLEAST8 "x"
201 #define SCNXLEAST8 "X"
202 #define SCNoFAST8 "o"
203 #define SCNuFAST8 "u"
204 #define SCNxFAST8 "x"
205 #define SCNXFAST8 "X"
206 
207 #define SCNo16 "ho"
208 #define SCNu16 "hu"
209 #define SCNx16 "hx"
210 #define SCNX16 "hX"
211 #define SCNoLEAST16 "ho"
212 #define SCNuLEAST16 "hu"
213 #define SCNxLEAST16 "hx"
214 #define SCNXLEAST16 "hX"
215 #define SCNoFAST16 "ho"
216 #define SCNuFAST16 "hu"
217 #define SCNxFAST16 "hx"
218 #define SCNXFAST16 "hX"
219 
220 #define SCNo32 "lo"
221 #define SCNu32 "lu"
222 #define SCNx32 "lx"
223 #define SCNX32 "lX"
224 #define SCNoLEAST32 "lo"
225 #define SCNuLEAST32 "lu"
226 #define SCNxLEAST32 "lx"
227 #define SCNXLEAST32 "lX"
228 #define SCNoFAST32 "lo"
229 #define SCNuFAST32 "lu"
230 #define SCNxFAST32 "lx"
231 #define SCNXFAST32 "lX"
232 
233 #define SCNo64 "I64o"
234 #define SCNu64 "I64u"
235 #define SCNx64 "I64x"
236 #define SCNX64 "I64X"
237 #define SCNoLEAST64 "I64o"
238 #define SCNuLEAST64 "I64u"
239 #define SCNxLEAST64 "I64x"
240 #define SCNXLEAST64 "I64X"
241 #define SCNoFAST64 "I64o"
242 #define SCNuFAST64 "I64u"
243 #define SCNxFAST64 "I64x"
244 #define SCNXFAST64 "I64X"
245 
246 #define SCNoMAX "I64o"
247 #define SCNuMAX "I64u"
248 #define SCNxMAX "I64x"
249 #define SCNXMAX "I64X"
250 
251 #ifdef _WIN64 // [
252 # define SCNoPTR "I64o"
253 # define SCNuPTR "I64u"
254 # define SCNxPTR "I64x"
255 # define SCNXPTR "I64X"
256 #else // _WIN64 ][
257 # define SCNoPTR "lo"
258 # define SCNuPTR "lu"
259 # define SCNxPTR "lx"
260 # define SCNXPTR "lX"
261 #endif // _WIN64 ]
262 
263 #endif // __STDC_FORMAT_MACROS ]
264 
265 // 7.8.2 Functions for greatest-width integer types
266 
267 // 7.8.2.1 The imaxabs function
268 #define imaxabs _abs64
269 
270 // 7.8.2.2 The imaxdiv function
271 
272 // This is modified version of div() function from Microsoft's div.c found
273 // in %MSVC.NET%\crt\src\div.c
274 #ifdef STATIC_IMAXDIV // [
275 static
276 #else // STATIC_IMAXDIV ][
277 _inline
278 #endif // STATIC_IMAXDIV ]
279 imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
280 {
281  imaxdiv_t result;
282 
283  result.quot = numer / denom;
284  result.rem = numer % denom;
285 
286  if (numer < 0 && result.rem > 0) {
287  // did division wrong; must fix up
288  ++result.quot;
289  result.rem -= denom;
290  }
291 
292  return result;
293 }
294 
295 // 7.8.2.3 The strtoimax and strtoumax functions
296 #define strtoimax _strtoi64
297 #define strtoumax _strtoui64
298 
299 // 7.8.2.4 The wcstoimax and wcstoumax functions
300 #define wcstoimax _wcstoi64
301 #define wcstoumax _wcstoui64
302 
303 
304 #endif // _MSC_INTTYPES_H_ ]