Don't call ReadArgs() if started from WB.
[tangerine.git] / compiler / clib / malloc.c
blob263a36cf36782f45fb22030dfcef53e82577f6d9
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function malloc().
6 */
8 #include "__arosc_privdata.h"
10 #include <errno.h>
11 #include <dos/dos.h>
12 #include <exec/memory.h>
13 #include <proto/exec.h>
14 #include <aros/symbolsets.h>
15 #include <aros/debug.h>
17 /*****************************************************************************
19 NAME */
20 #include <sys/types.h>
21 #include <stdlib.h>
23 void *malloc (
25 /* SYNOPSIS */
26 size_t size)
28 /* FUNCTION
29 Allocate size bytes of memory and return the address of the
30 first byte.
32 INPUTS
33 size - How much memory to allocate.
35 RESULT
36 A pointer to the allocated memory or NULL. If you don't need the
37 memory anymore, you can pass this pointer to free(). If you don't,
38 the memory will be freed for you when the application exits.
40 NOTES
41 This function must not be used in a shared library or in a threaded
42 application.
44 EXAMPLE
46 BUGS
48 SEE ALSO
49 free()
51 INTERNALS
53 ******************************************************************************/
55 UBYTE *mem = NULL;
56 AROS_GET_SYSBASE_OK
58 /* Allocate the memory */
59 mem = AllocPooled (__startup_mempool, size + AROS_ALIGN(sizeof(size_t)));
60 if (mem)
62 *((size_t *)mem) = size;
63 mem += AROS_ALIGN(sizeof(size_t));
65 else
66 errno = ENOMEM;
68 return mem;
70 } /* malloc */
73 int __init_memstuff(void)
75 AROS_GET_SYSBASE_OK
77 __startup_mempool = CreatePool(MEMF_ANY | MEMF_SEM_PROTECTED, 4096L, 2000L);
79 if (!__startup_mempool)
81 return 0;
84 return 1;
88 void __exit_memstuff(void)
90 AROS_GET_SYSBASE_OK
92 if (__startup_mempool)
94 DeletePool(__startup_mempool);
98 ADD2INIT(__init_memstuff, 0);
99 ADD2EXIT(__exit_memstuff, 0);