adb: make sure that file mode macros match linux.

We use <sys/stat.h> mode macros on the host to parse modes sent over
from the device, so they had better match. Add static_asserts to ensure
this.

(Also, fix the cases where they don't.)

Test: mma -j48, compiled the static_asserts on darwin manually
Change-Id: I883e4e6c7489ea64d3c02d26790ac8293366d989
diff --git a/file_sync_client.cpp b/file_sync_client.cpp
index 115095c..caa7a5f 100644
--- a/file_sync_client.cpp
+++ b/file_sync_client.cpp
@@ -43,6 +43,7 @@
 #include "adb_utils.h"
 #include "file_sync_service.h"
 #include "line_printer.h"
+#include "sysdeps/stat.h"
 
 #include <android-base/file.h>
 #include <android-base/strings.h>
@@ -64,15 +65,11 @@
 }
 
 static bool should_pull_file(mode_t mode) {
-    return mode & (S_IFREG | S_IFBLK | S_IFCHR);
+    return S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode);
 }
 
 static bool should_push_file(mode_t mode) {
-    mode_t mask = S_IFREG;
-#if !defined(_WIN32)
-    mask |= S_IFLNK;
-#endif
-    return mode & mask;
+    return S_ISREG(mode) || S_ISLNK(mode);
 }
 
 struct copyinfo {
diff --git a/sysdeps.h b/sysdeps.h
index 0489d09..05d9fde 100644
--- a/sysdeps.h
+++ b/sysdeps.h
@@ -180,8 +180,6 @@
     /* nothing really */
 }
 
-#define  S_ISLNK(m)   0   /* no symlinks on Win32 */
-
 extern int  adb_unlink(const char*  path);
 #undef  unlink
 #define unlink  ___xxx_unlink
diff --git a/sysdeps/stat.h b/sysdeps/stat.h
index 5953595..ed2cf25 100644
--- a/sysdeps/stat.h
+++ b/sysdeps/stat.h
@@ -43,4 +43,21 @@
 // Windows doesn't have lstat.
 #define lstat adb_stat
 
+// mingw doesn't define S_IFLNK or S_ISLNK.
+#define S_IFLNK 0120000
+#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
+
+// mingw defines S_IFBLK to a different value from bionic.
+#undef S_IFBLK
+#define S_IFBLK 0060000
+#undef S_ISBLK
+#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
 #endif
+
+// Make sure that host file mode values match the ones on the device.
+static_assert(S_IFMT == 00170000, "");
+static_assert(S_IFLNK == 0120000, "");
+static_assert(S_IFREG == 0100000, "");
+static_assert(S_IFBLK == 0060000, "");
+static_assert(S_IFDIR == 0040000, "");
+static_assert(S_IFCHR == 0020000, "");