diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-26 01:21:12 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-26 01:21:12 +0330 |
commit | 85bfc724dd2bdaa2259512c1b8ab21f7dfeca8f1 (patch) | |
tree | 0b9075ba9bf70aca9cdf36e5d909b161460b19a8 /src/utils/file.c | |
parent | 6edcfb23ffd49e937395b710f7c6213b2c0d93cf (diff) |
clean up
Diffstat (limited to 'src/utils/file.c')
-rw-r--r-- | src/utils/file.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/utils/file.c b/src/utils/file.c index 55a438c..61165d2 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -2,8 +2,8 @@ #include "utils/log.h" #include "utils/memory.h" +#include "utils/string.h" #include <stdio.h> -#include <string.h> size_t fileCodes_capacity = 0; char **fileCodes = NULL; @@ -36,10 +36,13 @@ void filePush(const char *filePath, char *code) { fileCodes_names = a404m_realloc( fileCodes_names, fileCodes_capacity * sizeof(*fileCodes_names)); } + size_t filePath_length = strLength(filePath); fileCodes[fileCodes_length] = code; fileCodes_names[fileCodes_length] = - a404m_malloc((strlen(filePath) + 1) * sizeof(**fileCodes_names)); - strcpy(fileCodes_names[fileCodes_length], filePath); + a404m_malloc((filePath_length + 1) * sizeof(**fileCodes_names)); + for (size_t i = 0; i < filePath_length; ++i) { + fileCodes_names[fileCodes_length][i] = filePath[i]; + } fileCodes_length += 1; } @@ -73,7 +76,7 @@ char *readWholeFile(const char *filePath) { 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) { + if (strEquals(filePath, str)) { return i; } } @@ -89,9 +92,11 @@ char *joinToPathOf(const char *original, const char *file) { } } char *result = - a404m_malloc((result_size + 1 + strlen(file) + 1) * sizeof(*result)); + a404m_malloc((result_size + 1 + strLength(file) + 1) * sizeof(*result)); - strncpy(result, original, result_size); + for (size_t i = 0; i < result_size; ++i) { + result[i] = original[i]; + } result[result_size++] = '/'; for (size_t i = 0; file[i] != '\0'; ++i) { |