Another pass at file.c: move posix-required "executable" to front of output,
next few fields in the order the other implementation outputs, fewer commas,
fix a big where big endian executable type wasn't detected right,
and fix the filehandle leak.
diff --git a/toys/pending/file.c b/toys/pending/file.c
index fbff586..1894122 100644
--- a/toys/pending/file.c
+++ b/toys/pending/file.c
@@ -46,39 +46,40 @@
     {0xabc7, "xtensa-old"}
   };
 
-  xprintf("ELF ");
+  printf("ELF ");
+
+  // executable (ELF says this is short but reality says byte, not MSB swapped)
+  i = toybuf[16];
+  if (i == 1) printf("relocatable");
+  else if (i == 2) printf("executable");
+  else if (i == 3) printf("shared object");
+  else if (i == 4) printf("core dump");
+  else printf("(bad type %d)", i);
+  printf(", ");
 
   // "64-bit"
-  if (bits == 1) xprintf("32-bit ");
-  else if (bits == 2) xprintf("64-bit ");
+  if (bits == 1) printf("32-bit ");
+  else if (bits == 2) printf("64-bit ");
   else {
-    xprintf("(bad class %d) ", bits);
+    printf("(bad class %d) ", bits);
     bits = 0;
   }
 
+  // "LSB"
+  if (endian == 1) printf("LSB ");
+  else if (endian == 2) {
+    printf("MSB ");
+    elf_int = peek_be;
+  } else {
+    printf("(bad endian %d) \n", endian);
+    endian = 0;
+  }
+
   // e_machine, ala "x86", from big table above
   j = elf_int(toybuf+18, 2);
   for (i = 0; i<ARRAY_LEN(type); i++) if (j==type[i].val) break;
-  if (i<ARRAY_LEN(type)) xprintf("%s ", type[i].name);
-  else xprintf("(unknown arch %d) ", j);
-
-  // "LSB"
-  if (endian == 1) xprintf("LSB ");
-  else if (endian == 2) {
-    xprintf("MSB ");
-    elf_int = peek_be;
-  } else {
-    xprintf("(bad endian %d)\n", endian);
-    endian = 0;
-  }
-
-  // ", executable"
-  i = elf_int(toybuf+16, 2);
-  if (i == 1) xprintf("relocatable");
-  else if (i == 2) xprintf("executable");
-  else if (i == 3) xprintf("shared object");
-  else if (i == 4) xprintf("core dump");
-  else xprintf("(bad type %d)", i);
+  if (i<ARRAY_LEN(type)) printf("%s", type[i].name);
+  else printf("(unknown arch %d)", j);
 
   bits--;
   // If we know our bits and endianness and phentsize agrees show dynamic linker
@@ -94,7 +95,7 @@
     // map e_phentsize*e_phnum bytes at e_phoff
     map = mmap(0, phsize*phnum, PROT_READ, MAP_SHARED, fd, mapoff);
     if (map) {
-      // Find PT_INTERP entry. (Not: fields got reordered for 64 bit)
+      // Find PT_INTERP entry. (Note: fields got reordered for 64 bit)
       for (i = 0; i<phnum; i++) {
         long long dlpos, dllen;
 
@@ -110,10 +111,10 @@
         if (dllen<0 || dllen>sizeof(toybuf)-128
             || dlpos!=lseek(fd, dlpos, SEEK_SET)
             || dllen!=readall(fd, toybuf+128, dllen)) break;
-        printf(", dynamic (%.*s)", (int)dllen, toybuf+128);
+        printf(", dynamic (%.*s", (int)dllen, toybuf+128);
       }
       if (!lib) printf(", static");
-      else printf(", needs %d lib%s", lib, lib>1 ? "s" : "");
+      else printf(" loads %d lib%s)", lib, lib>1 ? "s" : "");
       munmap(map, phsize*phnum);
     }
   }
@@ -250,13 +251,11 @@
         int fd = !strcmp(name, "-") ? 0 : open(name, O_RDONLY);
 
         if (fd!=-1) {
-          if (sb.st_size == 0) what = "empty";
-          else {
-            do_regular_file(fd, name);
-            continue;
-          }
+          if (!sb.st_size) what = "empty";
+          else do_regular_file(fd, name);
+          if (fd) close(fd);
+          if (sb.st_size) continue;
         }
-        if (fd>0) close(fd);
       } else if (S_ISBLK(sb.st_mode)) what = "block special";
       else if (S_ISCHR(sb.st_mode)) what = "character special";
       else if (S_ISDIR(sb.st_mode)) what = "directory";