From 783113e0bd020f0e7653d62c82fda5c34d472fb8 Mon Sep 17 00:00:00 2001 From: Chris Dunlop Date: Mon, 12 Dec 2011 14:04:25 +1100 Subject: [PATCH] Improve generation of hash file name Use the calculated checksum_len rather than assuming 16 bytes. Use sprintf() rather than hand-rolled binary-to-text. This is not in a critical performance path. Note: this same sprintf() method is used in checksum-updating.diff. Signed-off-by: Chris Dunlop --- hashlink.c | 15 +++++---------- 1 files changed, 5 insertions(+), 10 deletions(-) diff --git a/hashlink.c b/hashlink.c index 12cc39b..55433bc 100644 --- a/hashlink.c +++ b/hashlink.c @@ -21,6 +21,7 @@ #include "rsync.h" extern char *link_by_hash_dir; +extern int checksum_len; #ifdef HAVE_LINK @@ -30,18 +31,12 @@ char *make_hash_name(struct file_struct *file) uchar c, *src = (uchar*)F_SUM(file); int i; - for (dst = hash, i = 0; i < 4; i++, src++) { - c = *src >> 4; - *(dst++) = (c >= 10) ? (c - 10 + 'a') : (c + '0'); - c = *src & 0x0f; - *(dst++) = (c >= 10) ? (c - 10 + 'a') : (c + '0'); + for (dst = hash, i = 0; i < 4; i++, src++, dst += 2) { + sprintf(dst, "%02x", (int)CVAL(src, 0)); } *dst++ = '/'; - for (i = 0; i < 12; i++, src++) { - c = *src >> 4; - *(dst++) = (c >= 10) ? (c - 10 + 'a') : (c + '0'); - c = *src & 0x0f; - *(dst++) = (c >= 10) ? (c - 10 + 'a') : (c + '0'); + for ( ; i < checksum_len; i++, src++, dst += 2) { + sprintf(dst, "%02x", (int)CVAL(src, 0)); } *dst = 0; -- 1.7.0.4