Skip to content

Commit

Permalink
Fixed a bug with reversed arguments to the fwrite and fread functions…
Browse files Browse the repository at this point in the history
… for LIBC mode.
  • Loading branch information
MGlolenstine committed Nov 19, 2024
1 parent 89bd19a commit 366632e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/fdb_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fdb_err_t _fdb_file_read(fdb_db_t db, uint32_t addr, void *buf, size_t size)
FILE *fp = open_db_file(db, addr, false);
if (fp) {
addr = addr % db->sec_size;
if ((fseek(fp, addr, SEEK_SET) != 0) || (fread(buf, size, 1, fp) != size))
if ((fseek(fp, addr, SEEK_SET) != 0) || (fread(buf, size, 1, fp) != 1))
result = FDB_READ_ERR;
} else {
result = FDB_READ_ERR;
Expand All @@ -277,15 +277,14 @@ fdb_err_t _fdb_file_write(fdb_db_t db, uint32_t addr, const void *buf, size_t si
FILE *fp = open_db_file(db, addr, false);
if (fp) {
addr = addr % db->sec_size;
if ((fseek(fp, addr, SEEK_SET) != 0) || (fwrite(buf, size, 1, fp) != size))
if ((fseek(fp, addr, SEEK_SET) != 0) || (fwrite(buf, size, 1, fp) != 1))
result = FDB_READ_ERR;
if(sync) {
fflush(fp);
}
} else {
result = FDB_READ_ERR;
}

return result;
}

Expand Down

0 comments on commit 366632e

Please sign in to comment.