diff options
author | Robin Gareus <robin@gareus.org> | 2017-06-26 19:39:40 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-06-26 19:39:40 +0200 |
commit | 007f3cdbba01b58dc37ec214836ab0960ee13f82 (patch) | |
tree | d4d5ea5266b04d878537590ababee60c5d61be04 /libs/ardour/utils.cc | |
parent | a1cd4f8dfe2e301b677506c8a79d1f25ecd36b7c (diff) |
Add convenience fn to compute a file's sha1sum
Diffstat (limited to 'libs/ardour/utils.cc')
-rw-r--r-- | libs/ardour/utils.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index f73f206d29..31a94702e1 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -52,6 +52,7 @@ #include "pbd/stacktrace.h" #include "pbd/xml++.h" #include "pbd/basename.h" +#include "pbd/scoped_file_descriptor.h" #include "pbd/strsplit.h" #include "pbd/replace_all.h" @@ -719,6 +720,29 @@ ARDOUR::slider_position_to_gain_with_max (double g, double max_gain) return position_to_gain (g) * max_gain / 2.0; } +#include "sha1.c" + +std::string +ARDOUR::compute_sha1_of_file (std::string path) +{ + PBD::ScopedFileDescriptor fd (g_open (path.c_str(), O_RDONLY, 0444)); + if (fd < 0) { + return std::string (); + } + char buf[4096]; + ssize_t n_read; + char hash[41]; + Sha1Digest s; + sha1_init (&s); + + while ((n_read = ::read(fd, buf, sizeof(buf))) > 0) { + sha1_write (&s, (const uint8_t*) buf, n_read); + } + + sha1_result_hash (&s, hash); + return std::string (hash); +} + extern "C" { void c_stacktrace() { stacktrace (cerr); } } |