diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2024-09-25 19:47:29 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2024-09-25 19:47:29 +0330 |
commit | c409b8aaf6b6f63bd68a3356e146ab80b2ec8c4b (patch) | |
tree | 65ea5801fd910fc6bcff3f2e8f06b5fd7d249c78 /src/utils/file.c | |
parent | f79290084948f3cf140395c270c07cf29ca58e8d (diff) |
fixed multiple variable definition bug
tried to implement import
Diffstat (limited to 'src/utils/file.c')
-rw-r--r-- | src/utils/file.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/utils/file.c b/src/utils/file.c index 410c218..cdb2dfe 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -1,8 +1,10 @@ #include "file.h" + #include <stdio.h> +#include <string.h> #include <utils/memory/memory.h> -char *read_whole_file(const char *path) { +Code *read_whole_file(const char *path) { FILE *file = fopen(path, "r"); if (!file) { fprintf(stderr, "could not open file at path '%s'\n", path); @@ -18,5 +20,13 @@ char *read_whole_file(const char *path) { str[file_size] = '\0'; fclose(file); - return str; + Code *code = a404m_malloc(sizeof(*code)); + + size_t pathLen = strlen(path); + code->code = str; + code->filePath = a404m_malloc(pathLen+1); + + memcpy(code->filePath, path, pathLen+1); + + return code; } |