Skip to content

Commit

Permalink
check read size
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Dec 28, 2021
1 parent 14bedb5 commit 0c027a6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ readFile(
FILE* file = NULL;
Buffer buffer = {NULL, 0};
U8* data = NULL;
U32 size = 0;
long size = 0;
size_t read = 0;

file = fopen(path, "rb");
if (file == NULL) {
Expand All @@ -25,11 +26,14 @@ readFile(
if (data == NULL) {
return buffer;
}
fread(data, 1, size, file);
read = fread(data, 1, size, file);
if (read == size) {
buffer.data = data;
buffer.length = size;
} else {
free(data);
}
fclose(file);

buffer.data = data;
buffer.length = size;

return buffer;
}

0 comments on commit 0c027a6

Please sign in to comment.