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(-) (limited to 'bin') 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 wrap'>Commit message (Collapse)Author 2020-06-08Replace __dead2 with __attribute__((noreturn))June McEnroe sed 's/__dead2/__attribute__((noreturn))/' 2020-06-08Replace __FBSDID macros with commentsJune McEnroe sed -E 's|__FBSDID[(]"([^"]+)"[)];|/* \1 */|' 2020-06-08Remove reference to FreeBSD-specific libedit hackJune McEnroe Newer versions of libedit have sane tab-complete now without FreeBSD's hacks, and in fact the hack is gone in FreeBSD-CURRENT. I'm still a little confused why binding this weird function is necessary at all, but at least it exists everywhere, I guess. 2020-06-08Prefix mandoc with exec in about-filterJune McEnroe 2020-06-07Remove mktemp options from mkbuiltins, mktokensJune McEnroe Why even? 2020-06-07Cast z_stream fields to size_tJune McEnroe In the version of zlib in OpenBSD, these fields are of type off_t, which is signed (why?), rather than uLong. 2020-06-07Call static_assert by _Static_assertJune McEnroe OpenBSD doesn't #define static_assert in assert.h and _Static_assert is its real name I guess so why not? 2020-06-07Add OpenBSD to install.shJune McEnroe Straightforward. 2020-06-03Add The Song of AchillesJune McEnroe 2020-06-01Allow redirecting input in everJune McEnroe 2020-05-31Add %c conversion to c scriptJune McEnroe 2020-05-31Add c script to READMEJune McEnroe 2020-05-31Add c scriptJune McEnroe 2020-05-31Update mdoc source URLsJune McEnroe 2020-05-26Remove unfinished PSF fontsJune McEnroe