Mercurial > vba-clojure
view src/Port.h @ 24:59790d015f25 works-incomplete
checkpoint
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 04 Mar 2012 17:50:56 -0600 |
parents | f9f4f1b99eed |
children | 48369c6aeaa0 |
line wrap: on
line source
1 #ifndef VBA_PORT_H2 #define VBA_PORT_H4 #if _MSC_VER > 10005 #pragma once6 #endif // _MSC_VER > 10008 #include <ctime>10 #ifndef NULL11 #define NULL 012 #endif14 typedef unsigned char bool8;16 #ifdef HAVE_STDINT_H17 #include <stdint.h>19 typedef int8_t int8;20 typedef uint8_t uint8;21 typedef int16_t int16;22 typedef uint16_t uint16;23 typedef int32_t int32;24 typedef uint32_t uint32;25 typedef int64_t int64;26 typedef uint64_t uint64;27 typedef intptr_t pint;29 #else /* Don't have stdint.h */31 #ifdef PTR_NOT_INT32 typedef long pint;33 #else /* pointer is int */34 typedef int pint;35 #endif /* PTR_NOT_INT */37 /* FIXME: Refactor this by moving out the BORLAND part and unifying typedefs */38 #ifndef WIN3239 typedef unsigned char uint8;40 typedef unsigned short uint16;41 typedef signed char int8;42 typedef short int16;43 typedef int int32;44 typedef unsigned int uint32;45 # ifdef __GNUC__ /* long long is not part of ISO C++ */46 __extension__ typedef long long int64;47 __extension__ typedef unsigned long long uint64;48 # else49 typedef long long int64;50 typedef unsigned long long uint64;51 # endif52 #else /* WIN32 */54 # ifdef __BORLANDC__55 # include <systypes.h>56 # else58 typedef unsigned char uint8;59 typedef unsigned short uint16;60 typedef signed char int8;61 typedef short int16;63 # ifndef WSAAPI64 /* winsock2.h typedefs int32 as well. */65 typedef long int32;66 # endif68 typedef unsigned int uint32;70 # endif /* __BORLANDC__ */72 typedef __int64 int64;73 typedef unsigned __int64 uint64;75 #endif /* WIN32 */76 #endif /* HAVE_STDINT_H */78 #ifndef WIN3280 #ifndef PATH_MAX81 #define PATH_MAX 102482 #endif84 #define _MAX_DIR PATH_MAX85 #define _MAX_DRIVE 186 #define _MAX_FNAME PATH_MAX87 #define _MAX_EXT PATH_MAX88 #define _MAX_PATH PATH_MAX90 #define ZeroMemory(a, b) memset((a), 0, (b))92 void _makepath(char *path, const char *drive, const char *dir,93 const char *fname, const char *ext);94 void _splitpath(const char *path, char *drive, char *dir, char *fname,95 char *ext);96 #else /* WIN32 */97 #define strcasecmp stricmp98 #define strncasecmp strnicmp99 #endif101 typedef uint8 u8;102 typedef uint16 u16;103 typedef uint32 u32;104 typedef uint64 u64;105 typedef int8 s8;106 typedef int16 s16;107 typedef int32 s32;108 typedef int64 s64;110 // for consistency111 static inline u8 swap8(u8 v)112 {113 return v;114 }116 // swaps a 16-bit value117 static inline u16 swap16(u16 v)118 {119 return (v<<8)|(v>>8);120 }122 // swaps a 32-bit value123 static inline u32 swap32(u32 v)124 {125 return (v<<24)|((v<<8)&0xff0000)|((v>>8)&0xff00)|(v>>24);126 }128 #define READ8LE(x) \129 *((u8 *)x)131 #define WRITE8LE(x, v) \132 *((u8 *)x) = (v)134 #ifdef WORDS_BIGENDIAN135 #if defined(__GNUC__) && defined(__ppc__)137 #define READ16LE(base) \138 ({ unsigned short lhbrxResult; \139 __asm__("lhbrx %0, 0, %1" : "=r" (lhbrxResult) : "r" (base) : "memory"); \140 lhbrxResult; })142 #define READ32LE(base) \143 ({ unsigned long lwbrxResult; \144 __asm__("lwbrx %0, 0, %1" : "=r" (lwbrxResult) : "r" (base) : "memory"); \145 lwbrxResult; })147 #define WRITE16LE(base, value) \148 __asm__("sthbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")150 #define WRITE32LE(base, value) \151 __asm__("stwbrx %0, 0, %1" : : "r" (value), "r" (base) : "memory")153 #else154 #define READ16LE(x) \155 swap16(*((u16 *)(x)))156 #define READ32LE(x) \157 swap32(*((u32 *)(x)))158 #define WRITE16LE(x, v) \159 *((u16 *)x) = swap16((v))160 #define WRITE32LE(x, v) \161 *((u32 *)x) = swap32((v))162 #endif163 #else164 #define READ16LE(x) \165 *((u16 *)x)166 #define READ32LE(x) \167 *((u32 *)x)168 #define WRITE16LE(x, v) \169 *((u16 *)x) = (v)170 #define WRITE32LE(x, v) \171 *((u32 *)x) = (v)172 #endif174 #ifndef CTASSERT175 #define CTASSERT(x) typedef char __assert ## y[(x) ? 1 : -1];176 #endif178 #endif // VBA_PORT_H