HEBench
utilities.cpp
Go to the documentation of this file.
1 
2 // Copyright (C) 2021 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include <algorithm>
6 
8 
9 namespace hebench {
10 namespace cpp {
11 namespace Utilities {
12 
13 std::uint64_t copyString(char *dst, std::uint64_t size, const std::string &src)
14 {
15  std::uint64_t retval = src.size() + 1;
16 
17  if (dst && size > 0)
18  {
19  std::uint64_t min_size = std::min(size, retval);
20  if (min_size > 1)
21  std::copy_n(src.c_str(), min_size - 1, dst);
22  dst[min_size - 1] = '\0'; // close string
23  } // end if
24 
25  return retval;
26 }
27 
28 } // namespace Utilities
29 } // namespace cpp
30 } // namespace hebench
std::uint64_t copyString(char *dst, std::uint64_t size, const std::string &src)
Copies a C++ string object into a C-style string.
Definition: utilities.cpp:13