sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 7132473947c7d907e6e0a81bc9c3b44701fd54ff
parent 365f392d3c1e2e204bbb466469a5e56cf7a10ec5
Author: FRIGN <dev@frign.de>
Date:   Wed Sep 30 00:08:58 +0200

Some small changes for od(1)

1) Move usage() down above main().
2) Consistently use printaddress() across the code.
3) Use off_t instead of size_t for file offsets.

Diffstat:
od.c | 34+++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/od.c b/od.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <inttypes.h> #include <stdlib.h> #include <string.h> @@ -9,21 +10,15 @@ static unsigned char radix = 'o'; static unsigned char type = 'o'; static void -usage(void) +printaddress(FILE *f, off_t addr) { - eprintf("usage: %s [-A d|o|x|n] [-t a|c|d|o|u|x] [file ...]\n", argv0); -} - -static void -printaddress(FILE *f, size_t addr) -{ - char fmt[] = "%06z# "; + char fmt[] = "%07j# "; if (radix == 'n') { fputc(' ', f); } else { fmt[4] = radix; - fprintf(f, fmt, addr); + fprintf(f, fmt, (intmax_t)addr); } } @@ -73,13 +68,12 @@ printchar(FILE *f, unsigned char c) static void od(FILE *in, char *in_name, FILE *out, char *out_name) { + off_t addr; + size_t i, chunklen; unsigned char buf[BUFSIZ]; - char fmt[] = "\n%.6z#"; - off_t addr, bread, i; - addr = 0; - for (; (bread = fread(buf, 1, BUFSIZ, in)); ) { - for (i = 0; i < bread; ++i, ++addr) { + for (addr = 0; (chunklen = fread(buf, 1, BUFSIZ, in)); ) { + for (i = 0; i < chunklen; ++i, ++addr) { if ((addr % bytes_per_line) == 0) { if (addr) fputc('\n', out); @@ -90,11 +84,17 @@ od(FILE *in, char *in_name, FILE *out, char *out_name) if (feof(in) || ferror(in) || ferror(out)) break; } + fputc('\n', out); if (radix != 'n') { - fmt[5] = radix; - fprintf(out, fmt, addr); + printaddress(out, addr); + fputc('\n', out); } - fputc('\n', out); +} + +static void +usage(void) +{ + eprintf("usage: %s [-A d|o|x|n] [-t a|c|d|o|u|x] [file ...]\n", argv0); } int