summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/file.c28
-rw-r--r--src/utils/file.h2
-rw-r--r--src/utils/string.c1
3 files changed, 19 insertions, 12 deletions
diff --git a/src/utils/file.c b/src/utils/file.c
index 89ccfa8..921befb 100644
--- a/src/utils/file.c
+++ b/src/utils/file.c
@@ -30,6 +30,21 @@ void fileDelete() {
fileCodes_length = 0;
}
+void filePush(const char *filePath, char *code) {
+ if (fileCodes_capacity == fileCodes_length) {
+ fileCodes_capacity += fileCodes_capacity / 2 + 1;
+ fileCodes =
+ a404m_realloc(fileCodes, fileCodes_capacity * sizeof(*fileCodes));
+ fileCodes_names = a404m_realloc(
+ fileCodes_names, fileCodes_capacity * sizeof(*fileCodes_names));
+ }
+ fileCodes[fileCodes_length] = code;
+ fileCodes_names[fileCodes_length] =
+ a404m_malloc((strlen(filePath) + 1) * sizeof(**fileCodes_names));
+ strcpy(fileCodes_names[fileCodes_length], filePath);
+ fileCodes_length += 1;
+}
+
char *readWholeFile(const char *filePath) {
FILE *file = fopen(filePath, "r");
@@ -48,18 +63,7 @@ char *readWholeFile(const char *filePath) {
fclose(file);
- if (fileCodes_capacity == fileCodes_length) {
- fileCodes_capacity += fileCodes_capacity / 2 + 1;
- fileCodes =
- a404m_realloc(fileCodes, fileCodes_capacity * sizeof(*fileCodes));
- fileCodes_names = a404m_realloc(
- fileCodes_names, fileCodes_capacity * sizeof(*fileCodes_names));
- }
- fileCodes[fileCodes_length] = str;
- fileCodes_names[fileCodes_length] =
- a404m_malloc((strlen(filePath) + 1) * sizeof(**fileCodes_names));
- strcpy(fileCodes_names[fileCodes_length], filePath);
- fileCodes_length += 1;
+ filePush(filePath, str);
return str;
}
diff --git a/src/utils/file.h b/src/utils/file.h
index 4a904e4..31e6503 100644
--- a/src/utils/file.h
+++ b/src/utils/file.h
@@ -10,4 +10,6 @@ extern size_t fileCodes_length;
void fileInit();
void fileDelete();
+void filePush(const char *filePath,char *code);
+
char *readWholeFile(const char *filePath);
diff --git a/src/utils/string.c b/src/utils/string.c
index 5f9b7de..a5baab4 100644
--- a/src/utils/string.c
+++ b/src/utils/string.c
@@ -1,5 +1,6 @@
#include "string.h"
#include "memory.h"
+#include "utils/log.h"
#include <stdint.h>
#include <string.h>