mmplugins/lib3gp/impl/src/memwrap.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <3gplibrary/mp4config.h>
       
    17 #include <stdlib.h>
       
    18 #include <string.h>
       
    19 
       
    20 
       
    21 /*
       
    22  * Function:
       
    23  *
       
    24  *   void *mp4malloc(size_t size)
       
    25  *
       
    26  * Description:
       
    27  *
       
    28  *   This is a wrapper for standard C library function calloc.
       
    29  *
       
    30  * Parameters:
       
    31  *
       
    32  *   size   Size of memory block to be allocated.
       
    33  *
       
    34  * Return value:
       
    35  *
       
    36  *   See calloc.
       
    37  *
       
    38  */
       
    39 void *mp4malloc(size_t size)
       
    40 	{
       
    41 	TInt sizex = size;
       
    42   
       
    43 	if ( sizex <= 0 || sizex >= KMaxTInt/2 )
       
    44 		{
       
    45 		return NULL;    // calloc will panic with negative values or size >= KMaxTInt / 2
       
    46 		}
       
    47 	else
       
    48 		{
       
    49 		return calloc(size, 1);
       
    50 		}
       
    51 	}
       
    52 
       
    53 
       
    54 /*
       
    55  * Function:
       
    56  *
       
    57  *   void *mp4realloc(void *memblock,
       
    58  *                    size_t size,
       
    59  *                    size_t oldsize)
       
    60  *
       
    61  * Description:
       
    62  *
       
    63  *   This is a wrapper for standard C library function realloc.
       
    64  *
       
    65  * Parameters:
       
    66  *
       
    67  *   memblock   Allocated memory pointer
       
    68  *   size       New size
       
    69  *   oldsize    Size of memblock
       
    70  *
       
    71  * Return value:
       
    72  *
       
    73  *   See realloc.
       
    74  *
       
    75  */
       
    76 void *mp4realloc(void *memblock, size_t size, size_t oldsize)
       
    77 {
       
    78   void *p;
       
    79 
       
    80   p = realloc(memblock, size);
       
    81   if (p == NULL)
       
    82     return p;
       
    83 
       
    84   memset(((mp4_u8 *)p) + oldsize, 0, size - oldsize);
       
    85 
       
    86   return p;
       
    87 }
       
    88 
       
    89 
       
    90 /*
       
    91  * Function:
       
    92  *
       
    93  *   void mp4free(void *mem)
       
    94  *
       
    95  * Description:
       
    96  *
       
    97  *   This is a wrapper for standard C library function free.
       
    98  *
       
    99  * Parameters:
       
   100  *
       
   101  *   mem   Pointer to allocated memory
       
   102  *
       
   103  * Return value:
       
   104  *
       
   105  *   None
       
   106  *
       
   107  */
       
   108 void mp4free(void *mem)
       
   109 {
       
   110   free(mem);
       
   111 }
       
   112 
       
   113 
       
   114 /*
       
   115  * Function:
       
   116  *
       
   117  *   void *mp4memcpy(void *dest,
       
   118  *                   void *src,
       
   119  *                   mp4_u32 count)
       
   120  *
       
   121  * Description:
       
   122  *
       
   123  *   This is a wrapper for standard C library function memcpy.
       
   124  *
       
   125  * Parameters:
       
   126  *
       
   127  *   dest    Destination of copy
       
   128  *   src     Source of copy
       
   129  *   count   Number of nytes to copy
       
   130  *
       
   131  * Return value:
       
   132  *
       
   133  *   See memcpy.
       
   134  *
       
   135  */
       
   136 void *mp4memcpy(void *dest, void *src, mp4_u32 count)
       
   137 {
       
   138   memcpy(dest, src, count);
       
   139 
       
   140   return dest;
       
   141 }
       
   142 
       
   143 // End of File