[hackers] [sbase] Some small changes for od(1) || FRIGN
commit 7132473947c7d907e6e0a81bc9c3b44701fd54ff
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Wed Sep 30 00:08:58 2015 +0200
Commit: sin <sin_AT_2f30.org>
CommitDate: Wed Sep 30 19:44:10 2015 +0100
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.
diff --git a/od.c b/od.c
index 8e71b60..c444421 100644
--- a/od.c
+++ b/od.c
_AT_@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
_AT_@ -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);
}
}
_AT_@ -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);
_AT_@ -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
Received on Wed Sep 30 2015 - 20:44:17 CEST
This archive was generated by hypermail 2.3.0
: Wed Sep 30 2015 - 20:48:27 CEST