-/* no stdint.h in < C99 */
-#if __STDC_VERSION__ < 199901L
-# if CHAR_MIN == -128
- typedef unsigned char uint8_t; /* same as below */
-# elif SCHAR_MIN == -128
- typedef unsigned char uint8_t; /* same as above */
-# endif
-# if SHRT_MAX == 0x7FFF
- typedef short int16_t;
- typedef unsigned short uint16_t;
-# elif INT_MAX == 0x7FFF
- typedef int int16_t;
- typedef unsigned int uint16_t;
+#ifndef _MSC_VER
+# include <stdint.h>
+#else
+ typedef unsigned __int8 uint8_t;
+ typedef unsigned __int16 uint16_t;
+ typedef unsigned __int32 uint32_t;
+ typedef unsigned __int64 uint64_t;
+
+ typedef __int16 int16_t;
+ typedef __int32 int32_t;
+ typedef __int64 int64_t;
+#endif
+
+/*
+ *windows makes these prefixed because they're C99
+ * TODO: utility versions that are type-safe and not
+ * just plain textual subsitution.
+ */
+#ifdef _MSC_VER
+# define snprintf(X, Y, Z, ...) _snprintf(X, Y, Z, __VA_ARGS__)
+ /* strtof doesn't exist -> strtod does though :) */
+# define strtof(X, Y) (float)(strtod(X, Y))
+#endif
+
+/*
+ * Very roboust way at determining endianess at compile time: this handles
+ * almost every possible situation. Otherwise a runtime check has to be
+ * performed.
+ */
+#define GMQCC_BYTE_ORDER_LITTLE 1234
+#define GMQCC_BYTE_ORDER_BIG 4321
+
+#if defined (__GNUC__) || defined (__GNU_LIBRARY__)
+# if defined (__FreeBSD__) || defined (__OpenBSD__)
+# include <sys/endian.h>
+# elif defined (BSD) && (BSD >= 199103) || defined (__DJGPP__) || defined (__CYGWIN32__)
+# include <machine/endiane.h>
+# elif defined (__APPLE__)
+# if defined (__BIG_ENDIAN__) && !defined(BIG_ENDIAN)
+# define BIG_ENDIAN
+# elif defined (__LITTLE_ENDIAN__) && !defined (LITTLE_ENDIAN)
+# define LITTLE_ENDIAN
+# endif
+# elif !defined (__MINGW32__)
+# include <endian.h>
+# if !defined (__BEOS__)
+# include <byteswap.h>
+# endif