aboutsummaryrefslogtreecommitdiff
path: root/src/filehandler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/filehandler.c')
-rw-r--r--src/filehandler.c62
1 files changed, 0 insertions, 62 deletions
diff --git a/src/filehandler.c b/src/filehandler.c
deleted file mode 100644
index f42a22b..0000000
--- a/src/filehandler.c
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <filehandler.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-static size_t
-size(filehandler_t *fh)
-{
- unsigned int current = ftell(fh->f);
-
- fseek(fh->f, 0, SEEK_END);
- unsigned int s = ftell(fh->f);
-
- fseek(fh->f, current, SEEK_SET);
- return s;
-}
-
-void
-filehandler_init(filehandler_t *fh, char *path)
-{
- fh->f = NULL;
- fh->buffer = NULL;
-
- fh->path = (char *) calloc(strlen(path) + 1, sizeof(char));
- strcpy(fh->path, path);
-}
-
-bool
-filehandler_open(filehandler_t *fh)
-{
- fh->f = fopen(fh->path, "r");
- if (fh->f == NULL) {
- printf("Unable to open %s\n", fh->path);
- return false;
- }
-
- return true;
-}
-
-char *
-filehandler_read(filehandler_t *fh)
-{
- fseek(fh->f, 0, SEEK_SET);
-
- size_t buf_size = size(fh);
-
- fh->buffer = (char *) calloc(buf_size, sizeof(char));
- int bytesread = fread(fh->buffer, sizeof(char), buf_size, fh->f);
-
- if (bytesread < 0) {
- return NULL;
- }
- return fh->buffer;
-}
-
-void
-filehandler_close(filehandler_t *fh)
-{
- fclose(fh->f);
- free(fh->buffer);
-}