summary refs log tree commit diff
path: root/.bin/xx.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2016-09-12 14:40:54 -0400
committerJune McEnroe <june@causal.agency>2016-09-12 14:40:54 -0400
commitb6596d2a1c027c776b5681e1306789bf689cbbb3 (patch)
treed98eeb60e5395bd4a591d4362cfe427fb2187c42 /.bin/xx.c
parentRename colorscheme to lame (diff)
downloadsrc-b6596d2a1c027c776b5681e1306789bf689cbbb3.tar.gz
src-b6596d2a1c027c776b5681e1306789bf689cbbb3.zip
Add .bin/xx.c
Diffstat (limited to '')
-rwxr-xr-x.bin/xx.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/.bin/xx.c b/.bin/xx.c
new file mode 100755
index 00000000..d2d86574
--- /dev/null
+++ b/.bin/xx.c
@@ -0,0 +1,36 @@
+#if 0
+exec cc -Weverything -o ~/.bin/xx $0
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+    char *path = NULL;
+
+    if (argc > 1)
+        path = argv[1];
+
+    FILE *file = path ? fopen(path, "r") : stdin;
+    if (!file) {
+        perror(path);
+        return EXIT_FAILURE;
+    }
+
+    uint8_t buf[16];
+    for (;;) {
+        size_t n = fread(buf, 1, sizeof(buf), file);
+        for (size_t i = 0; i < n; ++i)
+            printf("%02x ", buf[i]);
+        printf("\n");
+        if (n < sizeof(buf)) break;
+    }
+    if (ferror(file)) {
+        perror(path);
+        return EXIT_FAILURE;
+    }
+
+    return EXIT_SUCCESS;
+}