Skip to content

Commit

Permalink
DB, read_entry: Get rid of goto, simplify semi-duplicate if block
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Krakow <kai@kaishome.de>
  • Loading branch information
kakra committed Oct 23, 2020
1 parent eaf247b commit d3edb60
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions fossilize_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,27 +309,15 @@ struct DumbDirectoryDatabase : DatabaseInterface
return false;
}

bool success = false;
size_t file_size = size_t(ftell(file));
rewind(file);

bool success = true;
if (blob)
{
if (*blob_size != file_size)
goto discard_and_close;
}
success = (*blob_size == file_size) && (fread(blob, 1, file_size, file) == file_size);
else
*blob_size = file_size;

if (blob)
{
if (fread(blob, 1, file_size, file) != file_size)
goto discard_and_close;
}

success = true;

discard_and_close:
LINUX_fadvise(file, 0, file_size, POSIX_FADV_DONTNEED);
fclose(file);
return success;
Expand Down

0 comments on commit d3edb60

Please sign in to comment.