os/ossrv/genericopenlibs/openenvcore/libc/src/ualloc.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-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 
    17 #include <e32std.h>
    18 #include <stdlib.h> //size_t
    19 #include <errno.h>
    20 
    21 // We use the EPOC32 memory allocation which is already
    22 // thread-safe, so we don't need the _malloc_r variants
    23 
    24 extern "C" {
    25 
    26 EXPORT_C void* malloc (size_t nbytes)
    27 	{
    28 	if (nbytes >= (KMaxTInt/2))
    29 		{
    30 		errno = ENOMEM;
    31 		return NULL;
    32 		}
    33 
    34 	TAny *Tptr = User::Alloc(nbytes);
    35 	if(Tptr == NULL)
    36 		errno = ENOMEM;
    37 	
    38 	return Tptr;
    39 	}
    40 
    41 EXPORT_C void* realloc (void *p, size_t nbytes)
    42 	{
    43 	if (nbytes >= (KMaxTInt/2))
    44 		{
    45 		errno = ENOMEM;
    46 		return NULL;
    47 		}
    48 		
    49 	TAny *Tptr = User::ReAlloc(p, nbytes);
    50 	if(Tptr == NULL)
    51 		errno = ENOMEM;
    52 	
    53 	return Tptr;
    54 	}
    55 
    56 EXPORT_C void free (void *p)
    57 	{
    58 	User::Free(p);
    59 	}
    60 
    61 } // extern "C"