diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-02-06 18:46:25 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-02-06 18:46:25 +0100 |
commit | ba5a93c94f07d52d942b071bd47535da6b6324e6 (patch) | |
tree | 53bc8691bc5016e7de217891b7dcf63134e3ac9e /c | |
parent | minor work on port (diff) | |
download | sha3sum-ba5a93c94f07d52d942b071bd47535da6b6324e6.tar.gz sha3sum-ba5a93c94f07d52d942b071bd47535da6b6324e6.tar.bz2 sha3sum-ba5a93c94f07d52d942b071bd47535da6b6324e6.tar.xz |
and now it compiles
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'c')
-rw-r--r-- | c/sha3sum.c | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/c/sha3sum.c b/c/sha3sum.c index a0ed1ec..6ff70e7 100644 --- a/c/sha3sum.c +++ b/c/sha3sum.c @@ -276,7 +276,7 @@ int main(int argc, char** argv) char* stdin = null; char* filename; char* fn; - long f, fail = false; + long f, fail = false, _; for (f = 0; f < fptr; f++) { @@ -295,50 +295,75 @@ int main(int argc, char** argv) } initialise(r, c, o); - /* String rc = ""; */ int blksize = 4096; /** XXX os.stat(os.path.realpath(fn)).st_size; **/ - char* chunk = malloc(blksize) - for (;;) - { - long read = fread(chunk, 1, blksize, file); - if (read <= 0) - break; - update(chunk, read); - } + char* chunk = malloc(blksize); + for (;;) + { + long read = fread(chunk, 1, blksize, file); + if (read <= 0) + break; + update(chunk, read); + } free(chunk); - byte* bs = digest(null, 0); - long bsn = (o + 7) >> 3; - for (long _ = 1; _ < i; _++) + char* bs = digest(null, 0); + long bn = (o + 7) >> 3; + for (_ = 1; _ < i; _++) { initialise(r, c, o); - bs = digest(bs, bsn); + bs = digest(bs, bn); } if (binary) { + long j; if (filename == null) - stdin = bs; - for (long j = 0; j < bsn; j++) + { + stdin = bs; + bs = null; + } + for (j = 0; j < bn; j++) putchar(*(bs + j)); fflush(stdout); } else { - for (int b = 0, bn = bs.length; b < bn; b++) - { rc += "0123456789ABCDEF".charAt((bs[b] >> 4) & 15); - rc += "0123456789ABCDEF".charAt(bs[b] & 15); + long flen = 0, rcptr = 0, b = 0; + if (filename != null) + while (*(filename + flen)) + flen++; + char* rc = malloc((bn << 1) + 3 + (filename == null ? 1 : 0) + flen); + for (b = 0; b < bn; b++) + { + *(rc + rcptr++) = "0123456789ABCDEF"[(bs[b] >> 4) & 15]; + *(rc + rcptr++) = "0123456789ABCDEF"[bs[b] & 15]; } - rc += " " + (filename == null ? "-" : filename) + "\n"; + *(rc + rcptr++) = ' '; if (filename == null) - stdin = rc.getBytes("UTF-8"); - System.out.print(rc); + *(rc + rcptr++) = '-'; + else + { + flen = 0; + while (*(filename + flen)) + *(rc + rcptr++) = *(filename + flen++); + } + *(rc + rcptr++) = '\n'; + *(rc + rcptr++) = 0; + printf("%s", rc); fflush(stdout); + if (filename == null) + stdin = rc; + else + free(rc); } - free(bs); + if (bs != null) + free(bs); fclose(file); } + if (stdin != null) + free(stdin); + fflush(stdout); fflush(stderr); if (fail) |