From 12f0744f340746b3a1c1accfdf993d6548f33e56 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 23 May 2017 17:35:49 -0700 Subject: Add and use xmmap. Everyone forgets that mmap returns MAP_FAILED rather than NULL on failure. Every use of mmap in toybox was either doing the wrong check, or no check at all (including the two I personally added). --- lib/xwrap.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/xwrap.c') diff --git a/lib/xwrap.c b/lib/xwrap.c index 0281e701..83f54a0a 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -58,6 +58,13 @@ void xexit(void) _xexit(); } +void *xmmap(void *addr, size_t length, int prot, int flags, int fd, off_t off) +{ + void *ret = mmap(addr, length, prot, flags, fd, off); + if (ret == MAP_FAILED) perror_exit("mmap"); + return ret; +} + // Die unless we can allocate memory. void *xmalloc(size_t size) { -- cgit v1.2.3