diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-09 00:49:53 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-09 00:49:53 +0100 |
| commit | 7f95deec0af600bddecf5d61299d2319d9059965 (patch) | |
| tree | 22012d45b6bd3a3bc5aefb044745d0e3afe2e692 /file.c | |
| parent | 842f5df169f6e576fa462d414c2645f108bfb9b6 (diff) | |
| download | crep-7f95deec0af600bddecf5d61299d2319d9059965.tar.gz | |
Fixed space width
Diffstat (limited to 'file.c')
| -rw-r--r-- | file.c | 70 |
1 files changed, 35 insertions, 35 deletions
@@ -4,41 +4,41 @@ #include "file.h" struct FileContent read_entire_file(const char *file_path) { - struct FileContent file_data; - file_data.content = NULL; - file_data.count = 0; - - FILE *file = fopen(file_path, "rb"); - if (file == NULL) { - perror("Error opening file"); - return file_data; - } - - fseek(file, 0, SEEK_END); - long file_size = ftell(file); - fseek(file, 0, SEEK_SET); - - if (file_size == -1) { - perror("Error getting file size"); - return file_data; - } - - file_data.content = (const char *)malloc(file_size); - if (file_data.content == NULL) { - perror("Error allocating memory"); - return file_data; - } - - size_t bytes_read = fread((void *)file_data.content, 1, file_size, file); - if (bytes_read != (size_t)file_size) { - perror("Error reading file"); - free((void *)file_data.content); + struct FileContent file_data; file_data.content = NULL; + file_data.count = 0; + + FILE *file = fopen(file_path, "rb"); + if (file == NULL) { + perror("Error opening file"); + return file_data; + } + + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + + if (file_size == -1) { + perror("Error getting file size"); + return file_data; + } + + file_data.content = (const char *)malloc(file_size); + if (file_data.content == NULL) { + perror("Error allocating memory"); + return file_data; + } + + size_t bytes_read = fread((void *)file_data.content, 1, file_size, file); + if (bytes_read != (size_t)file_size) { + perror("Error reading file"); + free((void *)file_data.content); + file_data.content = NULL; + return file_data; + } + + file_data.count = bytes_read; + + fclose(file); return file_data; - } - - file_data.count = bytes_read; - - fclose(file); - return file_data; } |
