[libc-commits] [libc] [libc] [search] implement hcreate(_r)/hsearch(_r)/hdestroy(_r) (PR #73469)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Mon Nov 27 16:19:25 PST 2023
================
@@ -0,0 +1,35 @@
+//===-- Implementation of hsearch -------------------------------*- C++ -*-===//
+//
+// 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/search/hsearch.h"
+#include "src/__support/HashTable/table.h"
+#include "src/errno/libc_errno.h"
+#include "src/search/hsearch/global.h"
+
+namespace LIBC_NAMESPACE {
+LLVM_LIBC_FUNCTION(ENTRY *, hsearch, (ENTRY item, ACTION action)) {
+ ENTRY *result;
+
+ switch (action) {
+ case FIND:
+ result = internal::global_hash_table->find(item.key);
+ if (result == nullptr) {
+ libc_errno = ESRCH;
+ }
+ break;
+ case ENTER:
+ result = internal::global_hash_table->insert(item);
----------------
SchrodingerZhu wrote:
`POSIX.1` leaves it as unspecified. Per `MUSL`'s implementation, such cases (including memory leak caused by multiple hcreate) are not checked.
https://github.com/llvm/llvm-project/pull/73469
More information about the libc-commits
mailing list