xref: /llvm-project/libc/src/string/stpcpy.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
19b6f8b98SMichael Jones //===-- Implementation of stpcpy ------------------------------------------===//
29b6f8b98SMichael Jones //
39b6f8b98SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
49b6f8b98SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
59b6f8b98SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
69b6f8b98SMichael Jones //
79b6f8b98SMichael Jones //===----------------------------------------------------------------------===//
89b6f8b98SMichael Jones 
99b6f8b98SMichael Jones #include "src/string/stpcpy.h"
10*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
119b6f8b98SMichael Jones #include "src/string/mempcpy.h"
129b6f8b98SMichael Jones #include "src/string/string_utils.h"
139b6f8b98SMichael Jones 
149b6f8b98SMichael Jones #include "src/__support/common.h"
159b6f8b98SMichael Jones 
16*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
179b6f8b98SMichael Jones 
189b6f8b98SMichael Jones LLVM_LIBC_FUNCTION(char *, stpcpy,
199b6f8b98SMichael Jones                    (char *__restrict dest, const char *__restrict src)) {
209b6f8b98SMichael Jones   size_t size = internal::string_length(src) + 1;
219b6f8b98SMichael Jones   char *result =
22b6bc9d72SGuillaume Chatelet       reinterpret_cast<char *>(LIBC_NAMESPACE::mempcpy(dest, src, size));
239b6f8b98SMichael Jones 
249b6f8b98SMichael Jones   if (result != nullptr)
259b6f8b98SMichael Jones     return result - 1;
269b6f8b98SMichael Jones   return nullptr;
279b6f8b98SMichael Jones }
289b6f8b98SMichael Jones 
29*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
30