X-Git-Url: https://uglyman.kremlin.cc/gitweb/gitweb.cgi?p=systembsd.git;a=blobdiff_plain;f=src%2Futil.c;h=aea6b8db35410fa6aa61f54a8479f48c2ea7d729;hp=bb5670a18d2ebcd8762197f60ab9769cae934d9e;hb=10ddceeb98322259fc13e3022ceeafc2191bb89d;hpb=de46ace438056c7e63fcf3527fc9a3e6cc5c976e diff --git a/src/util.c b/src/util.c index bb5670a..aea6b8d 100644 --- a/src/util.c +++ b/src/util.c @@ -26,6 +26,26 @@ const gint MAX_TOKENS = 20; +/* return must be g_free()'d */ +gchar *get_file_sha256(const gchar *path) { + + gchar *checksum; + GMappedFile *file; + GBytes *data; + GError *err = NULL; + + file = g_mapped_file_new(path, FALSE, &err); + + if(file) { + + data = g_mapped_file_get_bytes(file); + g_mapped_file_unref(file); + checksum = g_compute_checksum_for_bytes(G_CHECKSUM_SHA256, data); + return checksum; + } else + return NULL; +} + /* return must be g_free()'d */ gchar *config_get(const gchar *path, gchar *key) {