From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2525 Path: news.gmane.org!not-for-mail From: Isaac Dunham Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] Re: strverscmp (Was: Re: lshw FTBFS: res_querydomain...) Date: Mon, 31 Dec 2012 12:49:52 -0800 Message-ID: <20121231124952.87eaca31.idunham@lavabit.com> References: <20121230215931.cf9ff1d0.idunham@lavabit.com> <20121231124418.GD4468@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Mon__31_Dec_2012_12_49_52_-0800_gftVeYTbDlK7kl6B" X-Trace: ger.gmane.org 1356987005 28579 80.91.229.3 (31 Dec 2012 20:50:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 31 Dec 2012 20:50:05 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2526-gllmg-musl=m.gmane.org@lists.openwall.com Mon Dec 31 21:50:21 2012 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 1TpmJR-0006py-6K for gllmg-musl@plane.gmane.org; Mon, 31 Dec 2012 21:50:21 +0100 Original-Received: (qmail 3153 invoked by uid 550); 31 Dec 2012 20:50:06 -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 3145 invoked from network); 31 Dec 2012 20:50:05 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=lavabit; d=lavabit.com; b=jSNztHXwgQ0OVD7FbZpl9ft2Of3EQnb4ufGgQmTsuhnF7gKtjB/BH9ozBDUY4bpzmffqJMeBV8pWaE1T0H/faKK0Pi0vHG2z927WOuvtAi5/qI/GeWSi0OdS7qHLSDpsxOhYF7bw3kkSIUdF2ssxGnt33c35RkF+R5hQKJaMcMY=; h=Date:From:To:Subject:Message-Id:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type; In-Reply-To: <20121231124418.GD4468@port70.net> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; i486-pc-linux-gnu) Xref: news.gmane.org gmane.linux.lib.musl.general:2525 Archived-At: This is a multi-part message in MIME format. --Multipart=_Mon__31_Dec_2012_12_49_52_-0800_gftVeYTbDlK7kl6B Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 31 Dec 2012 13:44:18 +0100 Szabolcs Nagy wrote: > > * Isaac Dunham [2012-12-30 21:59:31 -0800]: > > Currently, I've got a very hackish implementation that isn't fit to ship: > > btw, what happened with strverscmp I had been waiting untill someone commented one way or the other on the last version of the standalone test version I sent. But here's the patch. -- Isaac Dunham --Multipart=_Mon__31_Dec_2012_12_49_52_-0800_gftVeYTbDlK7kl6B Content-Type: text/x-diff; name="strverscmp.diff" Content-Disposition: attachment; filename="strverscmp.diff" Content-Transfer-Encoding: 7bit commit ddf8e4a8099535b61fa7baaa7fae35e18ccf24ae Author: Isaac Dunham Date: Mon Dec 31 12:38:36 2012 -0800 Fix strverscmp. Disagrees with glibc by saying that 00 < 009, but that's a GNU bug. diff --git a/src/string/strverscmp.c b/src/string/strverscmp.c index 7054967..8f3f11f 100644 --- a/src/string/strverscmp.c +++ b/src/string/strverscmp.c @@ -1,7 +1,41 @@ +#define _GNU_SOURCE +#include #include int strverscmp(const char *l, const char *r) { - /* FIXME */ - return strcmp(l, r); + int haszero=1; + while (*l && *r && l[0]==r[0]){ + if (l[0]=='0'){ + if (haszero==1) { + haszero=0; + } + } else if (isdigit(l[0])) { + if (haszero==1) { + haszero=2; + } + } else { + haszero=1; + } + l++; r++; + } + if (haszero==1 && (l[0]=='0' || r[0]=='0')) { + haszero=0; + } + if ((isdigit(l[0]) && isdigit(r[0]) ) && haszero) { + int lenl=0, lenr=0, firstl=l[0], firstr=r[0]; + while (isdigit(l++[0]) ) { + lenl++; + } + while (isdigit(r++[0]) ) { + lenr++; + } + if (lenl==lenr) { + return (firstl - firstr); + } else { + return (lenl - lenr); + } + } else { + return (l[0] - r[0]); + } } --Multipart=_Mon__31_Dec_2012_12_49_52_-0800_gftVeYTbDlK7kl6B--