1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "easy_util.h"
17
18#include "easy_def.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24int MemoryInit(uint8_t* data, const size_t dataLen)
25{
26    if (data == NULL) {
27        return ERR_MEM_OPT_FAILED;
28    }
29    uint8_t* tmpData = data;
30    for (size_t index = 0; index < dataLen; ++index) {
31        *tmpData = 0;
32        ++tmpData;
33    }
34    return SUCCESS;
35}
36
37int MemoryCopy(uint8_t* dest, size_t destLen, uint8_t* src, const size_t srcLen)
38{
39    if ((dest == NULL) || (src == NULL) || (destLen < srcLen)) {
40        return ERR_MEM_OPT_FAILED;
41    }
42    uint8_t* destTmpData = dest;
43    uint8_t* srcTmpData = src;
44    for (size_t index = 0; index < srcLen; ++index) {
45        *destTmpData = *srcTmpData;
46        ++destTmpData;
47        ++srcTmpData;
48    }
49    return SUCCESS;
50}
51
52#ifdef __cplusplus
53}
54#endif