ack/lang/cem/libcc.ansi/malloc/malloc.h
David Given a200a2fb53 Replaced the funky and hard-to-compile ACK malloc with a much smaller
and simpler one stolen from K&R. libc builds now.
2016-08-11 00:30:32 +02:00

26 lines
539 B
C

/* This is an ANSI C version of the classic K&R memory allocator, with
* some improvements stolen from the Fuzix libc.
*/
#ifndef MALLOC_H
#define MALLOC_H
typedef struct block_s {
struct block_s* next;
size_t size; /* in sizeof(block_t) units */
} block_t;
extern block_t __mem_root;
extern block_t* __mem_first_free;
#define BLOCKOF(p) (((block_t*)(p)) - 1)
/* Smallest amount to allocate from brk */
#define BRKSIZE (512 / sizeof(block_t))
#define BLOCKCOUNT(bytes) \
(bytes + sizeof(block_t) + sizeof(block_t) - 1)
#endif