• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "hc_types.h"
17 #include <stdlib.h>
18 #include <string.h>
19 #include "hc_log.h"
20 #include "ohos_mem_pool.h"
21 
HcMalloc(uint32_t size,char val)22 void *HcMalloc(uint32_t size, char val)
23 {
24     if (size == 0) {
25         LOGE("Malloc size is invalid.");
26         return NULL;
27     }
28 #if defined(OHOS_MEM)
29     void *addr = OhosMalloc(MEM_TYPE_HICHAIN, size);
30 #else
31     void *addr = malloc(size);
32 #endif
33     if (addr != NULL) {
34         (void)memset_s(addr, size, val, size);
35     }
36     return addr;
37 }
38 
HcFree(void * addr)39 void HcFree(void *addr)
40 {
41     if (addr != NULL) {
42 #if defined(OHOS_MEM)
43     OhosFree(addr);
44 #else
45     free(addr);
46 #endif
47     }
48 }
49 
HcStrlen(const char * str)50 uint32_t HcStrlen(const char *str)
51 {
52     if (str == NULL) {
53         return 0;
54     }
55     const char *p = str;
56     while (*p++ != '\0') {}
57     return p - str - 1;
58 }
59 
60