1 /*
2  * Copyright (c) 2023 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 "mock_adaptor_memory.h"
17 
18 #include <cstdlib>
19 
20 #include "securec.h"
21 
22 namespace OHOS {
23 namespace UserIam {
24 namespace UserAuth {
MallocTest(const size_t size)25 void *MockMemMgr::MallocTest(const size_t size)
26 {
27     if (size == 0) {
28         return NULL;
29     }
30 
31     void *data = malloc(size);
32     if (data != NULL) {
33         (void)memset_s(data, size, 0, size);
34     }
35 
36     return data;
37 }
38 
FreeTest(void * ptr)39 void MockMemMgr::FreeTest(void *ptr)
40 {
41     if (ptr == NULL) {
42         return;
43     }
44     free(ptr);
45 }
46 } // namespace UserAuth
47 } // namespace UserIam
48 } // namespace OHOS
49 
50 extern "C" {
51 using namespace OHOS::UserIam::UserAuth;
52 IMPLEMENT_FUNCTION_WITH_INVOKER(MockMemMgr, void *, Malloc, (const size_t size), MockMemMgr::MallocTest);
53 IMPLEMENT_FUNCTION_WITH_INVOKER(MockMemMgr, void, Free, (void *ptr), MockMemMgr::FreeTest);
54 }