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

Function rmdir

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

* this function is a POSIX compliant version, which will remove a directory. * * @param pathname the path name to be removed. * * @return 0 on successful, others on failed. */

Source from the content-addressed store, hash-verified

860 * @return 0 on successful, others on failed.
861 */
862int rmdir(const char *pathname)
863{
864 int result;
865 DIR *dir = RT_NULL;
866 struct stat stat;
867
868 if (!pathname)
869 {
870 rt_set_errno(-EPERM);
871 return -1;
872 }
873
874 dir = opendir(pathname);
875 if (dir)
876 {
877 struct dirent *dirent;
878
879 while (1)
880 {
881 dirent = readdir(dir);
882 if (dirent == RT_NULL)
883 break;
884 if (rt_strcmp(".", dirent->d_name) != 0 &&
885 rt_strcmp("..", dirent->d_name) != 0)
886 {
887 break;
888 }
889 }
890
891 closedir(dir);
892
893 if (dirent)
894 {
895 rt_set_errno(-EPERM);
896 return -1;
897 }
898 }
899
900 if (dfs_file_lstat(pathname, &stat) == 0)
901 {
902 if (S_ISLNK(stat.st_mode))
903 {
904 rt_set_errno(-EPERM);
905 return -1;
906 }
907 }
908
909 result = dfs_file_unlink(pathname);
910 if (result < 0)
911 {
912 rt_set_errno(result);
913
914 return -1;
915 }
916
917 return 0;
918}
919RTM_EXPORT(rmdir);

Callers

nothing calls this directly

Calls 7

rt_set_errnoFunction · 0.85
rt_strcmpFunction · 0.85
dfs_file_lstatFunction · 0.85
opendirFunction · 0.70
readdirFunction · 0.70
closedirFunction · 0.70
dfs_file_unlinkFunction · 0.70

Tested by

no test coverage detected