diff options
author | Elliott Hughes <enh@google.com> | 2017-05-23 17:35:49 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2017-05-24 19:56:58 -0500 |
commit | 12f0744f340746b3a1c1accfdf993d6548f33e56 (patch) | |
tree | 7fa4ac6625bcaff12c300f4ef54d53649cfe7628 /lib | |
parent | 5a159cceb35fe08e444bd5a1771f8059888b03ff (diff) | |
download | toybox-12f0744f340746b3a1c1accfdf993d6548f33e56.tar.gz |
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).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.h | 1 | ||||
-rw-r--r-- | lib/xwrap.c | 7 |
2 files changed, 8 insertions, 0 deletions
@@ -115,6 +115,7 @@ void xstrncpy(char *dest, char *src, size_t size); void xstrncat(char *dest, char *src, size_t size); void _xexit(void) noreturn; void xexit(void) noreturn; +void *xmmap(void *addr, size_t length, int prot, int flags, int fd, off_t off); void *xmalloc(size_t size); void *xzalloc(size_t size); void *xrealloc(void *ptr, size_t size); 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) { |