Adding some msvc specific defines
authorElizabeth Smith <elizabeths@fb.com>
Tue, 6 May 2014 18:21:11 +0000 (11:21 -0700)
committerDave Watson <davejwatson@fb.com>
Tue, 20 May 2014 19:53:57 +0000 (12:53 -0700)
Summary:
msvc puts ssize_t in a stupidly odd place and names it weirdly too
this also takes care of snprintf missing (the semantics are slightly off in the msvc version regarding the return value, but usage in folly is limited and does NOT do the double snprintf call madness so this is safe)
funcsig and pretty function give you roughtly the same thing in compiler specific implementations
strerror_s is msvc's thread save strerror

@override-unit-failures

Test Plan: fbmake runtests

Reviewed By: delong.j@fb.com

FB internal diff: D1291542

folly/Portability.h

index a29862c35a770044c71a522a3c41f4c6dfd52da2..4d623eb4908d32a60806d02dc1e2eb5c0b796172 100644 (file)
@@ -188,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_