diff options
author | Marcel Moolenaar <marcel@FreeBSD.org> | 2016-09-26 04:14:00 +0000 |
---|---|---|
committer | Marcel Moolenaar <marcel@FreeBSD.org> | 2016-09-26 04:14:00 +0000 |
commit | 7b5a53ea4da12961edde4df7af211adb6df6b65c (patch) | |
tree | 98b5a0fcac6c889237cb8d916898b968a70994c8 | |
parent | d191be26c0b1758ca940ac0a7ad53eca88f34b2b (diff) | |
download | src-7b5a53ea4da12961edde4df7af211adb6df6b65c.tar.gz src-7b5a53ea4da12961edde4df7af211adb6df6b65c.zip |
Portability changes:
1. macOS nor Linux have MAP_NOCORE nor MAP_NOSYNC. Define as 0.
2. macOS doesn't have SEEK_DATA nor SEEK_HOLE. Define as -1
so that lseek will return -1 (with errno set to EINVAL).
3. gcc correctly warns that error is assigned but not used in
image_copyout_region(). Fix by returning on the first error.
Notes
Notes:
svn path=/head/; revision=306333
-rw-r--r-- | usr.bin/mkimg/image.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/usr.bin/mkimg/image.c b/usr.bin/mkimg/image.c index 39ae41230808..3a2936c20131 100644 --- a/usr.bin/mkimg/image.c +++ b/usr.bin/mkimg/image.c @@ -45,6 +45,20 @@ __FBSDID("$FreeBSD$"); #include "image.h" #include "mkimg.h" +#ifndef MAP_NOCORE +#define MAP_NOCORE 0 +#endif +#ifndef MAP_NOSYNC +#define MAP_NOSYNC 0 +#endif + +#ifndef SEEK_DATA +#define SEEK_DATA -1 +#endif +#ifndef SEEK_HOLE +#define SEEK_HOLE -1 +#endif + struct chunk { STAILQ_ENTRY(chunk) ch_list; size_t ch_size; /* Size of chunk in bytes. */ @@ -582,10 +596,13 @@ image_copyout_region(int fd, lba_t blk, lba_t size) size *= secsz; - while (size > 0) { + error = 0; + while (!error && size > 0) { ch = image_chunk_find(blk); - if (ch == NULL) - return (EINVAL); + if (ch == NULL) { + error = EINVAL; + break; + } ofs = (blk - ch->ch_block) * secsz; sz = ch->ch_size - ofs; sz = ((lba_t)sz < size) ? sz : (size_t)size; @@ -606,7 +623,7 @@ image_copyout_region(int fd, lba_t blk, lba_t size) size -= sz; blk += sz / secsz; } - return (0); + return (error); } int |