diff options
author | Rob Landley <rob@landley.net> | 2021-05-15 10:10:24 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2021-05-15 10:10:24 -0500 |
commit | 16e2520bf8d3ac90012bbda150d39856064439c3 (patch) | |
tree | d875a6beba17a1b1b175d4e25abced9518b85ab2 /toys | |
parent | 3748313ffd75cf177d90e209a269e17913fed111 (diff) | |
download | toybox-16e2520bf8d3ac90012bbda150d39856064439c3.tar.gz |
Style cleanup.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/file.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/toys/posix/file.c b/toys/posix/file.c index ecb3fc43..0f8b5314 100644 --- a/toys/posix/file.c +++ b/toys/posix/file.c @@ -243,7 +243,7 @@ static void do_regular_file(int fd, char *name) (int)peek_be(s+2, 2), (int)peek_be(s, 2), (int)peek_be(s+2, 2)-44); // https://source.android.com/devices/tech/dalvik/dex-format#dex-file-magic - else if (len>8 && strstart(&s, "dex\n") && s[3] == 0) + else if (len>8 && strstart(&s, "dex\n") && !s[3]) xprintf("Android dex file, version %s\n", s); // https://people.freebsd.org/~kientzle/libarchive/man/cpio.5.txt @@ -256,13 +256,13 @@ static void do_regular_file(int fd, char *name) else if (toybuf[5] == '1') cpioformat = "SVR4 with no CRC"; else if (toybuf[5] == '2') cpioformat = "SVR4 with CRC"; xprintf("ASCII cpio archive (%s)\n", cpioformat); - } else if (len>33 && (magic=peek(&s,2), magic==0143561 || magic==070707)) { + } else if (len>33 && ((magic=peek(&s,2))==0143561 || magic==070707)) { if (magic == 0143561) printf("byte-swapped "); xputs("cpio archive"); // tar archive (old, ustar/pax, or gnu) } else if (len>500 && is_tar_header(s)) xprintf("%s tar archive%s\n", s[257] ? "POSIX" : "old", - strncmp(s+262," ",2)?"":" (GNU)"); + (s[262]!=' ' || s[263]!=' ')?"":" (GNU)"); // zip/jar/apk archive, ODF/OOXML document, or such else if (len>5 && strstart(&s, "PK\03\04")) { int ver = toybuf[4]; @@ -278,19 +278,18 @@ static void do_regular_file(int fd, char *name) xputc('\n'); } else if (len>4 && strstart(&s, "BZh") && isdigit(*s)) xprintf("bzip2 compressed data, block size = %c00k\n", *s); - else if (len > 31 && peek_be(s, 7) == 0xfd377a585a0000UL) + else if (len>31 && peek_be(s, 7) == 0xfd377a585a0000UL) xputs("xz compressed data"); else if (len>10 && strstart(&s, "\x1f\x8b")) xputs("gzip compressed data"); else if (len>32 && !memcmp(s+1, "\xfa\xed\xfe", 3)) { - int bit = s[0]=='\xce'?32:64; - char *what; + int bit = (*s==0xce) ? 32 : 64; + char *what = 0; 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]); @@ -322,14 +321,14 @@ static void do_regular_file(int fd, char *name) } else if (len>32 && !memcmp(s, "RIF", 3) && !memcmp(s+8, "WAVEfmt ", 8)) { // https://en.wikipedia.org/wiki/WAV int le = (s[3] == 'F'); - int format = le ? peek_le(s+20,2) : peek_be(s+20,2); - int channels = le ? peek_le(s+22,2) : peek_be(s+22,2); - int hz = le ? peek_le(s+24,4) : peek_be(s+24,4); - int bits = le ? peek_le(s+34,2) : peek_be(s+34,2); + int format = le ? peek_le(s+20, 2) : peek_be(s+20, 2); + int channels = le ? peek_le(s+22, 2) : peek_be(s+22, 2); + int hz = le ? peek_le(s+24, 4) : peek_be(s+24, 4); + int bits = le ? peek_le(s+34, 2) : peek_be(s+34, 2); xprintf("WAV audio, %s, ", le ? "LE" : "BE"); - if (bits != 0) xprintf("%d-bit, ", bits); - if (channels==1||channels==2) xprintf("%s, ", channels==1?"mono":"stereo"); + if (bits) xprintf("%d-bit, ", bits); + if (channels==1||channels==2) xprintf("%s, ",(channels==1)?"mono":"stereo"); else xprintf("%d-channel, ", channels); xprintf("%d Hz, ", hz); // See https://tools.ietf.org/html/rfc2361, though there appear to be bugs @@ -353,27 +352,24 @@ static void do_regular_file(int fd, char *name) (int)peek_be(s+4, 2), (int)peek_be(s+8, 4)); // https://docs.microsoft.com/en-us/typography/opentype/spec/otff - } else if (len>12 && !memcmp(s, "OTTO", 4)) { - xputs("OpenType font"); - } else if (len>4 && !memcmp(s, "BC\xc0\xde", 4)) { - xputs("LLVM IR bitcode"); - } else if (strstart(&s, "-----BEGIN CERTIFICATE-----")) { - xputs("PEM certificate"); + } else if (len>12 && !memcmp(s, "OTTO", 4)) xputs("OpenType font"); + else if (len>4 && !memcmp(s, "BC\xc0\xde", 4)) xputs("LLVM IR bitcode"); + else if (strstart(&s,"-----BEGIN CERTIFICATE-----")) xputs("PEM certificate"); // https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx - } else if (len>0x70 && !memcmp(s, "MZ", 2) && - (magic=peek_le(s+0x3c,4))<len-4 && !memcmp(s+magic, "\x50\x45\0\0", 4)) { + else if (len>0x70 && !memcmp(s, "MZ", 2) && + (magic=peek_le(s+0x3c,4))<len-4 && !memcmp(s+magic, "\x50\x45\0", 4)) { xprintf("MS PE32%s executable %s", (peek_le(s+magic+24, 2)==0x20b)?"+":"", (peek_le(s+magic+22, 2)&0x2000)?"(DLL) ":""); if (peek_le(s+magic+20, 2)>70) { char *types[] = {0, "native", "GUI", "console", "OS/2", "driver", "CE", "EFI", "EFI boot", "EFI runtime", "EFI ROM", "XBOX", 0, "boot"}; - int type = peek_le(s+magic+92, 2); - char *name = (type>0 && type<ARRAY_LEN(types))?types[type]:0; + unsigned type = peek_le(s+magic+92, 2); + char *name = (type<ARRAY_LEN(types)) ? types[type] : 0; - xprintf("(%s) ", name?name:"unknown"); + xprintf("(%s) ", name ? : "unknown"); } - xprintf("%s\n", (peek_le(s+magic+4, 2)==0x14c)?"x86":"x86-64"); + xprintf("x86%s\n", (peek_le(s+magic+4, 2)==0x14c) ? "" : "-64"); // https://en.wikipedia.org/wiki/BMP_file_format } else if (len > 0x32 && !memcmp(s, "BM", 2) && !memcmp(s+6, "\0\0\0\0", 4)) { |