wut/libraries/wutdevoptab/devoptab_fs_diropen.c
James Benton 690bd6ccbd Revert "Rename wutdevoptab to wutdevoptab_sd"
This reverts commit 865af4609c49015c64f4092fd53315a1110b8042.
Turns out it is for whole filesystem. oops.
2018-07-19 08:51:40 +01:00

41 lines
850 B
C

#include "devoptab_fs.h"
DIR_ITER *
__wut_fs_diropen(struct _reent *r,
DIR_ITER *dirState,
const char *path)
{
FSDirectoryHandle fd;
FSStatus rc;
if (path == NULL) {
return NULL;
}
char *path_fixed = __wut_fs_fixpath(r,path);
if (!path_fixed) {
r->_errno = ENOMEM;
return NULL;
}
// Set up command block
FSCmdBlock fsCmd;
FSInitCmdBlock(&fsCmd);
__wut_fs_dir_t *dir = (__wut_fs_dir_t *)(dirState->dirStruct);
rc = FSOpenDir(__wut_devoptab_fs_client, &fsCmd, path_fixed, &fd, -1);
if (rc >= 0) {
dir->magic = FS_DIRITER_MAGIC;
dir->fd = fd;
memset(&dir->entry_data, 0, sizeof(dir->entry_data));
free(path_fixed);
return dirState;
}
free(path_fixed);
r->_errno = __wut_fs_translate_error(rc);
return NULL;
}