summaryrefslogtreecommitdiff
path: root/alloc.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2006-10-03 01:37:17 +0000
committerRich Felker <dalias@aerifal.cx>2006-10-03 01:37:17 +0000
commit0fe28fd69dd15006ccd684d563699420aadde61a (patch)
tree77a419dc56462f39c975b6c043a7bf344fc3f3e6 /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.c37
1 files changed, 37 insertions, 0 deletions
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 <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));
+}