Adding some msvc specific defines
[folly.git] / folly / Portability.h
index 43953f931a064c4afeb55d8a606afa8f65b1b928..4d623eb4908d32a60806d02dc1e2eb5c0b796172 100644 (file)
@@ -79,6 +79,21 @@ struct MaxAlign { char c; } __attribute__((aligned));
 # define FOLLY_X64 0
 #endif
 
+// packing is very ugly in msvc
+#ifdef _MSC_VER
+# define FOLLY_PACK_ATTR /**/
+# define FOLLY_PACK_PUSH __pragma(pack(push, 1))
+# define FOLLY_PACK_POP __pragma(pack(pop))
+#elif defined(__clang__) || defined(__GNUC__)
+# define FOLLY_PACK_ATTR __attribute__((packed))
+# define FOLLY_PACK_PUSH /**/
+# define FOLLY_PACK_POP /**/
+#else
+# define FOLLY_PACK_ATTR /**/
+# define FOLLY_PACK_PUSH /**/
+# define FOLLY_PACK_POP /**/
+#endif
+
 // portable version check
 #ifndef __GNUC_PREREQ
 # if defined __GNUC__ && defined __GNUC_MINOR__
@@ -173,4 +188,24 @@ struct MaxAlign { char c; } __attribute__((aligned));
 #endif
 #endif // __cplusplus
 
+// MSVC specific defines
+// mainly for posix compat
+#ifdef _MSC_VER
+
+// this definition is in a really silly place with a silly name
+// and ifdefing it every time we want it is painful
+#include <basetsd.h>
+typedef SSIZE_T ssize_t;
+
+// sprintf semantics are not exactly identical
+// but current usage is not a problem
+# define snprintf _snprintf
+
+// semantics here are identical
+# define strerror_r(errno,buf,len) strerror_s(buf,len,errno)
+
+// compiler specific to compiler specific
+# define __PRETTY_FUNCTION__ __FUNCSIG__
+#endif
+
 #endif // FOLLY_PORTABILITY_H_