sed: upgrade to 4.2.2

This pulls upstream sed 4.2.2. It fixes a but when
building with clang fortify.

BUG=chromium:638456
TEST=cbuildbot chromiumos-sdk falco-release

Change-Id: I48cb04ea63ac1ee2bb9759d63e034bc0a4a07fca
Reviewed-on: https://chromium-review.googlesource.com/374042
Commit-Ready: Yunlian Jiang <yunlian@chromium.org>
Tested-by: Yunlian Jiang <yunlian@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/sys-apps/sed/Manifest b/sys-apps/sed/Manifest
index 8bfc389..00963fb 100644
--- a/sys-apps/sed/Manifest
+++ b/sys-apps/sed/Manifest
@@ -1 +1 @@
-DIST sed-4.2.1.tar.bz2 899091 RMD160 f664dca0ca4472554ea0d595d544e232a3de51ad SHA1 ace93d23eabc00d3a8187ecf07d3a02b1b297810 SHA256 2ac3b36ca37bfeb43c4ef4025778cd66d89c77abb843d90552a515a7c9d2948f
+DIST sed-4.2.2.tar.bz2 1059414 SHA256 f048d1838da284c8bc9753e4506b85a1e0cc1ea8999d36f6995bcb9460cddbd7 SHA512 dbbb0bb348fac54612d29182c09c88bda7096dea03bd94f03c580c24146e65a06db12808c6a1a9adc94548fa3843511e3e80b251cb07142110cf149eab23f573 WHIRLPOOL d816657c51a2718c2b309455facaff50c9da08b79d20985ab1d61faa5b42bffa0b33ea7d3368a8cdaa6079891cfc27cdab38788563c8323081580b4478c7e2b5
diff --git a/sys-apps/sed/files/dos2unix b/sys-apps/sed/files/dos2unix
deleted file mode 100755
index b046880..0000000
--- a/sys-apps/sed/files/dos2unix
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-exec sed -e 's/\x0D$//' "$@"
diff --git a/sys-apps/sed/files/sed-4.2.1-handle-incomplete-sequences-as-if-they-were-invalid.patch b/sys-apps/sed/files/sed-4.2.1-handle-incomplete-sequences-as-if-they-were-invalid.patch
deleted file mode 100644
index dfd9206..0000000
--- a/sys-apps/sed/files/sed-4.2.1-handle-incomplete-sequences-as-if-they-were-invalid.patch
+++ /dev/null
@@ -1,45 +0,0 @@
-http://bugs.gentoo.org/284403
-
-From 20f68fb1abe862a98bc0378e5bb54d94bb98b8fe Mon Sep 17 00:00:00 2001
-From: Paolo Bonzini <bonzini@gnu.org>
-Date: Thu, 15 Oct 2009 19:56:12 +0200
-Subject: [PATCH] handle incomplete sequences as if they were invalid
-
-2009-10-15  Paolo Bonzini  <bonzini@gnu.org>
-	    WANG Yunfeng  <uhuruh@gmail.com>
-
-	* sed/execute.c (str_append, str_append_modified): Handle incomplete
-	sequences as if they were invalid.
----
- ChangeLog     |    6 ++++++
- NEWS          |    4 +++-
- sed/execute.c |    6 +++---
- 3 files changed, 12 insertions(+), 4 deletions(-)
-
-diff --git a/sed/execute.c b/sed/execute.c
-index 66cb809..d5903be 100644
---- a/sed/execute.c
-+++ b/sed/execute.c
-@@ -254,8 +254,8 @@ str_append(to, string, length)
-       {
-         size_t n = MBRLEN (string, length, &to->mbstate);
- 
--        /* An invalid sequence is treated like a singlebyte character. */
--        if (n == (size_t) -1)
-+        /* An invalid or imcomplete sequence is treated like a singlebyte character. */
-+        if (n == (size_t) -1 || n == (size_t) -2)
- 	  {
- 	    memset (&to->mbstate, 0, sizeof (to->mbstate));
- 	    n = 1;
-@@ -341,7 +341,7 @@ str_append_modified(to, string, length, type)
-       /* Copy the new wide character to the end of the string. */
-       n = WCRTOMB (to->active + to->length, wc, &to->mbstate);
-       to->length += n;
--      if (n == -1)
-+      if (n == -1 || n == -2)
- 	{
- 	  fprintf (stderr, "Case conversion produced an invalid character!");
- 	  abort ();
--- 
-1.7.3.1
-
diff --git a/sys-apps/sed/files/unix2dos b/sys-apps/sed/files/unix2dos
deleted file mode 100755
index 4902a7c..0000000
--- a/sys-apps/sed/files/unix2dos
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-exec sed -e 's/$//' "$@"
diff --git a/sys-apps/sed/sed-4.2.1-r1.ebuild b/sys-apps/sed/sed-4.2.2.ebuild
similarity index 60%
rename from sys-apps/sed/sed-4.2.1-r1.ebuild
rename to sys-apps/sed/sed-4.2.2.ebuild
index 7d7d453..1266bcc 100644
--- a/sys-apps/sed/sed-4.2.1-r1.ebuild
+++ b/sys-apps/sed/sed-4.2.2.ebuild
@@ -1,6 +1,8 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2016 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/sys-apps/sed/sed-4.2.1-r1.ebuild,v 1.12 2012/08/26 17:00:34 armin76 Exp $
+# $Id$
+
+EAPI=5
 
 inherit eutils flag-o-matic toolchain-funcs
 
@@ -14,7 +16,8 @@
 IUSE="acl nls selinux static"
 
 RDEPEND="acl? ( virtual/acl )
-	nls? ( virtual/libintl )"
+	nls? ( virtual/libintl )
+	selinux? ( sys-libs/libselinux )"
 DEPEND="${RDEPEND}
 	nls? ( sys-devel/gettext )"
 
@@ -30,41 +33,32 @@
 	fi
 }
 
-src_unpack() {
-	unpack ${A}
-	cd "${S}"
+src_prepare() {
 	epatch "${FILESDIR}"/${PN}-4.1.5-alloca.patch
-	epatch "${FILESDIR}"/${P}-handle-incomplete-sequences-as-if-they-were-invalid.patch #284403
-	# don't use sed here if we have to recover a broken host sed
-}
 
-src_compile() {
+	# don't use sed before bootstrap if we have to recover a broken host sed
 	src_bootstrap_sed
 	# this has to be after the bootstrap portion
 	sed -i \
 		-e '/docdir =/s:=.*/doc:= $(datadir)/doc/'${PF}'/html:' \
 		doc/Makefile.in || die "sed html doc"
+}
 
-	local myconf= bindir=/bin
-	if ! use userland_GNU ; then
-		myconf="--program-prefix=g"
-		bindir=/usr/bin
+src_configure() {
+	local myconf=()
+	if use userland_GNU; then
+		myconf+=( --exec-prefix="${EPREFIX}" )
+	else
+		myconf+=( --program-prefix=g )
 	fi
 
+	# Should be able to drop this hack in next release. #333887
+	tc-is-cross-compiler && export gl_cv_func_working_acl_get_file=yes
 	export ac_cv_search_setfilecon=$(usex selinux -lselinux)
 	export ac_cv_header_selinux_{context,selinux}_h=$(usex selinux)
 	use static && append-ldflags -static
 	econf \
-		--bindir=${bindir} \
 		$(use_enable acl) \
 		$(use_enable nls) \
-		${myconf}
-	emake || die "build failed"
-}
-
-src_install() {
-	emake install DESTDIR="${D}" || die "Install failed"
-	dodoc NEWS README* THANKS AUTHORS BUGS ChangeLog
-	docinto examples
-	dodoc "${FILESDIR}"/{dos2unix,unix2dos}
+		"${myconf[@]}"
 }