diff options
author | Rich Felker <dalias@aerifal.cx> | 2006-10-03 01:37:17 +0000 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2006-10-03 01:37:17 +0000 |
commit | 0fe28fd69dd15006ccd684d563699420aadde61a (patch) | |
tree | 77a419dc56462f39c975b6c043a7bf344fc3f3e6 /alloc.c |
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. ^_^
Diffstat (limited to 'alloc.c')
-rw-r--r-- | alloc.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -0,0 +1,37 @@ +/* uuterm, Copyright (C) 2006 Rich Felker; licensed under GNU GPL v2 only */ + +#include <stdlib.h> +#include <sys/mman.h> + +#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)); +} |