~mordred/libmemcached/merge-vs-work

« back to all changes in this revision

Viewing changes to win32/windows/inttypes.h

  • Committer: Monty Taylor
  • Date: 2011-02-13 18:47:03 UTC
  • Revision ID: mordred@inaugust.com-20110213184703-usxdc2h4do3bnxhx
Build for Visual Studio.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
// 
 
30
///////////////////////////////////////////////////////////////////////////////
 
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
#if _MSC_VER > 1000
 
40
#pragma once
 
41
#endif
 
42
 
 
43
#include <stdint.h>
 
44
 
 
45
// 7.8 Format conversion of integer types
 
46
 
 
47
typedef struct {
 
48
   intmax_t quot;
 
49
   intmax_t rem;
 
50
} imaxdiv_t;
 
51
 
 
52
// 7.8.1 Macros for format specifiers
 
53
 
 
54
/* I hate this, so I'm removing it. Love Monty
 
55
#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [   See footnote 185 at page 198
 
56
*/
 
57
 
 
58
// The fprintf macros for signed integers are:
 
59
#define PRId8       "d"
 
60
#define PRIi8       "i"
 
61
#define PRIdLEAST8  "d"
 
62
#define PRIiLEAST8  "i"
 
63
#define PRIdFAST8   "d"
 
64
#define PRIiFAST8   "i"
 
65
 
 
66
#define PRId16       "hd"
 
67
#define PRIi16       "hi"
 
68
#define PRIdLEAST16  "hd"
 
69
#define PRIiLEAST16  "hi"
 
70
#define PRIdFAST16   "hd"
 
71
#define PRIiFAST16   "hi"
 
72
 
 
73
#define PRId32       "I32d"
 
74
#define PRIi32       "I32i"
 
75
#define PRIdLEAST32  "I32d"
 
76
#define PRIiLEAST32  "I32i"
 
77
#define PRIdFAST32   "I32d"
 
78
#define PRIiFAST32   "I32i"
 
79
 
 
80
#define PRId64       "I64d"
 
81
#define PRIi64       "I64i"
 
82
#define PRIdLEAST64  "I64d"
 
83
#define PRIiLEAST64  "I64i"
 
84
#define PRIdFAST64   "I64d"
 
85
#define PRIiFAST64   "I64i"
 
86
 
 
87
#define PRIdMAX     "I64d"
 
88
#define PRIiMAX     "I64i"
 
89
 
 
90
#define PRIdPTR     "Id"
 
91
#define PRIiPTR     "Ii"
 
92
 
 
93
// The fprintf macros for unsigned integers are:
 
94
#define PRIo8       "o"
 
95
#define PRIu8       "u"
 
96
#define PRIx8       "x"
 
97
#define PRIX8       "X"
 
98
#define PRIoLEAST8  "o"
 
99
#define PRIuLEAST8  "u"
 
100
#define PRIxLEAST8  "x"
 
101
#define PRIXLEAST8  "X"
 
102
#define PRIoFAST8   "o"
 
103
#define PRIuFAST8   "u"
 
104
#define PRIxFAST8   "x"
 
105
#define PRIXFAST8   "X"
 
106
 
 
107
#define PRIo16       "ho"
 
108
#define PRIu16       "hu"
 
109
#define PRIx16       "hx"
 
110
#define PRIX16       "hX"
 
111
#define PRIoLEAST16  "ho"
 
112
#define PRIuLEAST16  "hu"
 
113
#define PRIxLEAST16  "hx"
 
114
#define PRIXLEAST16  "hX"
 
115
#define PRIoFAST16   "ho"
 
116
#define PRIuFAST16   "hu"
 
117
#define PRIxFAST16   "hx"
 
118
#define PRIXFAST16   "hX"
 
119
 
 
120
#define PRIo32       "I32o"
 
121
#define PRIu32       "I32u"
 
122
#define PRIx32       "I32x"
 
123
#define PRIX32       "I32X"
 
124
#define PRIoLEAST32  "I32o"
 
125
#define PRIuLEAST32  "I32u"
 
126
#define PRIxLEAST32  "I32x"
 
127
#define PRIXLEAST32  "I32X"
 
128
#define PRIoFAST32   "I32o"
 
129
#define PRIuFAST32   "I32u"
 
130
#define PRIxFAST32   "I32x"
 
131
#define PRIXFAST32   "I32X"
 
132
 
 
133
#define PRIo64       "I64o"
 
134
#define PRIu64       "I64u"
 
135
#define PRIx64       "I64x"
 
136
#define PRIX64       "I64X"
 
137
#define PRIoLEAST64  "I64o"
 
138
#define PRIuLEAST64  "I64u"
 
139
#define PRIxLEAST64  "I64x"
 
140
#define PRIXLEAST64  "I64X"
 
141
#define PRIoFAST64   "I64o"
 
142
#define PRIuFAST64   "I64u"
 
143
#define PRIxFAST64   "I64x"
 
144
#define PRIXFAST64   "I64X"
 
145
 
 
146
#define PRIoMAX     "I64o"
 
147
#define PRIuMAX     "I64u"
 
148
#define PRIxMAX     "I64x"
 
149
#define PRIXMAX     "I64X"
 
150
 
 
151
#define PRIoPTR     "Io"
 
152
#define PRIuPTR     "Iu"
 
153
#define PRIxPTR     "Ix"
 
154
#define PRIXPTR     "IX"
 
155
 
 
156
// The fscanf macros for signed integers are:
 
157
#define SCNd8       "d"
 
158
#define SCNi8       "i"
 
159
#define SCNdLEAST8  "d"
 
160
#define SCNiLEAST8  "i"
 
161
#define SCNdFAST8   "d"
 
162
#define SCNiFAST8   "i"
 
163
 
 
164
#define SCNd16       "hd"
 
165
#define SCNi16       "hi"
 
166
#define SCNdLEAST16  "hd"
 
167
#define SCNiLEAST16  "hi"
 
168
#define SCNdFAST16   "hd"
 
169
#define SCNiFAST16   "hi"
 
170
 
 
171
#define SCNd32       "ld"
 
172
#define SCNi32       "li"
 
173
#define SCNdLEAST32  "ld"
 
174
#define SCNiLEAST32  "li"
 
175
#define SCNdFAST32   "ld"
 
176
#define SCNiFAST32   "li"
 
177
 
 
178
#define SCNd64       "I64d"
 
179
#define SCNi64       "I64i"
 
180
#define SCNdLEAST64  "I64d"
 
181
#define SCNiLEAST64  "I64i"
 
182
#define SCNdFAST64   "I64d"
 
183
#define SCNiFAST64   "I64i"
 
184
 
 
185
#define SCNdMAX     "I64d"
 
186
#define SCNiMAX     "I64i"
 
187
 
 
188
#ifdef _WIN64 // [
 
189
#  define SCNdPTR     "I64d"
 
190
#  define SCNiPTR     "I64i"
 
191
#else  // _WIN64 ][
 
192
#  define SCNdPTR     "ld"
 
193
#  define SCNiPTR     "li"
 
194
#endif  // _WIN64 ]
 
195
 
 
196
// The fscanf macros for unsigned integers are:
 
197
#define SCNo8       "o"
 
198
#define SCNu8       "u"
 
199
#define SCNx8       "x"
 
200
#define SCNX8       "X"
 
201
#define SCNoLEAST8  "o"
 
202
#define SCNuLEAST8  "u"
 
203
#define SCNxLEAST8  "x"
 
204
#define SCNXLEAST8  "X"
 
205
#define SCNoFAST8   "o"
 
206
#define SCNuFAST8   "u"
 
207
#define SCNxFAST8   "x"
 
208
#define SCNXFAST8   "X"
 
209
 
 
210
#define SCNo16       "ho"
 
211
#define SCNu16       "hu"
 
212
#define SCNx16       "hx"
 
213
#define SCNX16       "hX"
 
214
#define SCNoLEAST16  "ho"
 
215
#define SCNuLEAST16  "hu"
 
216
#define SCNxLEAST16  "hx"
 
217
#define SCNXLEAST16  "hX"
 
218
#define SCNoFAST16   "ho"
 
219
#define SCNuFAST16   "hu"
 
220
#define SCNxFAST16   "hx"
 
221
#define SCNXFAST16   "hX"
 
222
 
 
223
#define SCNo32       "lo"
 
224
#define SCNu32       "lu"
 
225
#define SCNx32       "lx"
 
226
#define SCNX32       "lX"
 
227
#define SCNoLEAST32  "lo"
 
228
#define SCNuLEAST32  "lu"
 
229
#define SCNxLEAST32  "lx"
 
230
#define SCNXLEAST32  "lX"
 
231
#define SCNoFAST32   "lo"
 
232
#define SCNuFAST32   "lu"
 
233
#define SCNxFAST32   "lx"
 
234
#define SCNXFAST32   "lX"
 
235
 
 
236
#define SCNo64       "I64o"
 
237
#define SCNu64       "I64u"
 
238
#define SCNx64       "I64x"
 
239
#define SCNX64       "I64X"
 
240
#define SCNoLEAST64  "I64o"
 
241
#define SCNuLEAST64  "I64u"
 
242
#define SCNxLEAST64  "I64x"
 
243
#define SCNXLEAST64  "I64X"
 
244
#define SCNoFAST64   "I64o"
 
245
#define SCNuFAST64   "I64u"
 
246
#define SCNxFAST64   "I64x"
 
247
#define SCNXFAST64   "I64X"
 
248
 
 
249
#define SCNoMAX     "I64o"
 
250
#define SCNuMAX     "I64u"
 
251
#define SCNxMAX     "I64x"
 
252
#define SCNXMAX     "I64X"
 
253
 
 
254
#ifdef _WIN64 // [
 
255
#  define SCNoPTR     "I64o"
 
256
#  define SCNuPTR     "I64u"
 
257
#  define SCNxPTR     "I64x"
 
258
#  define SCNXPTR     "I64X"
 
259
#else  // _WIN64 ][
 
260
#  define SCNoPTR     "lo"
 
261
#  define SCNuPTR     "lu"
 
262
#  define SCNxPTR     "lx"
 
263
#  define SCNXPTR     "lX"
 
264
#endif  // _WIN64 ]
 
265
 
 
266
/*
 
267
#endif // __STDC_FORMAT_MACROS ]
 
268
*/
 
269
 
 
270
// 7.8.2 Functions for greatest-width integer types
 
271
 
 
272
// 7.8.2.1 The imaxabs function
 
273
#define imaxabs _abs64
 
274
 
 
275
// 7.8.2.2 The imaxdiv function
 
276
 
 
277
// This is modified version of div() function from Microsoft's div.c found
 
278
// in %MSVC.NET%\crt\src\div.c
 
279
#ifdef STATIC_IMAXDIV // [
 
280
static
 
281
#else // STATIC_IMAXDIV ][
 
282
_inline
 
283
#endif // STATIC_IMAXDIV ]
 
284
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
 
285
{
 
286
   imaxdiv_t result;
 
287
 
 
288
   result.quot = numer / denom;
 
289
   result.rem = numer % denom;
 
290
 
 
291
   if (numer < 0 && result.rem > 0) {
 
292
      // did division wrong; must fix up
 
293
      ++result.quot;
 
294
      result.rem -= denom;
 
295
   }
 
296
 
 
297
   return result;
 
298
}
 
299
 
 
300
// 7.8.2.3 The strtoimax and strtoumax functions
 
301
#define strtoimax _strtoi64
 
302
#define strtoumax _strtoui64
 
303
 
 
304
// 7.8.2.4 The wcstoimax and wcstoumax functions
 
305
#define wcstoimax _wcstoi64
 
306
#define wcstoumax _wcstoui64
 
307
 
 
308
 
 
309
#endif // _MSC_INTTYPES_H_ ]