From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2617 Path: news.gmane.org!not-for-mail From: =?ISO-8859-2?Q?Daniel_Cegie=B3ka?= Newsgroups: gmane.linux.lib.musl.general Subject: Re: REG_STARTEND (regex) Date: Tue, 15 Jan 2013 19:55:23 +0100 Message-ID: References: <20130115134244.GW20323@brightrain.aerifal.cx> <20130115184513.GZ20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1358276155 8685 80.91.229.3 (15 Jan 2013 18:55:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Jan 2013 18:55:55 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2618-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jan 15 19:56:13 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 1TvBgB-0000lA-Rl for gllmg-musl@plane.gmane.org; Tue, 15 Jan 2013 19:56:12 +0100 Original-Received: (qmail 18256 invoked by uid 550); 15 Jan 2013 18:55:55 -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 18248 invoked from network); 15 Jan 2013 18:55:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=vihaSG1M8CEgdGHnW5Coelcb0G0AbYvjyO5Pv8r0HPY=; b=x2SeFNLRE81Ttf2Jfav2wNFkcPaoezP6NZF7oYBxS6TJt3tsWIhh9fLwVrjD/+3BP1 JIyRnvhqlxB66lMYRI5c9sJfqqMRMt5u1Ikz9qv3rZFQMCoYlDwf0CgB1nS6Wg59/lhy 9GTv+09trqjflQvHICvCDzyWY8DGBK8+YXxyqQISI1HLK2Tcu1kQ7/s58uIXMGgNiQA6 bMIXQFbrXuBOU8yxZWC0KgjHmbwFJ3Y0GHu8fhOxs/Bnt3d5in673M93B4KN6lpDVkVP dE4JnmK21OmrobwgB4jD5x00VvdCwODSqb8bqkz3Bqv8e1qbaQavP8iseQF2n95hc5pn hTHQ== In-Reply-To: <20130115184513.GZ20323@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:2617 Archived-At: 2013/1/15 Rich Felker > 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. > thx Rich, I found a similar solution in a 'file' package: else { regmatch_t pmatch[1]; #ifndef REG_STARTEND #define REG_STARTEND 0 size_t l = ms->search.s_len - 1; char c = ms->search.s[l]; ((char *)(intptr_t)ms->search.s)[l] = '\0'; #else pmatch[0].rm_so = 0; pmatch[0].rm_eo = ms->search.s_len; #endif rc = regexec(&rx, (const char *)ms->search.s, 1, pmatch, REG_STARTEND); #if REG_STARTEND == 0 ((char *)(intptr_t)ms->search.s)[l] = c; #endif switch (rc) { case 0: https://raw.github.com/glensc/file/master/src/softmagic.c Best regards, Daniel