readdir_r use in tagcache.check_dir, ft_load

Change-Id: Ibcde39ed247e100dd47ae877fb2a3625bbb38d8b
This commit is contained in:
William Wilgus 2024-05-01 10:01:56 -04:00 committed by William Wilgus
parent f2f5543856
commit 0c737d3b2e
7 changed files with 129 additions and 24 deletions

View file

@ -159,6 +159,7 @@ file_error:
return rc;
}
#if 0
/* read a directory */
struct dirent * readdir(DIR *dirp)
{
@ -182,23 +183,19 @@ file_error:
return res;
}
#endif
#if 0 /* not included now but probably should be */
/* read a directory (reentrant) */
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
/* readdir, readdir_r common fn */
static int readdir_common(DIR *dirp, struct dirent *entry, struct dirent **result)
{
if (!result)
FILE_ERROR_RETURN(EFAULT, -2);
*result = NULL;
if (!entry)
FILE_ERROR_RETURN(EFAULT, -3);
*result = NULL; /* we checked for validity before calling, yes? */
struct dirstr_desc * const dir = GET_DIRSTR(READER, dirp);
if (!dir)
FILE_ERROR_RETURN(ERRNO, -1);
if (!entry)
entry = &dir->entry;
int rc = ns_readdir_dirent(&dir->stream, &dir->scan, entry);
if (rc < 0)
FILE_ERROR(EIO, rc * 10 - 4);
@ -218,6 +215,27 @@ file_error:
return rc;
}
/* read a directory */
struct dirent * readdir(DIR *dirp)
{
struct dirent *entry;
readdir_common(dirp, NULL, &entry);
return entry;
}
/* read a directory (reentrant) */
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
{
if (!result)
FILE_ERROR_RETURN(EFAULT, -2);
*result = NULL;
if (!entry)
FILE_ERROR_RETURN(EFAULT, -3);
return readdir_common(dirp, entry, result);
}
#if 0 /* not included now but probably should be */
/* reset the position of a directory stream to the beginning of a directory */
void rewinddir(DIR *dirp)
{