From ecff9807619d2f050eba48434136c86a883b6dfb Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Fri, 23 Feb 2018 17:40:30 +0100 Subject: [PATCH] libc: 'rmdir()': delete directories only Fixes #2685 --- repos/libports/src/lib/libc/file_operations.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/repos/libports/src/lib/libc/file_operations.cc b/repos/libports/src/lib/libc/file_operations.cc index a19818c81..46502d7a0 100644 --- a/repos/libports/src/lib/libc/file_operations.cc +++ b/repos/libports/src/lib/libc/file_operations.cc @@ -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);