872 |
872 |
873 if(path[len-1] == '/') { |
873 if(path[len-1] == '/') { |
874 path[len-1] = '\0'; |
874 path[len-1] = '\0'; |
875 } |
875 } |
876 } |
876 } |
|
877 |
|
878 char* util_file_hash(const char *path) { |
|
879 FILE *in = fopen(path, "r"); |
|
880 if(!in) { |
|
881 return NULL; |
|
882 } |
|
883 |
|
884 DAV_SHA_CTX *sha = dav_hash_init(); |
|
885 char *buf = malloc(16384); |
|
886 |
|
887 size_t r; |
|
888 while((r = fread(buf, 1, 16384, in)) > 0) { |
|
889 dav_hash_update(sha, buf, r); |
|
890 } |
|
891 |
|
892 char hash[DAV_SHA256_DIGEST_LENGTH]; |
|
893 dav_hash_final(sha, hash); |
|
894 free(buf); |
|
895 fclose(in); |
|
896 |
|
897 return util_hexstr(hash, DAV_SHA256_DIGEST_LENGTH); |
|
898 } |