X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=fwcutter%2Ffwcutter.c;h=79e351f6dd4c3ca5ff297bd301f7c497b614117b;hb=a73ba526c3bd9f4e95cc95808d7487607c651cd0;hp=5d5aa80d1785bde0335d42afd76b69dec63c564c;hpb=70d21fd8251710ff407fbd3fb3371678c63d7783;p=b43-tools.git diff --git a/fwcutter/fwcutter.c b/fwcutter/fwcutter.c index 5d5aa80..79e351f 100644 --- a/fwcutter/fwcutter.c +++ b/fwcutter/fwcutter.c @@ -65,18 +65,6 @@ static int file_ok(const struct file *f) return !(f->flags & FW_FLAG_UNSUPPORTED) || cmdargs.unsupported; } -/* Convert a CPU-endian 16bit integer to Big-Endian */ -static be16_t to_be16(uint16_t v) -{ - uint8_t ret[2]; - - ret[0] = (v & 0xFF00) >> 8; - ret[1] = (v & 0x00FF); - - return *((be16_t *)ret); -} - -#if 0 /* Convert a Big-Endian 16bit integer to CPU-endian */ static uint16_t from_be16(be16_t v) { @@ -87,19 +75,11 @@ static uint16_t from_be16(be16_t v) return ret; } -#endif -/* Convert a CPU-endian 32bit integer to Big-Endian */ -static be32_t to_be32(uint32_t v) +/* Convert a CPU-endian 16bit integer to Big-Endian */ +static be16_t to_be16(uint16_t v) { - uint8_t ret[4]; - - ret[0] = (v & 0xFF000000) >> 24; - ret[1] = (v & 0x00FF0000) >> 16; - ret[2] = (v & 0x0000FF00) >> 8; - ret[3] = (v & 0x000000FF); - - return *((be32_t *)ret); + return (be16_t)from_be16((be16_t)v); } /* Convert a Big-Endian 32bit integer to CPU-endian */ @@ -115,6 +95,12 @@ static uint32_t from_be32(be32_t v) return ret; } +/* Convert a CPU-endian 32bit integer to Big-Endian */ +static be32_t to_be32(uint32_t v) +{ + return (be32_t)from_be32((be32_t)v); +} + /* tiny disassembler */ static void print_ucode_version(struct insn *insn) { @@ -462,10 +448,10 @@ static void print_supported_files(void) "\t" "\n\n"); /* print for legacy driver first */ - for (i = 0; i < FILES; i++) + for (i = 0; i < ARRAY_SIZE(files); i++) if (file_ok(&files[i]) && !(files[i].flags & FW_FLAG_V4)) print_file(&files[i]); - for (i = 0; i < FILES; i++) + for (i = 0; i < ARRAY_SIZE(files); i++) if (file_ok(&files[i]) && files[i].flags & FW_FLAG_V4) print_file(&files[i]); printf("\n"); @@ -491,7 +477,7 @@ static const struct file *find_file(FILE *fd) signature[8], signature[9], signature[10], signature[11], signature[12], signature[13], signature[14], signature[15]); - for (i = 0; i < FILES; ++i) { + for (i = 0; i < ARRAY_SIZE(files); i++) { if (file_ok(&files[i]) && strcasecmp(md5sig, files[i].md5) == 0) { printf("This file is recognised as:\n");