From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2615 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: REG_STARTEND (regex) Date: Tue, 15 Jan 2013 13:45:13 -0500 Message-ID: <20130115184513.GZ20323@brightrain.aerifal.cx> References: <20130115134244.GW20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1358275527 2116 80.91.229.3 (15 Jan 2013 18:45:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Jan 2013 18:45:27 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2616-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jan 15 19:45:45 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1TvBW3-0001dd-35 for gllmg-musl@plane.gmane.org; Tue, 15 Jan 2013 19:45:43 +0100 Original-Received: (qmail 13944 invoked by uid 550); 15 Jan 2013 18:45:25 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 13936 invoked from network); 15 Jan 2013 18:45:25 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2615 Archived-At: On Tue, Jan 15, 2013 at 04:16:29PM +0100, Daniel Cegiełka wrote: > Thank you for your reply. It's terribly sad that there are so many > problems with portability. There are a lot of high-quality tools in > the *BSD, which could be used in Linux. And rather than stick to the > POSIX people still create a barrier, like REG_STARTEND, 'sed -i', > bison (instead POSIX yacc), perl in the Makefile(!!!) etc. > > 'sed -i' is used in many programs (even linux, e2fsprogs, old libcap > etc.) and there is no chance to avoid it. So I'm looking for an > alternative to the gnu-sed+gnulib. I found that sed from FreeBSD has > support for -i and is much smaller than the gnu sed: > > http://svnweb.freebsd.org/base/release/9.1.0/usr.bin/sed/ > > ls -lh /bin/sed ./sed > -rwxr-xr-x 1 root root 143K Jun 22 2012 /bin/sed > -rwxr-xr-x 1 root root 35K Jan 15 14:32 ./sed > > (compiled on linux with glibc) > > Now I want to use it with musl, but sed (and grep) from FreeBSD uses > REG_STARTEND and I don't really know how to solve this problem. > > > http://svnweb.freebsd.org/base/release/9.1.0/usr.bin/sed/process.c?revision=243808&view=markup > > 651 /* Set anchors */ > 652 match[0].rm_so = 0; > 653 match[0].rm_eo = slen; > 654 > 655 eval = regexec(defpreg, string, > 656 nomatch ? 0 : maxnsub + 1, match, eflags | REG_STARTEND); > > > Does anyone have suggestions on how this can be modified to be able to > use it with musl. If the start position is 0, which it seems to be here, there's nothing to be done but removing REG_STARTEND. All it's doing is allowing you to process data with embedded nul bytes, which is not required by the standard or useful for any meaningful use of sed. Nobody will notice the difference with it missing unless they're trying to perform hideous hacks like patching binary files with sed... If the start position were not zero, you could compensate by just adding the start offset to the pointer you pass in, then adjusting all the match offsets after regexec returns. Rich