svn commit: r306333 - head/usr.bin/mkimg

Marcel Moolenaar marcel at FreeBSD.org
Mon Sep 26 04:14:01 UTC 2016


Author: marcel
Date: Mon Sep 26 04:14:00 2016
New Revision: 306333
URL: https://svnweb.freebsd.org/changeset/base/306333

Log:
  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.

Modified:
  head/usr.bin/mkimg/image.c

Modified: head/usr.bin/mkimg/image.c
==============================================================================
--- head/usr.bin/mkimg/image.c	Mon Sep 26 02:29:28 2016	(r306332)
+++ head/usr.bin/mkimg/image.c	Mon Sep 26 04:14:00 2016	(r306333)
@@ -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, 
 
 	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, 
 		size -= sz;
 		blk += sz / secsz;
 	}
-	return (0);
+	return (error);
 }
 
 int


More information about the svn-src-head mailing list