1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "chre/util/nanoapp/string.h"
18 #include "chre/util/nanoapp/assert.h"
19 
20 namespace chre {
21 
copyString(char * destination,const char * source,size_t destinationBufferSize)22 void copyString(char *destination, const char *source,
23                 size_t destinationBufferSize) {
24   CHRE_ASSERT_NOT_NULL(destination);
25   CHRE_ASSERT_NOT_NULL(source);
26 
27   if (destinationBufferSize == 0) {
28     return;
29   }
30 
31   uint32_t i;
32   for (i = 0; i < destinationBufferSize - 1 && source[i] != '\0'; ++i) {
33     destination[i] = source[i];
34   }
35 
36   memset(&destination[i], 0, destinationBufferSize - i);
37 }
38 
39 }  // namespace chre
40