MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / opendir

Function opendir

components/dfs/dfs_v2/src/dfs_posix.c:928–975  ·  view source on GitHub ↗

* this function is a POSIX compliant version, which will open a directory. * * @param name the path name to be open. * * @return the DIR pointer of directory, NULL on open directory failed. */

Source from the content-addressed store, hash-verified

926 * @return the DIR pointer of directory, NULL on open directory failed.
927 */
928DIR *opendir(const char *name)
929{
930 DIR *t = RT_NULL;
931 int fd, result;
932 struct dfs_file *file = RT_NULL;
933
934 if (!name || dfs_file_isdir(name) != 0)
935 {
936 rt_set_errno(-RT_ERROR);
937 return RT_NULL;
938 }
939
940 fd = fd_new();
941 if (fd >= 0)
942 {
943 file = fd_get(fd);
944 }
945 else
946 {
947 rt_set_errno(-RT_ERROR);
948 return RT_NULL;
949 }
950
951 result = dfs_file_open(file, name, O_RDONLY | O_DIRECTORY, 0);
952 if (result >= 0)
953 {
954 /* open successfully */
955 t = (DIR *) rt_malloc(sizeof(DIR));
956 if (t == NULL)
957 {
958 dfs_file_close(file);
959 fd_release(fd);
960 }
961 else
962 {
963 rt_memset(t, 0, sizeof(DIR));
964
965 t->fd = fd;
966 }
967
968 return t;
969 }
970
971 fd_release(fd);
972 rt_set_errno(result);
973
974 return NULL;
975}
976RTM_EXPORT(opendir);
977
978/**

Callers 2

rmdirFunction · 0.70
chdirFunction · 0.70

Calls 9

dfs_file_isdirFunction · 0.85
rt_set_errnoFunction · 0.85
rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
fd_newFunction · 0.70
fd_getFunction · 0.70
dfs_file_openFunction · 0.70
dfs_file_closeFunction · 0.70
fd_releaseFunction · 0.70

Tested by

no test coverage detected