From: kremlin Date: Mon, 25 Aug 2014 17:05:40 +0000 (-0500) Subject: add get_file_sha256(path) to util.c X-Git-Url: https://uglyman.kremlin.cc/gitweb/gitweb.cgi?a=commitdiff_plain;h=5ef520164eac5ee8f2be263ea5caa962ec5503f3;p=systembsd.git add get_file_sha256(path) to util.c --- 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) {