From: Isaac Dunham <idunham@lavabit.com>
To: musl@lists.openwall.com
Subject: [PATCH] Re: strverscmp (Was: Re: lshw FTBFS: res_querydomain...)
Date: Mon, 31 Dec 2012 12:49:52 -0800 [thread overview]
Message-ID: <20121231124952.87eaca31.idunham@lavabit.com> (raw)
In-Reply-To: <20121231124418.GD4468@port70.net>
[-- Attachment #1: Type: text/plain, Size: 450 bytes --]
On Mon, 31 Dec 2012 13:44:18 +0100
Szabolcs Nagy <nsz@port70.net> wrote:
>
> * Isaac Dunham <idunham@lavabit.com> [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 <idunham@lavabit.com>
[-- Attachment #2: strverscmp.diff --]
[-- Type: text/x-diff, Size: 1189 bytes --]
commit ddf8e4a8099535b61fa7baaa7fae35e18ccf24ae
Author: Isaac Dunham <idunham@lavabit.com>
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 <ctype.h>
#include <string.h>
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]);
+ }
}
next prev parent reply other threads:[~2012-12-31 20:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-31 5:59 lshw FTBFS: res_querydomain declared but not implemented Isaac Dunham
2012-12-31 12:44 ` Szabolcs Nagy
2012-12-31 20:49 ` Isaac Dunham [this message]
2012-12-31 18:06 ` Rich Felker
2012-12-31 20:03 ` Isaac Dunham
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=20121231124952.87eaca31.idunham@lavabit.com \
--to=idunham@lavabit.com \
--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).