* 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. */
| 926 | * @return the DIR pointer of directory, NULL on open directory failed. |
| 927 | */ |
| 928 | DIR *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 | } |
| 976 | RTM_EXPORT(opendir); |
| 977 | |
| 978 | /** |
no test coverage detected