* 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. */
| 860 | * @return 0 on successful, others on failed. |
| 861 | */ |
| 862 | int 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 | } |
| 919 | RTM_EXPORT(rmdir); |
nothing calls this directly
no test coverage detected