synk

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

commit 1eb5f4be1f3e0da4bd419889f40a99dc67cd2ac6
parent 52315a137481905a33e482df08128ee85f90b6b5
Author: Willy <willyatmailoodotorg>
Date:   Mon Aug 22 14:16:15 +0200

Add function to format a sha512 hash as a base16 string

Diffstat:
synk.c | 23+++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/synk.c b/synk.c @@ -31,12 +31,14 @@ enum { const char *rsync_cmd[] = { "rsync", "-azEq", "--delete", NULL }; +void usage(char *name); +int sha512(FILE *stream, unsigned char *hash); +int sha512_compare(unsigned char *h1, unsigned char *h2); +char *sha512_format(unsigned char *hash); long gettimestamp(const char *path); 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, FILE *f, const char *path); -int sha512(FILE *stream, unsigned char *hash); -int sha512_compare(unsigned char *h1, unsigned char *h2); void usage(char *name) @@ -87,6 +89,23 @@ sha512_compare(unsigned char *h1, unsigned char *h2) } /* + * Format a sha512 hash (64 bits long) as an hexadecimal string (128 char) + * A pointer to this char is statically allocated, so multiple calls to this + * function will overwrite the converted value. + */ +char * +sha512_format(unsigned char *hash) +{ + int i; + static char fmt[128] = ""; + + for (i=0; i<64; i++) { + snprintf(fmt+i, 2, "%02x\n", hash[i]); + } + + return fmt; +} +/* * Returns the UNIX timestamp for the given file, or -1 in case stat(2) * is in error. */