libc: 'rmdir()': delete directories only

Fixes #2685
This commit is contained in:
Christian Prochaska 2018-02-23 17:40:30 +01:00 committed by Christian Helmuth
parent 88757a674a
commit ecff980761
1 changed files with 10 additions and 0 deletions

View File

@ -619,6 +619,16 @@ extern "C" int rename(const char *oldpath, const char *newpath)
extern "C" int rmdir(const char *path)
{
struct stat stat_buf;
if (stat(path, &stat_buf) == -1)
return -1;
if (!S_ISDIR(stat_buf.st_mode)) {
errno = ENOTDIR;
return -1;
}
try {
Absolute_path resolved_path;
resolve_symlinks_except_last_element(path, resolved_path);