From a153d73da2ac4387b1edfe6563c172becb9e6311 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Fri, 23 Feb 2018 18:06:02 -0500 Subject: Clean up xx There are probably like 12 commits with this title. --- bin/xx.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/bin/xx.c b/bin/xx.c index 25b84e2e..688db8bc 100644 --- a/bin/xx.c +++ b/bin/xx.c @@ -23,9 +23,9 @@ #include #include -static bool zero(const uint8_t *buf, size_t len) { - for (size_t i = 0; i < len; ++i) { - if (buf[i]) return false; +static bool zero(const uint8_t *ptr, size_t size) { + for (size_t i = 0; i < size; ++i) { + if (ptr[i]) return false; } return true; } @@ -43,10 +43,13 @@ static void dump(FILE *file) { uint8_t buf[options.cols]; size_t offset = 0; - for (size_t len; (len = fread(buf, 1, sizeof(buf), file)); offset += len) { - + for ( + size_t size; + (size = fread(buf, 1, sizeof(buf), file)); + offset += size + ) { if (options.skip) { - if (zero(buf, len)) { + if (zero(buf, size)) { if (!skip) printf("*\n"); skip = true; continue; @@ -65,7 +68,7 @@ static void dump(FILE *file) { printf(" "); } } - if (i < len) { + if (i < size) { printf("%02hhx ", buf[i]); } else { printf(" "); @@ -74,7 +77,7 @@ static void dump(FILE *file) { if (options.ascii) { printf(" "); - for (size_t i = 0; i < len; ++i) { + for (size_t i = 0; i < size; ++i) { if (options.group) { if (i && !(i % options.group)) { printf(" "); @@ -91,7 +94,7 @@ static void dump(FILE *file) { static void undump(FILE *file) { uint8_t byte; int match; - while (1 == (match = fscanf(file, " %hhx", &byte))) { + while (0 < (match = fscanf(file, " %hhx", &byte))) { printf("%c", byte); } if (!match) errx(EX_DATAERR, "invalid input"); @@ -99,7 +102,7 @@ static void undump(FILE *file) { int main(int argc, char *argv[]) { bool reverse = false; - char *path = NULL; + const char *path = NULL; int opt; while (0 < (opt = getopt(argc, argv, "ac:g:rsz"))) { @@ -124,7 +127,7 @@ int main(int argc, char *argv[]) { } else { dump(file); } - if (ferror(file)) err(EX_IOERR, "%s", path); + return EX_OK; } -- cgit 1.4.1 th>Commit message (Expand)Author 2014-01-14filter: add support for email filterJason A. Donenfeld 2014-01-14filter: return on null filter from open and closeJason A. Donenfeld 2014-01-14filter: add lua supportJason A. Donenfeld 2014-01-14filter: basic write hooking infrastructureJason A. Donenfeld 2014-01-14filter: allow for cleanup hook for filter typesJason A. Donenfeld 2014-01-14filter: introduce "filter type" prefixJohn Keeping 2014-01-14filter: add interface layerJohn Keeping 2014-01-14filter: add fprintf_filter functionJohn Keeping 2014-01-14authors: specify maintainersJason A. Donenfeld 2014-01-13filters: Improved syntax-highlighting.pyStefan Tatschner 2014-01-12tests: add CGIT_TEST_OPTS variable to MakefileJohn Keeping 2014-01-12ui-repolist: HTML-escape cgit_rooturl() responseJohn Keeping 2014-01-12ui-shared: URL-escape script_nameJohn Keeping 2014-01-12ui-refs: escape HTML chars in author and tagger namesJohn Keeping 2014-01-12filter: pass extra arguments via cgit_open_filterJohn Keeping 2014-01-12ui-snapshot: set unused cgit_filter fields to zeroJohn Keeping 2014-01-12html: remove redundant htmlfd variableJohn Keeping 2014-01-12tests: add Valgrind supportJohn Keeping 2014-01-12cache: don't leave cache_slot fields uninitializedJohn Keeping 2014-01-10filter: split filter functions into their own fileJason A. Donenfeld 2014-01-10filter: make exit status localJason A. Donenfeld 2014-01-10parsing: fix header typoJason A. Donenfeld 2014-01-10cgit.c: Fix comment on bit mask hackLukas Fleischer 2014-01-10cgit.c: Use "else" for mutually exclusive branchesLukas Fleischer 2014-01-10ui-snapshot.c: Do not reinvent suffixcmp()Lukas Fleischer 2014-01-10Refactor cgit_parse_snapshots_mask()Lukas Fleischer 2014-01-10Disallow use of undocumented snapshot delimitersLukas Fleischer 2014-01-10Replace most uses of strncmp() with prefixcmp()Lukas Fleischer 2014-01-09README: Fix dependenciesLukas Fleischer 2014-01-08README: Spelling and formatting fixesLukas Fleischer 2014-01-08Fix UTF-8 with syntax-highlighting.pyPřemysl Janouch 2014-01-08Add a suggestion to the manpagePřemysl Janouch 2014-01-08Fix the example configurationPřemysl Janouch 2014-01-08Fix about-formatting.shPřemysl Janouch 2014-01-08Fix some spelling errorsPřemysl Janouch 2014-01-08filters: highlight.sh: add css comments for highlight 2.6 and 3.8Ferry Huberts