mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] Fix strverscmp
@ 2012-12-05 19:09 Isaac Dunham
  2012-12-05 19:35 ` Rich Felker
  0 siblings, 1 reply; 10+ messages in thread
From: Isaac Dunham @ 2012-12-05 19:09 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 325 bytes --]

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 <idunham@lavabit.com>

[-- Attachment #2: strverscmp.diff --]
[-- Type: text/x-diff, Size: 1327 bytes --]

commit 21b9e883f440de900764a2e4077752268724c4db
Author: Isaac Dunham <idunham@lavabit.com>
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 <string.h>
 
 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;
 }

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-12-07  0:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-05 19:09 [PATCH] Fix strverscmp Isaac Dunham
2012-12-05 19:35 ` Rich Felker
2012-12-06  0:43   ` Isaac Dunham
2012-12-06  1:00     ` Rich Felker
2012-12-06  2:14       ` Rich Felker
2012-12-06  2:21       ` Isaac Dunham
2012-12-06  2:26         ` Rich Felker
2012-12-06  3:18           ` Isaac Dunham
2012-12-06  4:14             ` Rich Felker
2012-12-07  0:36               ` Isaac Dunham

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).