Changed lfs_dir_read to return 0 on success
Before: If an entry is found, lfs_dir_read returns 1 If at end of directory, lfs_dir_read returns 0 After: If an entry is found, lfs_dir_read returns 0 If at end of directory, lfs_dir_read returns LFS_ERR_NOENT --- lfs_dir_read is a bit of an odd function. It's supposed to match lfs_file_read, but instead of reading bytes, it reads directory entries. Its POSIX equivalent, readdir, indicates whether or not we reached the end of the directory by returning a NULL pointer: struct dirent *readdir(DIR *dirp); But this API needed to change for littlefs, since we don't use errno, instead returning errors as signed integers through all API functions, including lfs_dir_read. So, in an effort to match lfs_file_read, lfs_dir_read returned the "number" of directory entries read, limited to either 0 or 1. Perhaps unsurprisingly, this turned out to be confusing to users, and a better API was proposed hathach to instead return either 0 or LFS_ERR_NOENT, an error which can't occur for other reasons in lfs_dir_read. Suggested by hathach
This commit is contained in:
@@ -619,8 +619,9 @@ int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir);
|
||||
// Read an entry in the directory
|
||||
//
|
||||
// Fills out the info structure, based on the specified file or directory.
|
||||
// Returns a positive value on success, 0 at the end of directory,
|
||||
// or a negative error code on failure.
|
||||
//
|
||||
// Returns 0 on success, LFS_ERR_NOENT if there are no more directry entries,
|
||||
// or another negative error code on failure.
|
||||
int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info);
|
||||
|
||||
// Change the position of the directory
|
||||
|
||||
Reference in New Issue
Block a user