Annotation of src/usr.bin/nm/util.h, Revision 1.4
1.4 ! semarie 1: /* $OpenBSD: util.h,v 1.3 2015/05/17 20:19:08 guenther Exp $ */
1.2 millert 2:
3: /*
4: * Placed in the public domain by Todd C. Miller <Todd.Miller@courtesan.com>
5: * on October 9, 2004.
6: */
1.1 mickey 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); \
1.4 ! semarie 29: addr = NULL; \
1.1 mickey 30: } while (0)
31:
32: extern int usemmap;
1.3 guenther 33: extern int dynamic_only;