Snap for 10453563 from 758e9fba6fc9adbf15340f70c73baee7b168b1c9 to mainline-art-release

Change-Id: I9e75aa12471a80e2b074d09620e433b709196279
diff --git a/Android.bp b/Android.bp
index 711ef7c..b35ded7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -40,6 +40,15 @@
         "include",
     ],
     host_supported: true,
+    target: {
+        windows: {
+            enabled: true,
+            cflags: [
+                "-DNOGDI",
+                "-Wno-format",
+            ],
+        },
+    },
 }
 
 cc_library {
@@ -115,11 +124,17 @@
     local_include_dirs: [
         "include/tss2",
         "src",
-        "src/util",
     ],
     shared_libs: [
         "libbase",
     ],
+    target: {
+        windows: {
+            host_ldlibs: [
+                "-lws2_32",
+            ],
+        },
+    },
 }
 
 cc_library {
@@ -127,7 +142,6 @@
     defaults: [ "tpm2-tss-defaults" ],
     srcs: [
         "src/tss2-tcti/tcti-common.c",
-        "src/tss2-tcti/tcti-device.c",
         "src/tss2-tcti/tctildr.c",
         "src/tss2-tcti/tctildr-nodl.c",
     ],
@@ -140,6 +154,13 @@
         "tpm2-tss2-mu",
         "tpm2-tss2-util",
     ],
+    target: {
+        not_windows: {
+            srcs: [
+                "src/tss2-tcti/tcti-device.c",
+            ],
+        },
+    },
 }
 
 cc_library {
diff --git a/src/tss2-tcti/tctildr-nodl.c b/src/tss2-tcti/tctildr-nodl.c
index ca18e58..772178c 100644
--- a/src/tss2-tcti/tctildr-nodl.c
+++ b/src/tss2-tcti/tctildr-nodl.c
@@ -57,7 +57,7 @@
     char *conf;
     char *description;
 } tctis [] = {
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__MINGW32__)
     {
         .names = {
             "libtss2-tcti-tbs.so.0",
diff --git a/src/tss2-tcti/tctildr.c b/src/tss2-tcti/tctildr.c
index a0567ae..614b4d7 100644
--- a/src/tss2-tcti/tctildr.c
+++ b/src/tss2-tcti/tctildr.c
@@ -13,11 +13,13 @@
 #include <inttypes.h>
 #if defined(__linux__)
 #include <linux/limits.h>
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) || defined(__MINGW32__)
 #include <windows.h>
 #include <limits.h>
+
 #ifndef PATH_MAX
 #define PATH_MAX MAX_PATH
+#endif
 
 static char *strndup(const char* s, size_t n)
 {
@@ -34,7 +36,7 @@
     memcpy(dst, s, n);
     return dst;
 }
-#endif
+
 #else
 #include <limits.h>
 #endif
diff --git a/src/util/io.h b/src/util/io.h
index f20ff3e..7586e07 100644
--- a/src/util/io.h
+++ b/src/util/io.h
@@ -7,10 +7,12 @@
 #define UTIL_IO_H
 
 #ifdef _WIN32
-#include <BaseTsd.h>
+#include <basetsd.h>
 #include <winsock2.h>
 #include <ws2tcpip.h>
+#ifdef _MSC_VER
 typedef SSIZE_T ssize_t;
+#endif
 #define _HOST_NAME_MAX MAX_COMPUTERNAME_LENGTH
 
 #else