diff options
| author | Louis Burda <quent.burda@gmail.com> | 2021-05-09 12:37:16 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2021-05-09 12:37:16 +0200 |
| commit | 3b660c467f938df6898229e378074cfa5662ce9f (patch) | |
| tree | 32d8bed7139267c951f6aabd8238fce496150531 /service/src/util.c | |
| parent | a0d6bf48a185026589288fd9aa94506b321301d8 (diff) | |
| download | enowars5-service-stldoctor-3b660c467f938df6898229e378074cfa5662ce9f.tar.gz enowars5-service-stldoctor-3b660c467f938df6898229e378074cfa5662ce9f.zip | |
save hash statically, added file info output, improved error strings and minor fixes
Diffstat (limited to 'service/src/util.c')
| -rw-r--r-- | service/src/util.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/service/src/util.c b/service/src/util.c index cb97816..946bc19 100644 --- a/service/src/util.c +++ b/service/src/util.c @@ -46,27 +46,27 @@ const char* mhash(const char *filename, int len) { static const char *hexalph = "0123456789ABCDEF"; - static char buf[33]; + static char buf[MHASHLEN + 1]; int i, k; if (len == -1) len = strlen(filename); - for (i = 0; i < MIN(32, len); i++) { + for (i = 0; i < MIN(MHASHLEN, len); i++) { unsigned char v = 0; - for (k = i; k < len; k += 32) + for (k = i; k < len; k += MHASHLEN) v ^= filename[k]; buf[i*2+0] = hexalph[(v >> 0) & 0x0f]; buf[i*2+1] = hexalph[(v >> 4) & 0x0f]; } if (i == 0) { - memset(buf, '0', 32); - } else if (i < 32) { - for (k = 0; k < 32; k++) + memset(buf, '0', MHASHLEN); + } else if (i < MHASHLEN) { + for (k = 0; k < MHASHLEN; k++) buf[k] = buf[k % i]; } - buf[32] = '\0'; + buf[MHASHLEN] = '\0'; return buf; } |
