iotivity 0.9.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / common / src / oic_malloc.c
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 //-----------------------------------------------------------------------------
22 // Includes
23 //-----------------------------------------------------------------------------
24 #include <stdlib.h>
25 #include "oic_malloc.h"
26
27 // Enable extra debug logging for malloc.  Comment out to disable
28 //#define ENABLE_MALLOC_DEBUG  (1)
29
30 #ifdef ENABLE_MALLOC_DEBUG
31 #include "logger.h"
32 #define TAG PCF("OICMalloc")
33 #endif
34
35 //-----------------------------------------------------------------------------
36 // Typedefs
37 //-----------------------------------------------------------------------------
38
39 //-----------------------------------------------------------------------------
40 // Private variables
41 //-----------------------------------------------------------------------------
42
43 //-----------------------------------------------------------------------------
44 // Macros
45 //-----------------------------------------------------------------------------
46
47 //-----------------------------------------------------------------------------
48 // Internal API function
49 //-----------------------------------------------------------------------------
50
51 //-----------------------------------------------------------------------------
52 // Private internal function prototypes
53 //-----------------------------------------------------------------------------
54
55 //-----------------------------------------------------------------------------
56 // Public APIs
57 //-----------------------------------------------------------------------------
58
59 void *OICMalloc(size_t size)
60 {
61 #ifdef ENABLE_MALLOC_DEBUG
62     void *ptr = 0;
63
64     if (0 == size)
65     {
66         return NULL;
67     }
68
69     ptr = malloc(size);
70     OIC_LOG_V(INFO, TAG, "malloc: ptr=%p, size=%u", ptr, size);
71     return ptr;
72 #else
73     if (0 == size)
74     {
75         return NULL;
76     }
77     return malloc(size);
78 #endif
79 }
80
81 void OICFree(void *ptr)
82 {
83 #ifdef ENABLE_MALLOC_DEBUG
84     OIC_LOG_V(INFO, TAG, "free: ptr=%p", ptr);
85 #endif
86
87     free(ptr);
88 }
89