Author | Jamozed <[email protected]> |
Date | 2020-08-13 04:39:40 |
Commit | 828f5543b0b4fa56e1e4735c3bc0663545a5c0bd |
Parent | 03a082a8c818091ef7da1fa7a6d4acfabdf06ba1 |
crc32: Change CRC output to hexadecimal
Diffstat
M | src/crc32.c | | | 12 | ++++++------ |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/crc32.c b/src/crc32.c index ff38aa1..40609f6 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -1,4 +1,4 @@ -// crc32.c, version 1.0.5 +// crc32.c, version 1.0.6 // OMKOV cryptutils crc32 // Copyright (C) 2020, Jakob Wakeling // All rights reserved. @@ -37,7 +37,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include <stdint.h> #include <stdio.h> -#define VERSION "1.0.5" +#define VERSION "1.0.6" static const uint32_t CRC32[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, @@ -115,19 +115,19 @@ int main(int ac, char *av[]) { A0 = av[0]; } static inline int crc32(const char *file) { - uint8_t stdbuf[BUFSIZ * 16]; FILE *fi; + uint8_t buf[BUFSIZ * 16]; FILE *fi; register size_t fl = 0; register uint32_t crc = (uint32_t)~0; if (!file || (file[0] == '-' && file[1] == 0)) { fi = stdin; } else if (!(fi = fopen(file, "r"))) { return 1; } - for (size_t c; (c = fread(stdbuf, 1, sizeof (stdbuf), fi)); fl += c) { + for (size_t c; (c = fread(buf, 1, sizeof (buf), fi)); fl += c) { for (register size_t i = 0; i != c; ++i) { - crc = (crc >> 8) ^ CRC32[(crc ^ (unsigned int)stdbuf[i]) & 0xFF]; + crc = (crc >> 8) ^ CRC32[(crc ^ (unsigned int)buf[i]) & 0xFF]; } } crc = ~crc; - printf("%u %zu", crc, fl); + printf("%X %zu", crc, fl); if (file) { printf(" %s", file); } fputc('\n', stdout); if (fi != stdin) { fclose(fi); } return 0;