Basic Mach-O support in file(1).

The Nexus Player build was subtly broken in that it assumed that the host was
using ELF. No-one noticed until a Mac user tried to flash their build, which
contained a Mach-O x86 binary instead of an ELF x86 binary. Hilarity ensued.

(On the same day, file(1) was able to explain a mixup with an ELF hexagon
binary. Next time we see a Mach-O binary on an Android device, we'll be ready!)

Bug: http://b/66741960
diff --git a/toys/posix/file.c b/toys/posix/file.c
index 9958d04..2f1e95b 100644
--- a/toys/posix/file.c
+++ b/toys/posix/file.c
@@ -251,7 +251,26 @@
   } else if (len>4 && strstart(&s, "BZh") && isdigit(*s))
     xprintf("bzip2 compressed data, block size = %c00k\n", *s);
   else if (len>10 && strstart(&s, "\x1f\x8b")) xputs("gzip compressed data");
-  else {
+  else if (len>32 && !memcmp(s+1, "\xfa\xed\xfe", 3)) {
+    int bit = s[0]=='\xce'?32:64;
+    char *what;
+
+    xprintf("Mach-O %d-bit ", bit);
+
+    if (s[4] == 7) what = (bit==32)?"x86":"x86-";
+    else if (s[4] == 12) what = "arm";
+    else if (s[4] == 18) what = "ppc";
+    else what = NULL;
+    if (what) xprintf("%s%s ", what, (bit==32)?"":"64");
+    else xprintf("(bad arch %d) ", s[4]);
+
+    if (s[12] == 1) what = "object";
+    else if (s[12] == 2) what = "executable";
+    else if (s[12] == 6) what = "shared library";
+    else what = NULL;
+    if (what) xprintf("%s\n", what);
+    else xprintf("(bad type %d)\n", s[9]);
+  } else {
     char *what = 0;
     int i, bytes;