From 0fe28fd69dd15006ccd684d563699420aadde61a Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 3 Oct 2006 01:37:17 +0000 Subject: first working version of uuterm! - at this point it is purely experimental. only ascii characters are visible (using builtin font) although all characters are processed. - there are known bugs, including crashes. - there are major missing features. - but it works. ^_^ --- alloc.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 alloc.c (limited to 'alloc.c') diff --git a/alloc.c b/alloc.c new file mode 100644 index 0000000..34058b3 --- /dev/null +++ b/alloc.c @@ -0,0 +1,37 @@ +/* uuterm, Copyright (C) 2006 Rich Felker; licensed under GNU GPL v2 only */ + +#include +#include + +#include "uuterm.h" + +void *uuterm_alloc(size_t len) +{ +#ifdef MAP_ANONYMOUS + size_t *mem = mmap(0, len+sizeof(size_t), + PROT_READ|PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (mem == MAP_FAILED) return 0; + *mem++ = len; + return mem; +#else + return malloc(len); +#endif +} + +void uuterm_free(void *buf) +{ +#ifdef MAP_ANONYMOUS + size_t *mem = buf; + mem--; + munmap(mem, *mem); +#else + free(buf); +#endif +} + +void *uuterm_buf_alloc(int w, int h) +{ + /* FIXME: do we care about overflows? */ + return uuterm_alloc(UU_BUF_SIZE(w, h)); +} -- cgit v1.2.3