From 0c737d3b2e4728347cf4d52025f9fc2ebbee6e90 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Wed, 1 May 2024 10:01:56 -0400 Subject: readdir_r use in tagcache.check_dir, ft_load Change-Id: Ibcde39ed247e100dd47ae877fb2a3625bbb38d8b --- uisimulator/common/filesystem-sim.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'uisimulator/common/filesystem-sim.c') diff --git a/uisimulator/common/filesystem-sim.c b/uisimulator/common/filesystem-sim.c index f4f6321b7d..54e703ff40 100644 --- a/uisimulator/common/filesystem-sim.c +++ b/uisimulator/common/filesystem-sim.c @@ -704,6 +704,41 @@ struct sim_dirent * sim_readdir(DIR *dirp) return entry; } +/* read a directory (reentrant) */ +int sim_readdir_r(DIR *dirp, struct sim_dirent *entry, struct sim_dirent **result) +{ + if (!result) + FILE_ERROR_RETURN(EFAULT, -2); + + *result = NULL; + + if (!entry) + FILE_ERROR_RETURN(EFAULT, -3); + + struct dirstr_desc *dirstr = get_dirstr(dirp); + if (!dirstr) + FILE_ERROR_RETURN(ERRNO, -1); + + entry->info.osdirent = NULL; + + if (readdir_volume(dirstr, entry)) + { + *result = entry; + return 0; + } + OS_DIRENT_T *osdirent = os_readdir(dirstr->osdirp); + if (!osdirent) + FILE_ERROR_RETURN(ERRNO, -4); + + size_t size = sizeof (entry->d_name); + if (strlcpy_from_os(entry->d_name, osdirent->d_name, size) >= size) + FILE_ERROR_RETURN(ENAMETOOLONG, -5); + + entry->info.osdirent = osdirent; + *result = entry; + return 0; +} + int sim_mkdir(const char *path) { char ospath[SIM_TMPBUF_MAX_PATH]; -- cgit v1.2.3