1*9b6f8b98SMichael Jones //===-- Implementation of stpcpy ------------------------------------------===//
2*9b6f8b98SMichael Jones //
3*9b6f8b98SMichael Jones // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*9b6f8b98SMichael Jones // See https://llvm.org/LICENSE.txt for license information.
5*9b6f8b98SMichael Jones // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*9b6f8b98SMichael Jones //
7*9b6f8b98SMichael Jones //===----------------------------------------------------------------------===//
8*9b6f8b98SMichael Jones 
9*9b6f8b98SMichael Jones #include "src/string/stpcpy.h"
10*9b6f8b98SMichael Jones #include "src/string/mempcpy.h"
11*9b6f8b98SMichael Jones #include "src/string/string_utils.h"
12*9b6f8b98SMichael Jones 
13*9b6f8b98SMichael Jones #include "src/__support/common.h"
14*9b6f8b98SMichael Jones #include "src/__support/sanitizer.h"
15*9b6f8b98SMichael Jones 
16*9b6f8b98SMichael Jones namespace __llvm_libc {
17*9b6f8b98SMichael Jones 
18*9b6f8b98SMichael Jones LLVM_LIBC_FUNCTION(char *, stpcpy,
19*9b6f8b98SMichael Jones                    (char *__restrict dest, const char *__restrict src)) {
20*9b6f8b98SMichael Jones   size_t size = internal::string_length(src) + 1;
21*9b6f8b98SMichael Jones   char *result =
22*9b6f8b98SMichael Jones       reinterpret_cast<char *>(__llvm_libc::mempcpy(dest, src, size));
23*9b6f8b98SMichael Jones 
24*9b6f8b98SMichael Jones   if (result != nullptr)
25*9b6f8b98SMichael Jones     return result - 1;
26*9b6f8b98SMichael Jones   return nullptr;
27*9b6f8b98SMichael Jones }
28*9b6f8b98SMichael Jones 
29*9b6f8b98SMichael Jones } // namespace __llvm_libc
30