1 /* $OpenBSD: util.h,v 1.6 2019/01/25 00:19:26 millert Exp $ */ 2 3 /* 4 * Placed in the public domain by Todd C. Miller <millert@openbsd.org> 5 * on October 9, 2004. 6 */ 7 8 #define MMAP(ptr, len, prot, flags, fd, off) do { \ 9 if ((ptr = mmap(NULL, len, prot, flags, fd, off)) == MAP_FAILED) { \ 10 usemmap = 0; \ 11 if (errno != EINVAL) \ 12 warn("mmap"); \ 13 else if ((ptr = malloc(len)) == NULL) { \ 14 ptr = MAP_FAILED; \ 15 warn("malloc"); \ 16 } else if (pread(fd, ptr, len, off) != len) { \ 17 free(ptr); \ 18 ptr = MAP_FAILED; \ 19 warn("pread"); \ 20 } \ 21 } \ 22 } while (0) 23 24 #define MUNMAP(addr, len) do { \ 25 if (usemmap) \ 26 munmap(addr, len); \ 27 else \ 28 free(addr); \ 29 addr = NULL; \ 30 } while (0) 31 32 extern int usemmap; 33 extern int dynamic_only; 34 35 struct xnlist { 36 struct nlist nl; 37 unsigned long n_size; 38 }; 39