synk

synchronize files between hosts
Log | Files | Refs | README | LICENSE

commit 8e9a6f6cd8321f42ac8d55456b1092ef7a61f191
parent e107f99cfc32c18f5c8902f461b70336973de2d5
Author: Willy <willyatmailoodotorg>
Date:   Mon Aug 22 08:41:20 +0200

Function to compare hashes

Diffstat:
synk.c | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/synk.c b/synk.c @@ -36,6 +36,7 @@ int handleclient(int cfd, struct in_addr inet); int server(in_addr_t host, in_port_t port); int client(in_addr_t host, in_port_t port, const char *path); int sha512(FILE *stream, unsigned char *hash); +int sha512_compare(unsigned char *h1, unsigned char *h2); void usage(char *name) @@ -70,6 +71,22 @@ sha512(FILE *stream, unsigned char *hash) } /* + * Return 0 is two sha512 hashes match together, 1 otherwise. + * Hashes MUST be 64 byte long, and not NULL. + */ +int +sha512_compare(unsigned char *h1, unsigned char *h2) +{ + int i; + for (i=0; i<64; i++) { + if (h1[i] != h2[i]) + return 1; + } + + return 0; +} + +/* * Returns the UNIX timestamp for the given file, or -1 in case stat(2) * is in error. */