From c22925bf96fb269d71b031898c2602a350b6fbe7 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 12 Sep 2016 14:40:54 -0400 Subject: Add .bin/xx.c --- .bin/xx.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 .bin/xx.c (limited to '.bin/xx.c') 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 +#include +#include + +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; +} -- cgit 1.4.1