|
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 #include <e32std.h> |
|
17 #include <stdlib_r.h> |
|
18 |
|
19 // We use the EPOC32 memory allocation which is already |
|
20 // thread-safe, so we don't need the _malloc_r variants |
|
21 |
|
22 extern "C" { |
|
23 |
|
24 EXPORT_C void* malloc (size_t nbytes) |
|
25 { |
|
26 return User::Alloc(nbytes); |
|
27 } |
|
28 |
|
29 EXPORT_C void* realloc (void *p, size_t nbytes) |
|
30 { |
|
31 return User::ReAlloc(p, nbytes); |
|
32 } |
|
33 |
|
34 EXPORT_C void free (void *p) |
|
35 { |
|
36 User::Free(p); |
|
37 } |
|
38 |
|
39 #ifdef EKA2 |
|
40 EXPORT_C void* _placeholder_memmove (void* to, const void* from, size_t len) |
|
41 #else |
|
42 EXPORT_C void* memmove (void* to, const void* from, size_t len) |
|
43 #endif |
|
44 { |
|
45 Mem::Copy(to, from, len); // E32 unaligned careful copy |
|
46 return to; |
|
47 } |
|
48 |
|
49 #ifdef EKA2 |
|
50 EXPORT_C void* _placeholder_memset (void* to, int c, size_t len) |
|
51 #else |
|
52 EXPORT_C void* memset (void* to, int c, size_t len) |
|
53 #endif |
|
54 { |
|
55 Mem::Fill(to,len,c); |
|
56 return to; |
|
57 } |
|
58 |
|
59 EXPORT_C void* calloc (size_t n, size_t size) |
|
60 { |
|
61 n *= size; |
|
62 void *ret = User::Alloc(n); |
|
63 if (ret == 0) |
|
64 return 0; |
|
65 Mem::FillZ(ret,n); |
|
66 return ret; |
|
67 } |
|
68 |
|
69 EXPORT_C size_t strlen (const char *str) |
|
70 { |
|
71 return User::StringLength((TUint8*)str); |
|
72 } |
|
73 |
|
74 EXPORT_C size_t wcslen (const wchar_t *str) |
|
75 { |
|
76 return User::StringLength((TUint16*)str); |
|
77 } |
|
78 |
|
79 EXPORT_C unsigned int sleep (unsigned int secs) |
|
80 { |
|
81 // we don't allow the possibility of being woken by signals |
|
82 User::After(secs*1000000); |
|
83 return 0; |
|
84 } |
|
85 |
|
86 } // extern "C" |