From 6fabd762332e7eb4aa2f638034bd16c332e34741 Mon Sep 17 00:00:00 2001
From: matthew <matthew@owens.tech>
Date: Sat, 18 Aug 2018 17:15:11 +0100
Subject: [PATCH] implemented basic file read func

---
 common/fileRead.c | 31 +++++++++++++++++++++++++++++++
 common/fileRead.h |  5 +++++
 2 files changed, 36 insertions(+)
 create mode 100644 common/fileRead.c
 create mode 100644 common/fileRead.h

diff --git a/common/fileRead.c b/common/fileRead.c
new file mode 100644
index 0000000..8bc7eb0
--- /dev/null
+++ b/common/fileRead.c
@@ -0,0 +1,31 @@
+#include "fileRead.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+char *readFile(const char *path)
+{
+	char *buffer = NULL;
+	int str_size, read_size;
+	FILE *handler = fopen(path, "r");
+
+	if(handler)
+	{
+		fseek(handler, 0, SEEK_END);
+		str_size = ftell(handler);
+		rewind(handler);
+		 
+		// Allocating enough memory for the file and a null end char
+		buffer = malloc(sizeof(char) *  (str_size + 1));
+		read_size = fread(buffer, sizeof(char), str_size, handler);
+
+		// capping off the string
+		buffer[str_size] = '\0';
+
+		if(str_size != read_size){
+			free(buffer);
+			buffer = NULL;
+		}
+	}
+
+	return buffer;
+}
diff --git a/common/fileRead.h b/common/fileRead.h
new file mode 100644
index 0000000..7577b8f
--- /dev/null
+++ b/common/fileRead.h
@@ -0,0 +1,5 @@
+#ifndef FILEREAD_H
+#define FILEREAD_H
+
+char *readFile(const char *path);
+#endif//FILEREAD_H
-- 
2.20.1