[libc-commits] [libc] [libc][windows] implement unistd/rmdir (PR #123742)
Sirui Mu via libc-commits
libc-commits at lists.llvm.org
Sat Jan 25 19:30:29 PST 2025
================
@@ -0,0 +1,28 @@
+//===-- Windows implementation of rmdir -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/rmdir.h"
+#include "src/__support/OSUtil/windows/error.h"
+#include "src/__support/common.h"
+#include "src/errno/libc_errno.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, rmdir, (const char *path)) {
+ if (::RemoveDirectoryA(path))
----------------
Lancern wrote:
The POSIX standard prohibits `rmdir` from deleting symbolic links to directories, while `RemoveDirectory` will silently remove such symbolic links referred by `path`. Consider first checking whether `path` is a symbolic link by calling `GetFileAttributes` and test its return value against the `FILE_ATTRIBUTE_REPARSE_POINT` mask.
BTW, the POSIX standard also prohibits `rmdir` from deleting paths whose final component is either `.` or `..`. I'm not quite sure whether `RemoveDirectory` rejects such paths, we could have a quick test to verify this.
https://github.com/llvm/llvm-project/pull/123742
More information about the libc-commits
mailing list