Go to the documentation of this file.00001
00019
00020
00021 #ifndef _PLATFORM_HACKS_H_
00022 #define _PLATFORM_HACKS_H_
00023
00024 #ifdef __GNUC__
00025 #define MONGO_INLINE static __inline__
00026 #else
00027 #define MONGO_INLINE static
00028 #endif
00029
00030 #ifdef __cplusplus
00031 #define MONGO_EXTERN_C_START extern "C" {
00032 #define MONGO_EXTERN_C_END }
00033 #else
00034 #define MONGO_EXTERN_C_START
00035 #define MONGO_EXTERN_C_END
00036 #endif
00037
00038
00039 #if defined(MONGO_HAVE_STDINT) || __STDC_VERSION__ >= 199901L
00040 #include <stdint.h>
00041 #elif defined(MONGO_HAVE_UNISTD)
00042 #include <unistd.h>
00043 #elif defined(MONGO_USE__INT64)
00044 typedef __int64 int64_t;
00045 typedef unsigned __int64 uint64_t;
00046 #elif defined(MONGO_USE_LONG_LONG_INT)
00047 typedef long long int int64_t;
00048 typedef unsigned long long int uint64_t;
00049 #else
00050 #error must have a 64bit int type
00051 #endif
00052
00053
00054 #ifdef MONGO_BIG_ENDIAN
00055 #define bson_little_endian64(out, in) ( bson_swap_endian64(out, in) )
00056 #define bson_little_endian32(out, in) ( bson_swap_endian32(out, in) )
00057 #define bson_big_endian64(out, in) ( memcpy(out, in, 8) )
00058 #define bson_big_endian32(out, in) ( memcpy(out, in, 4) )
00059 #else
00060 #define bson_little_endian64(out, in) ( memcpy(out, in, 8) )
00061 #define bson_little_endian32(out, in) ( memcpy(out, in, 4) )
00062 #define bson_big_endian64(out, in) ( bson_swap_endian64(out, in) )
00063 #define bson_big_endian32(out, in) ( bson_swap_endian32(out, in) )
00064 #endif
00065
00066 MONGO_EXTERN_C_START
00067
00068 MONGO_INLINE void bson_swap_endian64(void* outp, const void* inp){
00069 const char *in = (const char*)inp;
00070 char *out = (char*)outp;
00071
00072 out[0] = in[7];
00073 out[1] = in[6];
00074 out[2] = in[5];
00075 out[3] = in[4];
00076 out[4] = in[3];
00077 out[5] = in[2];
00078 out[6] = in[1];
00079 out[7] = in[0];
00080
00081 }
00082 MONGO_INLINE void bson_swap_endian32(void* outp, const void* inp){
00083 const char *in = (const char*)inp;
00084 char *out = (char*)outp;
00085
00086 out[0] = in[3];
00087 out[1] = in[2];
00088 out[2] = in[1];
00089 out[3] = in[0];
00090 }
00091
00092 MONGO_EXTERN_C_END
00093
00094 #endif