mtools: update to 4.0.18-r2 for clang fixes

BUG=chromium:644387
TEST=`emerge-amd64-generic mtools` works w/clang

Change-Id: I33d96b9a8bb37836e062ed0afadaa677dde5776f
Reviewed-on: https://chromium-review.googlesource.com/452160
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Yunlian Jiang <yunlian@chromium.org>
(cherry picked from commit cd57ab041601c8a0335fe38315388220f777527b)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/1582359
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Commit-Queue: Hung-Te Lin <hungte@chromium.org>
Tested-by: Hung-Te Lin <hungte@chromium.org>
diff --git a/sys-fs/mtools/files/mtools-4.0.18-attr.patch b/sys-fs/mtools/files/mtools-4.0.18-attr.patch
new file mode 100644
index 0000000..3cd770b
--- /dev/null
+++ b/sys-fs/mtools/files/mtools-4.0.18-attr.patch
@@ -0,0 +1,51 @@
+From e8437f906ca86fd5b1cac20d240a0e114c5df7a9 Mon Sep 17 00:00:00 2001
+From: Mike Frysinger <vapier@gentoo.org>
+Date: Thu, 9 Mar 2017 16:06:54 -0800
+Subject: [PATCH] fix unused attribute in func definition
+
+UNUSED is for wrapping variable decls, not for variables in a function
+definition.  It will insert a semi-colon into the mix which makes clang
+upset:
+x86_64-cros-linux-gnu-clang  -DHAVE_CONFIG_H -DSYSCONFDIR=\"/etc/mtools\" \
+	-DCPU_x86_64 -DVENDOR_cros -DOS_linux_gnu -O2 -pipe -O2 -pipe \
+	-march=x86-64 -msse3 -g -fno-exceptions -fno-unwind-tables \
+	-fno-asynchronous-unwind-tables  -clang-syntax -Wall \
+	-fno-strict-aliasing -I.  -I.  -c mainloop.c
+mainloop.c:89:15: error: expected ')'
+int unix_loop(UNUSED(Stream_t *Stream), MainParam_t *mp, char *arg,
+              ^
+./sysincludes.h:106:47: note: expanded from macro 'UNUSED'
+                                              ^
+
+Arguably this should fail on gcc too, but it doesn't today.
+
+URL: https://crbug.com/644387
+---
+ mainloop.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/mainloop.c b/mainloop.c
+index f5f8349f1472..69af9a80c3e4 100644
+--- a/mainloop.c
++++ b/mainloop.c
+@@ -86,7 +86,7 @@ static const char *fix_mcwd(char *ans)
+ }
+ 
+ int unix_dir_loop(Stream_t *Stream, MainParam_t *mp); 
+-int unix_loop(UNUSED(Stream_t *Stream), MainParam_t *mp, char *arg,
++int unix_loop(Stream_t *Stream UNUSEDP, MainParam_t *mp, char *arg,
+ 	      int follow_dir_link);
+ 
+ static int _unix_loop(Stream_t *Dir, MainParam_t *mp,
+@@ -95,7 +95,7 @@ static int _unix_loop(Stream_t *Dir, MainParam_t *mp,
+ 	return unix_dir_loop(Dir, mp);
+ }
+ 
+-int unix_loop(UNUSED(Stream_t *Stream), MainParam_t *mp,
++int unix_loop(Stream_t *Stream UNUSEDP, MainParam_t *mp,
+ 	      char *arg, int follow_dir_link)
+ {
+ 	int ret;
+-- 
+2.12.0
+
diff --git a/sys-fs/mtools/files/mtools-4.0.18-memset.patch b/sys-fs/mtools/files/mtools-4.0.18-memset.patch
new file mode 100644
index 0000000..cf8d724
--- /dev/null
+++ b/sys-fs/mtools/files/mtools-4.0.18-memset.patch
@@ -0,0 +1,27 @@
+From bafeabbc474a98314e8cecf42c8339e1da21fea2 Mon Sep 17 00:00:00 2001
+From: Mike Frysinger <vapier@gentoo.org>
+Date: Thu, 9 Mar 2017 16:23:19 -0800
+Subject: [PATCH] fix typo in scsi_cmd setup
+
+The memset call ends up referring to the function scsi_cmd and
+clearing its memory instead of the local my_scsi_cmd variable.
+---
+ scsi.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/scsi.c b/scsi.c
+index 7510edcefe95..85ff3bc3dc55 100644
+--- a/scsi.c
++++ b/scsi.c
+@@ -170,7 +170,7 @@ int scsi_cmd(int fd, unsigned char *cdb, int cmdlen, scsi_io_mode_t mode,
+ 	/*
+ 	** Init the command
+ 	*/
+-	memset(&scsi_cmd,0,sizeof(scsi_cmd));
++	memset(&my_scsi_cmd,0,sizeof(my_scsi_cmd));
+ 	my_scsi_cmd.interface_id    = 'S';
+ 	my_scsi_cmd.dxfer_direction = (mode == SCSI_IO_READ)?(SG_DXFER_FROM_DEV):(SG_DXFER_TO_DEV);
+ 	my_scsi_cmd.cmd_len         = cmdlen;
+-- 
+2.12.0
+
diff --git a/sys-fs/mtools/mtools-4.0.18-r1.ebuild b/sys-fs/mtools/mtools-4.0.18-r2.ebuild
similarity index 87%
rename from sys-fs/mtools/mtools-4.0.18-r1.ebuild
rename to sys-fs/mtools/mtools-4.0.18-r2.ebuild
index f3a7672..4729200 100644
--- a/sys-fs/mtools/mtools-4.0.18-r1.ebuild
+++ b/sys-fs/mtools/mtools-4.0.18-r2.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2016 Gentoo Foundation
+# Copyright 1999-2017 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI="5"
@@ -30,6 +30,8 @@
 	sed -i -e "s:mkdir:mkdir -p:" mkinstalldirs || die
 
 	epatch "${FILESDIR}"/${P}-locking.patch # https://crbug.com/508713
+	epatch "${FILESDIR}"/${P}-attr.patch # https://crbug.com/644387
+	epatch "${FILESDIR}"/${P}-memset.patch
 }
 
 src_configure() {