mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: REG_STARTEND (regex)
Date: Tue, 15 Jan 2013 13:45:13 -0500	[thread overview]
Message-ID: <20130115184513.GZ20323@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAPLrYER-QsrVgYvgwf97e8XzoR9s3ifvyhYj-3tWOqk0JO_avA@mail.gmail.com>

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


  parent reply	other threads:[~2013-01-15 18:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15 10:34 Daniel Cegiełka
2013-01-15 13:42 ` Rich Felker
2013-01-15 15:16   ` Daniel Cegiełka
2013-01-15 15:37     ` John Spencer
2013-01-15 15:50       ` Daniel Cegiełka
2013-01-15 16:13         ` Rob Landley
2013-01-15 18:38         ` John Spencer
2013-01-16 15:41           ` Rob Landley
2013-01-15 16:11     ` Rob Landley
2013-01-15 18:45     ` Rich Felker [this message]
2013-01-15 18:55       ` Daniel Cegiełka
2013-01-16 15:42       ` Rob Landley
2013-01-16 16:57         ` Rich Felker
2014-06-11 14:24     ` Justin Cormack
2014-06-12  1:00       ` bfdamkoehler
2014-06-12  1:40         ` Rich Felker
2014-06-13  1:15           ` bfdamkoehler
2014-06-13  3:00             ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130115184513.GZ20323@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).