Alter sha1close() 3rd argument to request flush only
update=0 suppressed writing the final SHA-1 but was not used. Now final=0 suppresses SHA-1 finalization, SHA-1 writing, and closing -- in other words, only flush the buffer. Signed-off-by: Dana L. How <danahow@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Dana L. How committed
May 13, 2007 at 11:28 UTC
f02153696fc319c3c6dba2c27a5f7aed98eec465
1 file changed
+5
-3
csum-file.c
+5
-3
@@ -29,18 +29,20 @@ static void sha1flush(struct sha1file *f, unsigned int count)
29
}
30
}
31
32
-int sha1close(struct sha1file *f, unsigned char *result, int update)
32
+int sha1close(struct sha1file *f, unsigned char *result, int final)
33
{
34
unsigned offset = f->offset;
35
if (offset) {
36
SHA1_Update(&f->ctx, f->buffer, offset);
37
sha1flush(f, offset);
38
+ f->offset = 0;
39
}
40
+ if (!final)
41
+ return 0; /* only want to flush (no checksum write, no close) */
42
SHA1_Final(f->buffer, &f->ctx);
43
if (result)
44
hashcpy(result, f->buffer);
42
- if (update)
43
- sha1flush(f, 20);
45
+ sha1flush(f, 20);
46
if (close(f->fd))
47
die("%s: sha1 file error on close (%s)", f->name, strerror(errno));
48
free(f);