1 //===-- Implementation of hcreate_r -----------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/search/hcreate_r.h" 10 #include "src/__support/HashTable/randomness.h" 11 #include "src/__support/HashTable/table.h" 12 #include "src/errno/libc_errno.h" 13 14 namespace LIBC_NAMESPACE { 15 LLVM_LIBC_FUNCTION(int, hcreate_r, 16 (size_t capacity, struct hsearch_data *htab)) { 17 if (htab == nullptr) { 18 libc_errno = EINVAL; 19 return 0; 20 } 21 uint64_t randomness = internal::randomness::next_random_seed(); 22 internal::HashTable *table = 23 internal::HashTable::allocate(capacity, randomness); 24 if (table == nullptr) { 25 libc_errno = ENOMEM; 26 return 0; 27 } 28 htab->__opaque = table; 29 return 1; 30 } 31 32 } // namespace LIBC_NAMESPACE 33