]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add hash_file2() and hash_fd2() functions that update two hash sums
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Sep 2010 08:28:29 +0000 (10:28 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 5 Sep 2010 08:28:29 +0000 (10:28 +0200)
ccache.h
hash.c

index a55afdaefd44703e3de5775610e5ae367b8ac5e4..e58626e22fe6822aabfd735586402daad033c5c4 100644 (file)
--- 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 337ed55be7898afe2c11d82360a6447a2aefc379..88996eda27d4a2ec42ab6ff7f4e3df8cc5624539 100644 (file)
--- 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;
 }