diff options
| author | Jeffrey Armstrong <jeffrey.armstrong@approximatrix.com> | 2014-01-02 09:07:27 -0500 |
|---|---|---|
| committer | Jeffrey Armstrong <jeffrey.armstrong@approximatrix.com> | 2014-01-02 09:07:27 -0500 |
| commit | eb626bd8ee3fddae050dbf9babfbea19961a36f2 (patch) | |
| tree | 2002c12e08bf87e3a266f3696e932ce3e2af0170 /rfile.c | |
| download | prism-eb626bd8ee3fddae050dbf9babfbea19961a36f2.tar.gz prism-eb626bd8ee3fddae050dbf9babfbea19961a36f2.zip | |
Initial code commit, including db init and file hashing
Diffstat (limited to 'rfile.c')
| -rw-r--r-- | rfile.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -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;
+}
|
