tAdd function to format a sha512 hash as a base16 string - synk - synchronize files between hosts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 1eb5f4be1f3e0da4bd419889f40a99dc67cd2ac6
 (DIR) parent 52315a137481905a33e482df08128ee85f90b6b5
 (HTM) Author: Willy <willyatmailoodotorg>
       Date:   Mon, 22 Aug 2016 14:16:15 +0200
       
       Add function to format a sha512 hash as a base16 string
       
       Diffstat:
         M synk.c                              |      23 +++++++++++++++++++++--
       
       1 file changed, 21 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/synk.c b/synk.c
       t@@ -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)
       t@@ -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.
         */