1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmplugins/lib3gp/impl/src/memwrap.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,143 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <3gplibrary/mp4config.h>
1.20 +#include <stdlib.h>
1.21 +#include <string.h>
1.22 +
1.23 +
1.24 +/*
1.25 + * Function:
1.26 + *
1.27 + * void *mp4malloc(size_t size)
1.28 + *
1.29 + * Description:
1.30 + *
1.31 + * This is a wrapper for standard C library function calloc.
1.32 + *
1.33 + * Parameters:
1.34 + *
1.35 + * size Size of memory block to be allocated.
1.36 + *
1.37 + * Return value:
1.38 + *
1.39 + * See calloc.
1.40 + *
1.41 + */
1.42 +void *mp4malloc(size_t size)
1.43 + {
1.44 + TInt sizex = size;
1.45 +
1.46 + if ( sizex <= 0 || sizex >= KMaxTInt/2 )
1.47 + {
1.48 + return NULL; // calloc will panic with negative values or size >= KMaxTInt / 2
1.49 + }
1.50 + else
1.51 + {
1.52 + return calloc(size, 1);
1.53 + }
1.54 + }
1.55 +
1.56 +
1.57 +/*
1.58 + * Function:
1.59 + *
1.60 + * void *mp4realloc(void *memblock,
1.61 + * size_t size,
1.62 + * size_t oldsize)
1.63 + *
1.64 + * Description:
1.65 + *
1.66 + * This is a wrapper for standard C library function realloc.
1.67 + *
1.68 + * Parameters:
1.69 + *
1.70 + * memblock Allocated memory pointer
1.71 + * size New size
1.72 + * oldsize Size of memblock
1.73 + *
1.74 + * Return value:
1.75 + *
1.76 + * See realloc.
1.77 + *
1.78 + */
1.79 +void *mp4realloc(void *memblock, size_t size, size_t oldsize)
1.80 +{
1.81 + void *p;
1.82 +
1.83 + p = realloc(memblock, size);
1.84 + if (p == NULL)
1.85 + return p;
1.86 +
1.87 + memset(((mp4_u8 *)p) + oldsize, 0, size - oldsize);
1.88 +
1.89 + return p;
1.90 +}
1.91 +
1.92 +
1.93 +/*
1.94 + * Function:
1.95 + *
1.96 + * void mp4free(void *mem)
1.97 + *
1.98 + * Description:
1.99 + *
1.100 + * This is a wrapper for standard C library function free.
1.101 + *
1.102 + * Parameters:
1.103 + *
1.104 + * mem Pointer to allocated memory
1.105 + *
1.106 + * Return value:
1.107 + *
1.108 + * None
1.109 + *
1.110 + */
1.111 +void mp4free(void *mem)
1.112 +{
1.113 + free(mem);
1.114 +}
1.115 +
1.116 +
1.117 +/*
1.118 + * Function:
1.119 + *
1.120 + * void *mp4memcpy(void *dest,
1.121 + * void *src,
1.122 + * mp4_u32 count)
1.123 + *
1.124 + * Description:
1.125 + *
1.126 + * This is a wrapper for standard C library function memcpy.
1.127 + *
1.128 + * Parameters:
1.129 + *
1.130 + * dest Destination of copy
1.131 + * src Source of copy
1.132 + * count Number of nytes to copy
1.133 + *
1.134 + * Return value:
1.135 + *
1.136 + * See memcpy.
1.137 + *
1.138 + */
1.139 +void *mp4memcpy(void *dest, void *src, mp4_u32 count)
1.140 +{
1.141 + memcpy(dest, src, count);
1.142 +
1.143 + return dest;
1.144 +}
1.145 +
1.146 +// End of File