1//===-- Implementation of strdup ------------------------------------------===//
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/string/strdup.h"
10#include "src/errno/libc_errno.h"
11#include "src/string/allocating_string_utils.h"
12#include "src/string/memory_utils/inline_memcpy.h"
13
14#include "src/__support/common.h"
15
16#include <stdlib.h>
17
18namespace LIBC_NAMESPACE {
19
20LLVM_LIBC_FUNCTION(char *, strdup, (const char *src)) {
21 auto dup = internal::strdup(src);
22 if (dup)
23 return *dup;
24 if (src != nullptr)
25 libc_errno = ENOMEM;
26 return nullptr;
27}
28
29} // namespace LIBC_NAMESPACE
30

source code of libc/src/string/strdup.cpp