Skip to content

Commit 0116449

Browse files
fix(storage/spiffs): fix readdir setting errno on directory end
spiffs_res_to_errno maps `SPIFFS_ERR_END_OF_OBJECT` to EIO which breaks the common contract where errno should be 0 if readdir iterated through all the entries in a directory. The fix is explicitly checking for `SPIFFS_ERR_END_OF_OBJECT` and in that case set errno to 0.
1 parent ff97953 commit 0116449

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

components/spiffs/esp_spiffs.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,15 @@ static int vfs_spiffs_readdir_r(void* ctx, DIR* pdir, struct dirent* entry,
746746
char * item_name;
747747
do {
748748
if (SPIFFS_readdir(&dir->d, &out) == 0) {
749-
errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs));
749+
s32_t spiffs_res = SPIFFS_errno(efs->fs);
750+
switch (spiffs_res) {
751+
case SPIFFS_ERR_END_OF_OBJECT:
752+
errno = 0;
753+
break;
754+
default:
755+
errno = spiffs_res_to_errno(spiffs_res);
756+
break;
757+
}
750758
SPIFFS_clearerr(efs->fs);
751759
if (!errno) {
752760
*out_dirent = NULL;

0 commit comments

Comments
 (0)