armink / FlashDB

An ultra-lightweight database that supports key-value and time series data | 一款支持 KV 数据和时序数据的超轻量级数据库
Apache License 2.0
1.92k stars 435 forks source link

Fixed a bug with reversed arguments to the `fwrite` and `fread` functions for `libc` file mode. #333

Open MGlolenstine opened 5 days ago

MGlolenstine commented 5 days ago

When FDB_USING_FILE_LIBC_MODE is enabled, the libc functions fwrite and fread awaited an incorrect return.

Current function calls want to write size bytes once, and wait for the size of bytes written to be returned, but the functions return how many times the size was written (written as 1 in the code), which always returns 1, if it succeeds.

       On success, fread() and fwrite() return the number of items read
       or written.  This number equals the number of bytes transferred
       only when size is 1.  If an error occurs, or the end of the file
       is reached, the return value is a short item count (or zero).

[source]