[libc-commits] [libc] [libc] Implement alphasort in dirent (PR #226487)

Aman Maurya via libc-commits libc-commits at lists.llvm.org
Tue Sep 29 18:13:54 PDT 2026


================
@@ -0,0 +1,110 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unit tests for the POSIX alphasort function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/dirent/alphasort.h"
+
+#include "hdr/types/struct_dirent.h"
+#include "src/stdlib/qsort.h"
+#include "src/string/memory_utils/inline_memcpy.h"
+#include "src/string/string_length.h"
+#include "test/UnitTest/Test.h"
+
+namespace {
+
+struct MockDirent {
+  static constexpr size_t EXTRA_NAME_LEN = 64;
+  static constexpr size_t BUFFER_SIZE = sizeof(struct dirent) + EXTRA_NAME_LEN;
+
+  alignas(struct dirent) char buf[BUFFER_SIZE]{};
+
+  MockDirent(const char *name) {
+    auto *d = reinterpret_cast<struct dirent *>(buf);
+    size_t len = LIBC_NAMESPACE::internal::string_length(name);
+    if (len > EXTRA_NAME_LEN)
----------------
amanmaurya92 wrote:

done

https://github.com/llvm/llvm-project/pull/226487


More information about the libc-commits mailing list