brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · c89be80 Raw
34 lines · cpp
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-exception6//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/__support/libc_errno.h"13#include "src/__support/macros/config.h"14 15namespace LIBC_NAMESPACE_DECL {16LLVM_LIBC_FUNCTION(int, hcreate_r,17                   (size_t capacity, struct hsearch_data *htab)) {18  if (htab == nullptr) {19    libc_errno = EINVAL;20    return 0;21  }22  uint64_t randomness = internal::randomness::next_random_seed();23  internal::HashTable *table =24      internal::HashTable::allocate(capacity, randomness);25  if (table == nullptr) {26    libc_errno = ENOMEM;27    return 0;28  }29  htab->__opaque = table;30  return 1;31}32 33} // namespace LIBC_NAMESPACE_DECL34