1 //===-- Allocating string utils ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LIBC_SRC_STRING_ALLOCATING_STRING_UTILS_H
10 #define LIBC_SRC_STRING_ALLOCATING_STRING_UTILS_H
12 #include "src/__support/CPP/new.h"
13 #include "src/__support/CPP/optional.h"
14 #include "src/__support/macros/config.h"
15 #include "src/string/memory_utils/memcpy_implementations.h" // For string_length
16 #include "src/string/string_utils.h"
18 #include <stddef.h> // For size_t
20 namespace __llvm_libc
{
23 LIBC_INLINE
cpp::optional
<char *> strdup(const char *src
) {
26 size_t len
= string_length(src
) + 1;
28 char *newstr
= new (ac
) char[len
];
31 inline_memcpy(newstr
, src
, len
);
35 } // namespace internal
36 } // namespace __llvm_libc