summaryrefslogtreecommitdiff
path: root/rfile.c
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeffrey.armstrong@approximatrix.com>2014-01-02 09:07:27 -0500
committerJeffrey Armstrong <jeffrey.armstrong@approximatrix.com>2014-01-02 09:07:27 -0500
commiteb626bd8ee3fddae050dbf9babfbea19961a36f2 (patch)
tree2002c12e08bf87e3a266f3696e932ce3e2af0170 /rfile.c
downloadprism-eb626bd8ee3fddae050dbf9babfbea19961a36f2.tar.gz
prism-eb626bd8ee3fddae050dbf9babfbea19961a36f2.zip
Initial code commit, including db init and file hashing
Diffstat (limited to 'rfile.c')
-rw-r--r--rfile.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/rfile.c b/rfile.c
new file mode 100644
index 0000000..497d383
--- /dev/null
+++ b/rfile.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "prism.h"
+#include "md5.h"
+#include "rfile.h"
+
+static const char hex_str[]= "0123456789abcdef";
+
+int get_file_hash(const char *filename, char *hash)
+{
+FILE *fp;
+MD5_CTX hb;
+char buf[16];
+int i;
+
+ if(filename == NULL || hash == NULL)
+ return PRET_ERROR;
+
+ fp = fopen(filename, "rb");
+ if(fp == NULL)
+ return PRET_READERROR;
+
+ MD5_Init(&hb);
+ while(fgets(buf, 15, fp)) {
+ MD5_Update(&hb, buf, strlen(buf));
+ }
+ fclose(fp);
+
+ MD5_Final(buf, &hb);
+
+ for(i=0; i<16; i++) {
+ hash[2*i] = hex_str[buf[i] >> 4];
+ hash[2*i+1] = hex_str[buf[i] & 0x0F];
+ }
+
+ return PRET_OK;
+}