merge with master
[platform/core/multimedia/libmm-fileinfo.git] / utils / mm_file_util_memory.c
1 /*
2  * libmm-fileinfo
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Haejeong Kim <backto.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include "mm_file_utils.h"
26
27 #ifdef __MMFILE_MEM_TRACE__
28 EXPORT_API
29 void *mmfile_malloc_debug (unsigned int size, const char *func, unsigned int line)
30 {
31         void *tmp = malloc (size);
32
33         if (tmp) {
34                 memset (tmp, 0x00, size);
35                 fprintf (stderr, "## DEBUG ## %p = malloc (%d) by %s() %d\n", tmp, size, func, line);
36         }
37         return tmp;
38 }
39
40 EXPORT_API
41 void *mmfile_calloc_debug (unsigned int nmemb, unsigned int size, const char *func, unsigned int line)
42 {
43         void *tmp = calloc (nmemb, size);
44
45         if (tmp) {
46                 fprintf (stderr, "## DEBUG ## %p = calloc (%d, %d) by %s() %d\n", tmp, nmemb, size, func, line);
47         }
48         return tmp;
49 }
50
51 EXPORT_API
52 void mmfile_free_debug (void *ptr, const char *func, unsigned int line)
53 {
54         if (ptr) {
55                 fprintf (stderr, "## DEBUG ## free (%p) by %s() %d\n", ptr, func, line);
56                 free (ptr);
57         }
58 }
59
60
61 EXPORT_API
62 void *mmfile_realloc_debug (void *ptr, unsigned int size, const char *func, unsigned int line)
63 {
64         void *tmp = realloc (ptr, size);
65
66         if (tmp) {
67                 fprintf (stderr, "## DEBUG ## %p = realloc (%p, %d) by %s() %d\n", tmp, ptr, size, func, line);
68         }
69         return tmp;
70 }
71
72 EXPORT_API
73 void *mmfile_memset_debug (void *s, int c, unsigned int n, const char *func, unsigned int line)
74 {
75         fprintf (stderr, "## DEBUG ## memset (%p, %d, %d) by %s() %d\n", s, c, n, func, line);
76         return memset (s, c, n);
77 }
78
79 EXPORT_API
80 void *mmfile_memcpy_debug (void *dest, const void *src, unsigned int n, const char *func, unsigned int line)
81 {
82         fprintf (stderr, "## DEBUG ## memcpy (%p, %p, %d) by %s() %d\n", dest, src, n, func, line);
83         return memcpy (dest, src, n);
84 }
85
86 #else   /* __MMFILE_MEM_TRACE__ : ------------------------------------------------------------------*/
87
88 EXPORT_API
89 void *mmfile_malloc (unsigned int size)
90 {
91     void *tmp = malloc (size);
92     if (tmp)
93     {
94         memset (tmp, 0x00, size);
95     }
96     return tmp;
97 }
98
99 EXPORT_API
100 void *mmfile_calloc (unsigned int nmemb, unsigned int size)
101 {
102     void *tmp = calloc (nmemb, size);
103     return tmp;
104 }
105
106 EXPORT_API
107 void mmfile_free_r (void *ptr)
108 {
109     if (ptr) free (ptr);
110 }
111
112 EXPORT_API
113 void *mmfile_realloc (void *ptr, unsigned int size)
114 {
115     return realloc (ptr, size);
116 }
117
118 EXPORT_API
119 void *mmfile_memset (void *s, int c, unsigned int n)
120 {
121     return memset (s, c, n);
122 }
123
124 EXPORT_API
125 void *mmfile_memcpy (void *dest, const void *src, unsigned int n)
126 {
127     return memcpy (dest, src, n);
128 }
129 #endif
130