application.mui: implemented MUIM_Application_UnpushMethod
[AROS.git] / compiler / stdc / malloc.c
blob393d689f3484c101bc028333ce19ba91c12aaae9
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function malloc().
6 */
8 #include "__stdc_intbase.h"
10 #define DEBUG 0
12 #include <errno.h>
13 #include <dos/dos.h>
14 #include <exec/memory.h>
15 #include <proto/exec.h>
16 #include <aros/symbolsets.h>
17 #include <aros/debug.h>
19 /*****************************************************************************
21 NAME */
22 #include <stdlib.h>
24 void *malloc (
26 /* SYNOPSIS */
27 size_t size)
29 /* FUNCTION
30 Allocate size bytes of memory and return the address of the
31 first byte.
33 INPUTS
34 size - How much memory to allocate.
36 RESULT
37 A pointer to the allocated memory or NULL. If you don't need the
38 memory anymore, you can pass this pointer to free(). If you don't,
39 the memory will be freed for you when the application exits.
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 free()
50 INTERNALS
52 ******************************************************************************/
54 struct StdCIntBase *StdCBase = (struct StdCIntBase *)__aros_getbase_StdCBase();
55 UBYTE *mem = NULL;
57 /* Allocate the memory */
58 mem = AllocPooled (StdCBase->mempool, size + AROS_ALIGN(sizeof(size_t)));
59 if (mem)
61 *((size_t *)mem) = size;
62 mem += AROS_ALIGN(sizeof(size_t));
64 else
65 errno = ENOMEM;
67 return mem;
69 } /* malloc */
72 int __init_memstuff(struct StdCIntBase *StdCBase)
74 D(bug("__init_memstuff: task(%x), StdCBase(%x)\n",
75 FindTask(NULL), StdCBase
76 ));
78 StdCBase->mempool = CreatePool(MEMF_ANY | MEMF_SEM_PROTECTED, 65536L, 4096L);
80 D(bug("__init_memstuff: StdCBase->mempool(%x)\n", StdCBase->mempool));
82 if (!StdCBase->mempool)
84 return 0;
87 return 1;
91 void __exit_memstuff(struct StdCIntBase *StdCBase)
93 D(bug("__exit_memstuff: task(%x), StdCBase(%x), acb_mempool(%x)\n",
94 FindTask(NULL), StdCBase, StdCBase->mempool
95 ));
97 if (StdCBase->mempool)
99 DeletePool(StdCBase->mempool);
103 ADD2OPENLIB(__init_memstuff, 0);
104 ADD2CLOSELIB(__exit_memstuff, 0);