fix: handle partial reads
This commit is contained in:
+8
-1
@@ -26,6 +26,7 @@ bool file_should_update(const File *file) {
|
||||
|
||||
bool file_update(File *file) {
|
||||
long length;
|
||||
size_t read_length;
|
||||
FILE *file_pointer;
|
||||
|
||||
// free remaining data
|
||||
@@ -63,7 +64,13 @@ bool file_update(File *file) {
|
||||
return false;
|
||||
}
|
||||
// read file
|
||||
fread(file->content, sizeof(char), length, file_pointer);
|
||||
read_length = fread(file->content, sizeof(char), length, file_pointer);
|
||||
if (read_length != length) {
|
||||
file->error = true;
|
||||
fclose(file_pointer);
|
||||
log_error("Cannot read complete file '%s'", file->path);
|
||||
return false;
|
||||
}
|
||||
// close file
|
||||
fclose(file_pointer);
|
||||
// append null byte
|
||||
|
||||
Reference in New Issue
Block a user