From: Kamil Dudka Date: Thu, 5 Mar 2009 21:56:29 +0000 (+0100) Subject: filevercmp: Move hidden files up in ordering. X-Git-Tag: v0.1~6220 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=0443c2f39943017f0aaa0afacbf68fb725858963;p=gnulib.git filevercmp: Move hidden files up in ordering. --- diff --git a/ChangeLog b/ChangeLog index 903ff80bf..795c34fdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-03-05 Kamil Dudka + + * lib/filevercmp.c: Move hidden files up in ordering. + * tests/test-filevercmp.c: Add tests for hidden files. + 2009-03-04 Bruno Haible * modules/visibility (Makefile.am): Augment AM_CFLAGS. diff --git a/NEWS b/NEWS index bf48451f5..17e241fea 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ User visible incompatible changes Date Modules Changes +2009-03-05 filevercmp Move hidden files up in ordering. + 2009-01-22 c-strtod This function no longer calls xalloc_die(). If c-strtold you want to exit the program in case of out-of- memory, the calling function needs to arrange diff --git a/lib/filevercmp.c b/lib/filevercmp.c index 856f30ff0..7b40c98f7 100644 --- a/lib/filevercmp.c +++ b/lib/filevercmp.c @@ -124,8 +124,8 @@ verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len) int filevercmp (const char *s1, const char *s2) { - const char *s1_pos = s1; - const char *s2_pos = s2; + const char *s1_pos; + const char *s2_pos; const char *s1_suffix, *s2_suffix; size_t s1_len, s2_len; int result; @@ -135,7 +135,18 @@ filevercmp (const char *s1, const char *s2) if (simple_cmp == 0) return 0; + /* handle hidden files */ + while (*s1 == '.' || *s2 == '.') + { + if (*s1 != *s2) + return *s1 - *s2; + s1++; + s2++; + } + /* "cut" file suffixes */ + s1_pos = s1; + s2_pos = s2; s1_suffix = match_suffix (&s1_pos); s2_suffix = match_suffix (&s2_pos); s1_len = (s1_suffix ? s1_suffix : s1_pos) - s1; diff --git a/tests/test-filevercmp.c b/tests/test-filevercmp.c index 4efd108eb..fe54dc2f1 100644 --- a/tests/test-filevercmp.c +++ b/tests/test-filevercmp.c @@ -37,6 +37,16 @@ /* set of well sorted examples */ static const char *const examples[] = { + ".", + "..", + ".a~", + ".a", + ".b~", + ".b", + "a~", + "a", + "b~", + "b", "gcc-c++-10.fc9.tar.gz", "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2", "glibc-2-0.1.beta1.fc10.rpm",