diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/file.c | 15 | ||||
-rw-r--r-- | src/utils/file.h | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/utils/file.c b/src/utils/file.c index 6d737f7..714dc2c 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -44,6 +44,10 @@ void filePush(const char *filePath, char *code) { } char *readWholeFile(const char *filePath) { + const size_t index = getFileIndex(filePath); + if (index != fileCodes_length) { + return fileCodes[index]; + } FILE *file = fopen(filePath, "r"); if (!file) { @@ -65,3 +69,14 @@ char *readWholeFile(const char *filePath) { return str; } + +size_t getFileIndex(const char *filePath) { + for (size_t i = 0; i < fileCodes_length; ++i) { + const char *str = fileCodes_names[i]; + if (strcmp(filePath, str) == 0) { + return i; + } + } + + return fileCodes_length; +} diff --git a/src/utils/file.h b/src/utils/file.h index 31e6503..f0b0d8c 100644 --- a/src/utils/file.h +++ b/src/utils/file.h @@ -13,3 +13,4 @@ void fileDelete(); void filePush(const char *filePath,char *code); char *readWholeFile(const char *filePath); +size_t getFileIndex(const char *filePath); |