X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffilevercmp.c;h=cb7c25cb89d29a506283bbede2b5dabde5420f14;hb=f4c549fab688ce822556eadcf60fdda5042ade11;hp=99c07db9cc83398fc0b2b14c661f29db9e73c4fc;hpb=1721cf06d9f23949a7a2ed6aec7615f8f5731be4;p=gnulib.git diff --git a/lib/filevercmp.c b/lib/filevercmp.c index 99c07db9c..cb7c25cb8 100644 --- a/lib/filevercmp.c +++ b/lib/filevercmp.c @@ -1,7 +1,7 @@ /* Copyright (C) 1995 Ian Jackson Copyright (C) 2001 Anthony Towns - Copyright (C) 2008-2009 Free Software Foundation, Inc. + Copyright (C) 2008-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -89,32 +89,32 @@ verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len) { int first_diff = 0; while ((s1_pos < s1_len && !c_isdigit (s1[s1_pos])) - || (s2_pos < s2_len && !c_isdigit (s2[s2_pos]))) - { - int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]); - int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]); - if (s1_c != s2_c) - return s1_c - s2_c; - s1_pos++; - s2_pos++; - } + || (s2_pos < s2_len && !c_isdigit (s2[s2_pos]))) + { + int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]); + int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]); + if (s1_c != s2_c) + return s1_c - s2_c; + s1_pos++; + s2_pos++; + } while (s1[s1_pos] == '0') - s1_pos++; + s1_pos++; while (s2[s2_pos] == '0') - s2_pos++; + s2_pos++; while (c_isdigit (s1[s1_pos]) && c_isdigit (s2[s2_pos])) - { - if (!first_diff) - first_diff = s1[s1_pos] - s2[s2_pos]; - s1_pos++; - s2_pos++; - } + { + if (!first_diff) + first_diff = s1[s1_pos] - s2[s2_pos]; + s1_pos++; + s2_pos++; + } if (c_isdigit (s1[s1_pos])) - return 1; + return 1; if (c_isdigit (s2[s2_pos])) - return -1; + return -1; if (first_diff) - return first_diff; + return first_diff; } return 0; } @@ -135,11 +135,27 @@ filevercmp (const char *s1, const char *s2) if (simple_cmp == 0) return 0; - /* handle hidden files */ - while (*s1 == '.' || *s2 == '.') + /* special handle for "", "." and ".." */ + if (!*s1) + return -1; + if (!*s2) + return 1; + if (0 == strcmp (".", s1)) + return -1; + if (0 == strcmp (".", s2)) + return 1; + if (0 == strcmp ("..", s1)) + return -1; + if (0 == strcmp ("..", s2)) + return 1; + + /* special handle for other hidden files */ + if (*s1 == '.' && *s2 != '.') + return -1; + if (*s1 != '.' && *s2 == '.') + return 1; + if (*s1 == '.' && *s2 == '.') { - if (*s1 != *s2) - return *s1 - *s2; s1++; s2++; }