summaryrefslogtreecommitdiff
path: root/usr.bin/nm/util.h
blob: 64b4637eb103d00e669338b11ba7da50c3db0c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*	$OpenBSD: util.h,v 1.6 2019/01/25 00:19:26 millert Exp $	*/

/*
 * Placed in the public domain by Todd C. Miller <millert@openbsd.org>
 * on October 9, 2004.
 */

#define	MMAP(ptr, len, prot, flags, fd, off)	do {		\
	if ((ptr = mmap(NULL, len, prot, flags, fd, off)) == MAP_FAILED) { \
		usemmap = 0;						\
		if (errno != EINVAL)					\
			warn("mmap");					\
		else if ((ptr = malloc(len)) == NULL) {			\
			ptr = MAP_FAILED;				\
			warn("malloc");					\
		} else if (pread(fd, ptr, len, off) != len) {		\
			free(ptr);					\
			ptr = MAP_FAILED;				\
			warn("pread");					\
		}							\
	}								\
} while (0)

#define MUNMAP(addr, len)	do {					\
	if (usemmap)							\
		munmap(addr, len);					\
	else								\
		free(addr);						\
	addr = NULL;							\
} while (0)

extern int usemmap;
extern int dynamic_only;

struct xnlist {
	struct nlist nl;
	unsigned long n_size;
};