[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] Bug in listgroup?



Matthias Andree <ma@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> writes:

> Turns out we had most utility functions in place and reading a directory
> linearly should not be too expensive, please try this patch for
> LISTGROUP (do not copy & paste, but save the body of this article to a
> file and redirect patch's input) and let me know if it works - seems
> fine for me and is already committed to the DARCS repository (see
> <http://home.pages.de/~mandree/leafnode/beta/darcs/>):

...

On top of the previous patch, you'll need this for compliance with the
upcoming NNTP standard (draft 25 snapshot 5, backwards compatible with
RFC-2980):

Sun Jan  2 23:50:37 CET 2005  Matthias Andree <matthias.andree@xxxxxx>
  * sort numerically, not lexicographically.
--- leafnode-2-darcs-old/nntpd.c	2005-01-02 23:51:59.000000000 +0100
+++ leafnode-2-darcs-new/nntpd.c	2005-01-02 23:49:38.000000000 +0100
@@ -2012,10 +2012,15 @@ doxover(/*@null@*/ const struct newsgrou
     }
 }
 
-static int str_comp(const void *p1, const void *p2) {
+static int strnum_comp(const void *p1, const void *p2) {
     char *const *s1 = p1;
     char *const *s2 = p2;
-    return strcmp(*s1, *s2);
+    unsigned long u1, u2;
+    if (!get_ulong(*s1, &u1)) return 0;
+    if (!get_ulong(*s2, &u2)) return 0;
+    if (u1 == u2) return 0;
+    if (u1 < u2) return -1;
+    return 1;
 }
 
 static /*@null@*/ /*@dependent@*/ struct newsgroup *
@@ -2065,7 +2070,7 @@ dolistgroup(/*@null@*/ struct newsgroup 
 	char **t = dirlist(".", DIRLIST_ALLNUM, &ul), **i;
 	nntpprintf_as("211 Article list for %s follows", g->name);
 	if (t) {
-	    qsort(t, ul, sizeof(char *), str_comp);
+	    qsort(t, ul, sizeof(char *), strnum_comp);
 	    for (i = t; *i; i++)
 		nntpprintf_as("%s", *i);
 	    free_dirlist(t);



-- 
Matthias Andree
-- 
_______________________________________________
leafnode-list mailing list
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
http://www.dt.e-technik.uni-dortmund.de/mailman/listinfo/leafnode-list
http://leafnode.sourceforge.net/