From: Joel Rosdahl Date: Sun, 5 Sep 2010 08:28:29 +0000 (+0200) Subject: Add hash_file2() and hash_fd2() functions that update two hash sums X-Git-Tag: v3.1~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=95f1260b50063d749de4d9ae150b8acaaaf05c10;p=thirdparty%2Fccache.git Add hash_file2() and hash_fd2() functions that update two hash sums --- diff --git a/ccache.h b/ccache.h index a55afdaef..e58626e22 100644 --- a/ccache.h +++ b/ccache.h @@ -91,7 +91,9 @@ void hash_delimiter(struct mdfour *md, const char* type); void hash_string(struct mdfour *md, const char *s); void hash_int(struct mdfour *md, int x); bool hash_fd(struct mdfour *md, int fd); +bool hash_fd2(struct mdfour *md1, struct mdfour *md2, int fd); bool hash_file(struct mdfour *md, const char *fname); +bool hash_file2(struct mdfour *md1, struct mdfour *md2, const char *fname); /* ------------------------------------------------------------------------- */ /* util.c */ diff --git a/hash.c b/hash.c index 337ed55be..88996eda2 100644 --- a/hash.c +++ b/hash.c @@ -95,12 +95,27 @@ hash_int(struct mdfour *md, int x) */ bool hash_fd(struct mdfour *md, int fd) +{ + return hash_fd2(md, NULL, fd); +} + +/* + * Add contents of an open file to the hash. Returns true on success, otherwise + * false. + */ +bool +hash_fd2(struct mdfour *md1, struct mdfour *md2, int fd) { char buf[1024]; ssize_t n; while ((n = read(fd, buf, sizeof(buf))) > 0) { - hash_buffer(md, buf, n); + if (md1) { + hash_buffer(md1, buf, n); + } + if (md2) { + hash_buffer(md2, buf, n); + } } if (n == 0) { return true; @@ -115,6 +130,16 @@ hash_fd(struct mdfour *md, int fd) */ bool hash_file(struct mdfour *md, const char *fname) +{ + return hash_file2(md, NULL, fname); +} + +/* + * Add contents of a file to two hash sums. Returns true on success, otherwise + * false. + */ +bool +hash_file2(struct mdfour *md1, struct mdfour *md2, const char *fname) { int fd; bool ret; @@ -124,7 +149,7 @@ hash_file(struct mdfour *md, const char *fname) return false; } - ret = hash_fd(md, fd); + ret = hash_fd2(md1, md2, fd); close(fd); return ret; }