aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorkremlin <ian@kremlin.cc>2014-08-26 01:05:40 +0800
committerkremlin <ian@kremlin.cc>2014-08-26 01:05:40 +0800
commit5ef520164eac5ee8f2be263ea5caa962ec5503f3 (patch)
treef17e0ff112f9fdc3e5b6a33bc193d4cc2be78648 /src/util.c
parentdefc2e6786915f3e3a159dc994ef98f8364cbe21 (diff)
downloadsystembsd-5ef520164eac5ee8f2be263ea5caa962ec5503f3.tar
systembsd-5ef520164eac5ee8f2be263ea5caa962ec5503f3.tar.gz
systembsd-5ef520164eac5ee8f2be263ea5caa962ec5503f3.tar.bz2
systembsd-5ef520164eac5ee8f2be263ea5caa962ec5503f3.tar.lz
systembsd-5ef520164eac5ee8f2be263ea5caa962ec5503f3.tar.xz
systembsd-5ef520164eac5ee8f2be263ea5caa962ec5503f3.tar.zst
systembsd-5ef520164eac5ee8f2be263ea5caa962ec5503f3.zip
add get_file_sha256(path) to util.c
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index bb5670a..aea6b8d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -27,6 +27,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) {
gchar *content, **split_content, *cur, **cur_split, *ret;