utils.c (597B)
1 /* See LICENSE file for copyright and license details. */ 2 3 #include "proto.h" 4 5 void * 6 xmalloc(size_t size) 7 { 8 void *p; 9 10 p = malloc(size); 11 if (!p) 12 err(1, "malloc"); 13 return p; 14 } 15 16 void * 17 xrealloc(void *ptr, size_t size) 18 { 19 void *p; 20 21 p = realloc(ptr, size); 22 if (!p) 23 err(1, "malloc"); 24 return p; 25 } 26 27 void * 28 map_buf(size_t len) 29 { 30 void *buf; 31 32 buf = mmap(0, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 33 -1, 0); 34 if (buf == MAP_FAILED) 35 err(1, "mmap"); 36 37 return buf; 38 } 39 40 void 41 unmap_buf(void *buf, size_t len) 42 { 43 int ret; 44 45 ret = munmap(buf, len); 46 if (ret < 0) 47 err(1, "munmap"); 48 }