summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-02-23 18:06:02 -0500
committerJune McEnroe <june@causal.agency>2018-02-23 18:06:02 -0500
commitd1dc82b4c29c4969393b8c4027b29ca9cc2249df (patch)
tree0d4c8c87a57def499d6004d0a7b197f8f018ba42 /bin
parentClean up wake (diff)
downloadsrc-d1dc82b4c29c4969393b8c4027b29ca9cc2249df.tar.gz
src-d1dc82b4c29c4969393b8c4027b29ca9cc2249df.zip
Clean up xx
There are probably like 12 commits with this title.
Diffstat (limited to '')
-rw-r--r--bin/xx.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/bin/xx.c b/bin/xx.c
index 0d674162..e610c276 100644
--- a/bin/xx.c
+++ b/bin/xx.c
@@ -23,9 +23,9 @@
 #include <sysexits.h>
 #include <unistd.h>
 
-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;
 }