~ubuntu-branches/debian/sid/mstflint/sid

« back to all changes in this revision

Viewing changes to common/compatibility.h

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2014-07-04 15:39:23 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140704153923-khknwv3o1jeap3oo
Tags: 3.7.0-1
* New upstream release: 3.7.0-1.10.gdf7ec73
* Add build depends on libibmad-dev and autotools-dev.
* Remove build depends on automake and libtool.
* Switch to dh 9 and source format version 3.0
* Remove placeholder manpages.
* Remove flag DM-Upload-Allowed.
* Remove all current Uploaders, they're welcome back anytime.
  Add myself to Uploaders.
* Bump Standards-Version to 3.9.5 (no changes required).
* Update homepage.
* Add a watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) Jan 2006 Mellanox Technologies Ltd. All rights reserved.
 
3
 *
 
4
 * This software is available to you under a choice of one of two
 
5
 * licenses.  You may choose to be licensed under the terms of the GNU
 
6
 * General Public License (GPL) Version 2, available from the file
 
7
 * COPYING in the main directory of this source tree, or the
 
8
 * OpenIB.org BSD license below:
 
9
 *
 
10
 *     Redistribution and use in source and binary forms, with or
 
11
 *     without modification, are permitted provided that the following
 
12
 *     conditions are met:
 
13
 *
 
14
 *      - Redistributions of source code must retain the above
 
15
 *        copyright notice, this list of conditions and the following
 
16
 *        disclaimer.
 
17
 *
 
18
 *      - Redistributions in binary form must reproduce the above
 
19
 *        copyright notice, this list of conditions and the following
 
20
 *        disclaimer in the documentation and/or other materials
 
21
 *        provided with the distribution.
 
22
 *
 
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
24
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
25
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
26
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
27
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
28
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
29
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
30
 * SOFTWARE.
 
31
 *
 
32
 *  compatibility.h - Miscellaneous systems compatibility issues
 
33
 *
 
34
 *  Version: $Id: compatibility.h 3261 2007-01-28 14:59:53Z orenk $
 
35
 *
 
36
 */
 
37
 
 
38
#ifndef COMPATIBILITY_H
 
39
#define COMPATIBILITY_H
 
40
 
 
41
#include <stdio.h>
 
42
 
 
43
#if defined(__ia64__) || defined(__x86_64__) || defined(__PPC64__)
 
44
    #define U64L       "l"
 
45
#else
 
46
    #define U64L       "ll"
 
47
#endif
 
48
 
 
49
 
 
50
/* define macros to the architecture of the CPU */
 
51
#if defined(__linux) || defined(__FreeBSD__)             /* __linux || __FreeBSD__ */
 
52
#   if defined(__i386__)
 
53
#       define ARCH_x86
 
54
#   elif defined(__x86_64__)
 
55
#       define ARCH_x86_64
 
56
#   elif defined(__ia64__)
 
57
#       define ARCH_ia64
 
58
#   elif defined(__PPC64__)
 
59
#       define ARCH_ppc64
 
60
#   elif defined(__PPC__)
 
61
#       define ARCH_ppc
 
62
#   elif defined(__aarch64__)
 
63
#       define ARCH_arm64
 
64
#   else
 
65
#       error Unknown CPU architecture using the linux OS
 
66
#   endif
 
67
#elif defined(__MINGW32__) || defined(__MINGW64__)              /* Windows MINGW */
 
68
#   if defined(__MINGW32__)
 
69
#       define ARCH_x86
 
70
#   elif defined(__MINGW64__)
 
71
#       define ARCH_x86_64
 
72
#   else
 
73
#       error Unknown CPU architecture using the windows-mingw OS
 
74
#   endif
 
75
#elif defined(_WIN32) || defined(_WIN64)                /* Windows */
 
76
#   if defined(_WIN32)
 
77
#       define ARCH_x86
 
78
#   elif defined(_WIN64)
 
79
#       define ARCH_x86_64
 
80
#   else
 
81
#       error Unknown CPU architecture using the windows OS
 
82
#   endif
 
83
#else                                                   /* Unknown */
 
84
#   error Unknown OS
 
85
#endif
 
86
 
 
87
/* define macros for print fields */
 
88
#define U32D_FMT    "%u"
 
89
#define U32H_FMT    "0x%08x"
 
90
#define UH_FMT          "0x%x"
 
91
#define STR_FMT     "%s"
 
92
#define U16H_FMT    "0x%04x"
 
93
#define U8H_FMT     "0x%02x"
 
94
 
 
95
#if defined(ARCH_x86) || defined(ARCH_ppc) || defined(UEFI_BUILD)
 
96
#   if defined(__MINGW32__) || defined(__MINGW64__)
 
97
#       include <inttypes.h>
 
98
#       define U64D_FMT    "0x%"PRId64
 
99
#       define U64H_FMT    "0x%"PRIx64
 
100
#       define U64H_FMT_GEN ""PRIx64
 
101
#       define U48H_FMT    "0x%"PRIx64
 
102
#       define U64D_FMT_GEN ""PRId64
 
103
#   else
 
104
#       define U64D_FMT     "%llu"
 
105
#       define U64H_FMT     "0x%016llx"
 
106
#       define U64H_FMT_GEN "llx"
 
107
#       define U48H_FMT     "0x%012llx"
 
108
#       define U64D_FMT_GEN "llu"
 
109
#   endif
 
110
#elif defined (ARCH_ia64) || defined(ARCH_x86_64) || defined(ARCH_ppc64) || defined(ARCH_arm64)
 
111
#    define U64D_FMT     "%lu"
 
112
#    define U64H_FMT     "0x%016lx"
 
113
#    define U48H_FMT     "0x%012lx"
 
114
#    define U64H_FMT_GEN "lx"
 
115
#    define U64D_FMT_GEN "lu"
 
116
#else
 
117
#   error Unknown architecture
 
118
#endif  /* ARCH */
 
119
 
 
120
 
 
121
/* define msleep(x) - sleeps for x milliseconds */
 
122
#if defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__)
 
123
    #include <Winsock2.h>
 
124
    #include <winsock2.h>
 
125
    #include <windows.h>
 
126
    #define msleep(x)   Sleep(x)
 
127
#else
 
128
    #include <unistd.h>
 
129
    #define msleep(x)   usleep(((unsigned long)x)*1000)
 
130
#endif
 
131
 
 
132
/*
 
133
 * Only for architectures which can't do swab by themselves
 
134
 */
 
135
#define ___my_swab16(x) \
 
136
((u_int16_t)( \
 
137
        (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
 
138
        (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
 
139
#define ___my_swab32(x) \
 
140
((u_int32_t)( \
 
141
        (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
 
142
        (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) <<  8) | \
 
143
        (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >>  8) | \
 
144
        (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
 
145
#define ___my_swab64(x) \
 
146
((u_int64_t)( \
 
147
        (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
 
148
        (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
 
149
        (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
 
150
        (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) <<  8) | \
 
151
        (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >>  8) | \
 
152
        (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
 
153
        (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
 
154
        (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
 
155
 
 
156
/*
 
157
 * Linux
 
158
 */
 
159
#if defined(linux) || defined(__FreeBSD__)
 
160
// #include <asm/byteorder.h>
 
161
    #include <unistd.h>
 
162
    #include <sys/types.h>
 
163
 
 
164
    #if defined (__FreeBSD__)
 
165
    #include <sys/endian.h>
 
166
    #else
 
167
    #include <endian.h>
 
168
    #endif
 
169
 
 
170
    #undef __be64_to_cpu
 
171
    #undef __be32_to_cpu
 
172
    #undef __be16_to_cpu
 
173
    #undef __cpu_to_be64
 
174
    #undef __cpu_to_be32
 
175
    #undef __cpu_to_be16
 
176
    #undef __le64_to_cpu
 
177
    #undef __le32_to_cpu
 
178
    #undef __le16_to_cpu
 
179
    #undef __cpu_to_le64
 
180
    #undef __cpu_to_le32
 
181
    #undef __cpu_to_le16
 
182
 
 
183
    #if __BYTE_ORDER == __LITTLE_ENDIAN
 
184
 
 
185
        #define __be64_to_cpu(x) ___my_swab64(x)
 
186
        #define __be32_to_cpu(x) ___my_swab32(x)
 
187
        #define __be16_to_cpu(x) ___my_swab16(x)
 
188
        #define __cpu_to_be64(x) ___my_swab64(x)
 
189
        #define __cpu_to_be32(x) ___my_swab32(x)
 
190
        #define __cpu_to_be16(x) ___my_swab16(x)
 
191
        #define __le64_to_cpu(x) (x)
 
192
        #define __le32_to_cpu(x) (x)
 
193
        #define __le16_to_cpu(x) (x)
 
194
        #define __cpu_to_le64(x) (x)
 
195
        #define __cpu_to_le32(x) (x)
 
196
        #define __cpu_to_le16(x) (x)
 
197
 
 
198
    #elif __BYTE_ORDER == __BIG_ENDIAN
 
199
 
 
200
        #define __be64_to_cpu(x) (x)
 
201
        #define __be32_to_cpu(x) (x)
 
202
        #define __be16_to_cpu(x) (x)
 
203
        #define __cpu_to_be64(x) (x)
 
204
        #define __cpu_to_be32(x) (x)
 
205
        #define __cpu_to_be16(x) (x)
 
206
        #define __le64_to_cpu(x) ___my_swab64(x)
 
207
        #define __le32_to_cpu(x) ___my_swab32(x)
 
208
        #define __le16_to_cpu(x) ___my_swab16(x)
 
209
        #define __cpu_to_le64(x) ___my_swab64(x)
 
210
        #define __cpu_to_le32(x) ___my_swab32(x)
 
211
        #define __cpu_to_le16(x) ___my_swab16(x)
 
212
 
 
213
    #endif // __BYTE_ORDER
 
214
 
 
215
#endif
 
216
 
 
217
/*
 
218
 * Windows (CYGWIN)
 
219
 */
 
220
#if defined(__CYGWIN32__)
 
221
    #include <asm/byteorder.h>
 
222
    #include <unistd.h>
 
223
 
 
224
    #define __be64_to_cpu(x) ___my_swab64(x)
 
225
    #define __be32_to_cpu(x) ___my_swab32(x)
 
226
    #define __be16_to_cpu(x) ___my_swab16(x)
 
227
    #define __cpu_to_be64(x) ___my_swab64(x)
 
228
    #define __cpu_to_be32(x) ___my_swab32(x)
 
229
    #define __cpu_to_be16(x) ___my_swab16(x)
 
230
    #define __le64_to_cpu(x) (x)
 
231
    #define __le32_to_cpu(x) (x)
 
232
    #define __le16_to_cpu(x) (x)
 
233
    #define __cpu_to_le64(x) (x)
 
234
    #define __cpu_to_le32(x) (x)
 
235
    #define __cpu_to_le16(x) (x)
 
236
 
 
237
#endif
 
238
 
 
239
/*
 
240
 * Windows (DDK)
 
241
 */
 
242
#if defined(__WIN__)
 
243
    #include <Winsock2.h>
 
244
    #include <winsock2.h>
 
245
    #include <windows.h>
 
246
    #include <io.h>
 
247
 
 
248
    #define __LITTLE_ENDIAN 1234
 
249
    #define __BIG_ENDIAN 4321
 
250
    #define __BYTE_ORDER __LITTLE_ENDIAN
 
251
 
 
252
    #define __be64_to_cpu(x) ___my_swab64(x)
 
253
    #define __be32_to_cpu(x) ___my_swab32(x)
 
254
    #define __be16_to_cpu(x) ___my_swab16(x)
 
255
    #define __cpu_to_be64(x) ___my_swab64(x)
 
256
    #define __cpu_to_be32(x) ___my_swab32(x)
 
257
    #define __cpu_to_be16(x) ___my_swab16(x)
 
258
    #define __le64_to_cpu(x) (x)
 
259
    #define __le32_to_cpu(x) (x)
 
260
    #define __le16_to_cpu(x) (x)
 
261
    #define __cpu_to_le64(x) (x)
 
262
    #define __cpu_to_le32(x) (x)
 
263
    #define __cpu_to_le16(x) (x)
 
264
 
 
265
 
 
266
    #if defined(__MINGW32__) || defined(__MINGW64__)
 
267
        #include <stdint.h>
 
268
        #ifndef   MFT_TOOLS_VARS
 
269
            #define MFT_TOOLS_VARS
 
270
            typedef uint8_t  u_int8_t;
 
271
            typedef uint16_t u_int16_t;
 
272
            typedef uint32_t u_int32_t;
 
273
            typedef uint64_t u_int64_t;
 
274
        #endif
 
275
        #include <string.h>      // Get a define for strcasecmp
 
276
        // #define usleep(x) Sleep((x + 999)/1000)
 
277
 
 
278
    #else
 
279
        typedef unsigned __int8  u_int8_t;
 
280
        typedef __int8           int8_t;
 
281
        typedef unsigned __int16 u_int16_t;
 
282
        typedef __int16          int16_t;
 
283
        typedef unsigned __int32 u_int32_t;
 
284
        typedef __int32          int32_t;
 
285
        typedef unsigned __int64 u_int64_t;
 
286
        typedef __int64          int64_t;
 
287
 
 
288
        #define strcasecmp    _stricmp
 
289
        #define strtoll       _strtoi64
 
290
        #define strtoull      _strtoui64
 
291
        #define strdup        _strdup
 
292
 
 
293
    #endif
 
294
 
 
295
    #ifndef __WIN__ // TBD : investigate crash on win
 
296
inline
 
297
    #endif
 
298
 
 
299
    #define COMP_CDECL    __cdecl
 
300
    #define COMP_OPEN     ::_open
 
301
    #define COMP_CLOSE    ::_close
 
302
    #define COMP_READ     ::_read
 
303
    #define COMP_FSTAT    ::_fstat
 
304
 
 
305
    #ifndef __cplusplus
 
306
        #define close _close
 
307
    #endif
 
308
 
 
309
typedef struct _stat  Stat;
 
310
 
 
311
    #define PRIx64 "I64x"
 
312
    #define PRIu64 "I64u"
 
313
/*
 
314
    #ifdef __cplusplus
 
315
static inline int pread(int fd, void *buf, int count, u_int64_t offset) {return -1;}
 
316
static inline int pwrite(int fd, const void *buf, int count, u_int64_t offset) {return -1;}
 
317
    #else
 
318
static inline int pread(int fd, void *buf, int count, u_int64_t offset) {return -1;}
 
319
static inline int pwrite(int fd, const void *buf, int count, u_int64_t offset) {return -1;}
 
320
    #endif
 
321
*/
 
322
#else
 
323
 
 
324
    #define COMP_CDECL
 
325
    #define COMP_OPEN     ::open
 
326
    #define COMP_CLOSE    ::close
 
327
    #define COMP_READ     ::read
 
328
    #define COMP_FSTAT    ::fstat
 
329
 
 
330
typedef struct stat  Stat;
 
331
 
 
332
    #include <sys/time.h>
 
333
    #include <strings.h>
 
334
 
 
335
#endif
 
336
 
 
337
 
 
338
 
 
339
/*
 
340
 * MAC (Darwin)
 
341
 */
 
342
#if defined(__APPLE_CC__)
 
343
    #include <architecture/byte_order.h>
 
344
 
 
345
    #define __swab64(x)      NXSwapLongLong(x)
 
346
    #define __swab32(x)      NXSwapLong(x)
 
347
    #define __swab16(x)      NXSwapShort(x)
 
348
    #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
 
349
    #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
 
350
    #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
 
351
    #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
 
352
    #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
 
353
    #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
 
354
    #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
 
355
    #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
 
356
    #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
 
357
    #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
 
358
    #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
 
359
    #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
 
360
 
 
361
    #define __LITTLE_ENDIAN 1234
 
362
    #define __BIG_ENDIAN    4321
 
363
    #define __PDP_ENDIAN    3412
 
364
    #define __BYTE_ORDER    __BIG_ENDIAN
 
365
#endif
 
366
 
 
367
/*
 
368
 * Solaris
 
369
 * -------
 
370
 */
 
371
#if defined(__sparc__)
 
372
    #include <sys/byteorder.h>
 
373
    #include <sys/types.h>
 
374
    #include <unistd.h>
 
375
 
 
376
    #define __be64_to_cpu(x) (x)
 
377
    #define __be32_to_cpu(x) (x)
 
378
    #define __be16_to_cpu(x) (x)
 
379
    #define __cpu_to_be64(x) (x)
 
380
    #define __cpu_to_be32(x) (x)
 
381
    #define __cpu_to_be16(x) (x)
 
382
    #define __le64_to_cpu(x) ___my_swab64(x)
 
383
    #define __le32_to_cpu(x) ___my_swab32(x)
 
384
    #define __le16_to_cpu(x) ___my_swab16(x)
 
385
    #define __cpu_to_le64(x) ___my_swab64(x)
 
386
    #define __cpu_to_le32(x) ___my_swab32(x)
 
387
    #define __cpu_to_le16(x) ___my_swab16(x)
 
388
 
 
389
typedef uint64_t u_int64_t;
 
390
typedef uint32_t u_int32_t;
 
391
typedef uint16_t u_int16_t;
 
392
typedef uint8_t  u_int8_t;
 
393
 
 
394
#endif
 
395
 
 
396
// Convert BYTES - DWORDS with MEMCPY BE
 
397
#define BYTES_TO_DWORD_BE(dw_dest, byte_src) do {   u_int32_t tmp;\
 
398
                                                    memcpy(&tmp, byte_src, 4);\
 
399
                                                    *(dw_dest) = __be32_to_cpu(tmp);\
 
400
                                                } while (0)
 
401
 
 
402
#define DWORD_TO_BYTES_BE(bytes_dest, dw_src) do { u_int32_t tmp;\
 
403
                                                   tmp = __cpu_to_be32(*(dw_src));\
 
404
                                                   memcpy(bytes_dest, &tmp, 4);\
 
405
                                                 } while (0)
 
406
 
 
407
/*
 
408
 * Old GCC
 
409
 * -------
 
410
 */
 
411
#if !defined(__WIN__) && defined(__cplusplus) && __GNUG__ < 3
 
412
    #include <algo.h>
 
413
#endif
 
414
 
 
415
#define __STDC_FORMAT_MACROS
 
416
#if !defined(__WIN__) && !defined(UEFI_BUILD)
 
417
    #include <inttypes.h>
 
418
#endif
 
419
 
 
420
#ifdef __VMKERNEL_USER_WORLD__
 
421
    #define ROOT_PATH "/opt/mellanox/"
 
422
#else
 
423
    #define ROOT_PATH "/"
 
424
#endif
 
425
 
 
426
#endif
 
427