Added some tests, quick seek impl, fixed bugs
Turns out it's hard to test file holes without seek. It's interesting to note most of seek's buffer flush work actually occurs lazily in lfsr_file_write, so lfsr_file_seek turns out to be a relatively simple function.
This commit is contained in:
@@ -781,6 +781,8 @@ lfs_ssize_t lfsr_file_write(lfs_t *lfs, lfsr_file_t *file,
|
||||
// Returns the new position of the file, or a negative error code on failure.
|
||||
lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file,
|
||||
lfs_soff_t off, int whence);
|
||||
lfs_soff_t lfsr_file_seek(lfs_t *lfs, lfsr_file_t *file,
|
||||
lfs_soff_t off, uint8_t whence);
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Truncates the size of the file to the specified size
|
||||
@@ -794,12 +796,14 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size);
|
||||
// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR)
|
||||
// Returns the position of the file, or a negative error code on failure.
|
||||
lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file);
|
||||
lfs_soff_t lfsr_file_tell(lfs_t *lfs, lfsr_file_t *file);
|
||||
|
||||
// Change the position of the file to the beginning of the file
|
||||
//
|
||||
// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_SET)
|
||||
// Returns a negative error code on failure.
|
||||
int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file);
|
||||
int lfsr_file_rewind(lfs_t *lfs, lfsr_file_t *file);
|
||||
|
||||
// Return the size of the file
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user