From 16e2520bf8d3ac90012bbda150d39856064439c3 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 15 May 2021 10:10:24 -0500 Subject: Style cleanup. --- toys/posix/file.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'toys/posix') 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))0x70 && !memcmp(s, "MZ", 2) && + (magic=peek_le(s+0x3c,4))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 0x32 && !memcmp(s, "BM", 2) && !memcmp(s+6, "\0\0\0\0", 4)) { -- cgit v1.2.3