diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2015-09-01 14:33:25 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2015-09-01 14:33:25 +0200 |
commit | 05674e2924b1d8201c0dbee77e052d7ae2e2bfdd (patch) | |
tree | b0e6afbaa6ebaf9e9950686fa1d3c290947c34b8 | |
parent | 5afb943df5dc483ca6199c5417871383cc2d3972 (diff) | |
download | redo-c-05674e2924b1d8201c0dbee77e052d7ae2e2bfdd.tar.gz redo-c-05674e2924b1d8201c0dbee77e052d7ae2e2bfdd.tar.xz redo-c-05674e2924b1d8201c0dbee77e052d7ae2e2bfdd.zip |
improve hash hexify
-rw-r--r-- | redo.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/redo.c b/redo.c index c6eef92..4c160fa 100644 --- a/redo.c +++ b/redo.c @@ -290,12 +290,13 @@ static char * hashfile(int fd) { static char hex[16] = "0123456789abcdef"; + static char asciihash[65]; struct sha256 ctx; off_t off = 0; char buf[4096]; + char *a; unsigned char hash[32]; - static char asciihash[65]; int i; ssize_t r; @@ -308,12 +309,11 @@ hashfile(int fd) sha256_sum(&ctx, hash); - for (i = 0; i < 32; i++) { - // TODO *asciihash++ = ? - asciihash[2*i] = hex[hash[i] / 16]; - asciihash[2*i+1] = hex[hash[i] % 16]; + for (i = 0, a = asciihash; i < 32; i++) { + *a++ = hex[hash[i] / 16]; + *a++ = hex[hash[i] % 16]; } - asciihash[64] = 0; + *a = 0; return asciihash; } |