• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "memory.h"
17 #include "memory_mock.h"
18 
19 #include "log.h"
20 #include "securec.h"
21 
22 static bool g_isMock = false;
23 
SetMockFlag(bool flag)24 void SetMockFlag(bool flag)
25 {
26     g_isMock = flag;
27 }
28 
HcfMalloc(uint32_t size,char val)29 void *HcfMalloc(uint32_t size, char val)
30 {
31     if (g_isMock) {
32         return NULL;
33     }
34     void *addr = malloc(size);
35     if (addr != NULL) {
36         (void)memset_s(addr, size, val, size);
37     }
38     return addr;
39 }
40 
HcfFree(void * addr)41 void HcfFree(void *addr)
42 {
43     if (addr != NULL) {
44         free(addr);
45     }
46 }
47