os/ossrv/genericopenlibs/cstdlib/USTLIB/UALLOC.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/USTLIB/UALLOC.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,86 @@
     1.4 +// Copyright (c) 1998-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 <e32std.h>
    1.20 +#include <stdlib_r.h>
    1.21 +
    1.22 +// We use the EPOC32 memory allocation which is already
    1.23 +// thread-safe, so we don't need the _malloc_r variants
    1.24 +
    1.25 +extern "C" {
    1.26 +
    1.27 +EXPORT_C void* malloc (size_t nbytes)
    1.28 +	{
    1.29 +	return User::Alloc(nbytes);
    1.30 +	}
    1.31 +
    1.32 +EXPORT_C void* realloc (void *p, size_t nbytes)
    1.33 +	{
    1.34 +	return User::ReAlloc(p, nbytes);
    1.35 +	}
    1.36 +
    1.37 +EXPORT_C void free (void *p)
    1.38 +	{
    1.39 +	User::Free(p);
    1.40 +	}
    1.41 +
    1.42 +#ifdef EKA2
    1.43 +EXPORT_C void* _placeholder_memmove (void* to, const void* from, size_t len)
    1.44 +#else
    1.45 +EXPORT_C void* memmove (void* to, const void* from, size_t len)
    1.46 +#endif
    1.47 +	{
    1.48 +	Mem::Copy(to, from, len);		// E32 unaligned careful copy
    1.49 +	return to;
    1.50 +	}
    1.51 +
    1.52 +#ifdef EKA2
    1.53 +EXPORT_C void* _placeholder_memset (void* to, int c, size_t len)
    1.54 +#else
    1.55 +EXPORT_C void* memset (void* to, int c, size_t len)
    1.56 +#endif
    1.57 +	{
    1.58 +	Mem::Fill(to,len,c);
    1.59 +	return to;
    1.60 +	}
    1.61 +
    1.62 +EXPORT_C void* calloc (size_t n, size_t size)
    1.63 +    {
    1.64 +    n *= size;
    1.65 +    void *ret = User::Alloc(n);
    1.66 +    if (ret == 0)
    1.67 +	return 0;
    1.68 +    Mem::FillZ(ret,n);
    1.69 +    return ret;
    1.70 +    }
    1.71 +
    1.72 +EXPORT_C size_t strlen (const char *str)
    1.73 +    {
    1.74 +    return User::StringLength((TUint8*)str);
    1.75 +    }
    1.76 +
    1.77 +EXPORT_C size_t wcslen (const wchar_t *str)
    1.78 +    {
    1.79 +    return User::StringLength((TUint16*)str);
    1.80 +    }
    1.81 +
    1.82 +EXPORT_C unsigned int sleep (unsigned int secs)
    1.83 +	{
    1.84 +	// we don't allow the possibility of being woken by signals
    1.85 +	User::After(secs*1000000);
    1.86 +	return 0;
    1.87 +	}
    1.88 +
    1.89 +} // extern "C"