From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2413 Path: news.gmane.org!not-for-mail From: Isaac Dunham Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] Fix strverscmp Date: Wed, 5 Dec 2012 11:09:59 -0800 Message-ID: <20121205110959.87b6111a.idunham@lavabit.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Wed__5_Dec_2012_11_09_59_-0800_rM2+rDOxPfQqdEKE" X-Trace: ger.gmane.org 1354734620 22113 80.91.229.3 (5 Dec 2012 19:10:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Dec 2012 19:10:20 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2414-gllmg-musl=m.gmane.org@lists.openwall.com Wed Dec 05 20:10:31 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 1TgKMS-0001Pe-Cw for gllmg-musl@plane.gmane.org; Wed, 05 Dec 2012 20:10:24 +0100 Original-Received: (qmail 26392 invoked by uid 550); 5 Dec 2012 19:10:12 -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 26384 invoked from network); 5 Dec 2012 19:10:11 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=lavabit; d=lavabit.com; b=p5zZfy6AzYFlFsfl1hZtns9VV09kGYd2Oall4Y+s4GsiC1UWXsL+LIOVQDB/k05M6Gc+S30TInVjWTY0OV01my9MgJ1kHNbD1iz/ZHRno+X7bNiy0j0/URyS0fIT7cnrSf+K7WcmWgBjHjiSwBN02UdEW951sTr+3c0ctHdXqgA=; h=Date:From:To:Subject:Message-Id:X-Mailer:Mime-Version:Content-Type; X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; i486-pc-linux-gnu) Xref: news.gmane.org gmane.linux.lib.musl.general:2413 Archived-At: This is a multi-part message in MIME format. --Multipart=_Wed__5_Dec_2012_11_09_59_-0800_rM2+rDOxPfQqdEKE Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On the Puppy Linux forums, technosaurus mentioned that musl's strverscmp implementation was broken; he has a small version of strverscmp that works properly, which he placed under a CC0-like license. This patch changes strverscmp to use his version. Results are comparable to glibc. -- Isaac Dunham --Multipart=_Wed__5_Dec_2012_11_09_59_-0800_rM2+rDOxPfQqdEKE Content-Type: text/x-diff; name="strverscmp.diff" Content-Disposition: attachment; filename="strverscmp.diff" Content-Transfer-Encoding: 7bit commit 21b9e883f440de900764a2e4077752268724c4db Author: Isaac Dunham Date: Wed Dec 5 10:48:33 2012 -0800 Fix strverscmp. The original version used strcmp, resulting in incorrect sorting order. This version, based on a version Brad Conroy (technosaurus) published, behaves similarly to the glibc version. diff --git a/src/string/strverscmp.c b/src/string/strverscmp.c index 7054967..bab3e64 100644 --- a/src/string/strverscmp.c +++ b/src/string/strverscmp.c @@ -1,7 +1,27 @@ +/* + * Based on an implementation by Brad Conroy (technosaurus) + * published on the Puppy Linux forums. + * + * This work is released to the Public Domain. + * In locales that do not recognize public domain it is: + * Copyright Brad Conroy 2012, permission is hereby granted to use this work in + * accordance with any license approved by the Open Source Initiative for any + * purpose without restriction in perpetuity. + */ #include int strverscmp(const char *l, const char *r) { - /* FIXME */ - return strcmp(l, r); + int ret=0, buf=0; + while ( *l && *r && l[0]==r[0] ) { + l++; + r++; + } + do { + ret=(10 * ret) + l++[0] - '0'; + } while ( '0' <= l[0] && l[0] <= '9') ; + do { + buf=(10 * buf) + r++[0] - '0'; + } while ( '0' <= r[0] && r[0] <= '9'); + return ret - buf; } --Multipart=_Wed__5_Dec_2012_11_09_59_-0800_rM2+rDOxPfQqdEKE--