X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffilevercmp.c;h=20522d1c4c387ae9b505ad8156b75d2a92a206ed;hb=31d3154399f8c679ba23afb0f6bef03b73d4c741;hp=7b40c98f7bff874f50b2b097749efe6447975d02;hpb=0443c2f39943017f0aaa0afacbf68fb725858963;p=gnulib.git diff --git a/lib/filevercmp.c b/lib/filevercmp.c index 7b40c98f7..20522d1c4 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 Free Software Foundation, Inc. + Copyright (C) 2008-2009 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 @@ -27,7 +27,7 @@ #include /* Match a file suffix defined by this regular expression: - /(\.[A-Za-z][A-Za-z0-9]*)*$/ + /(\.[A-Za-z~][A-Za-z0-9~]*)*$/ Scan the string *STR and return a pointer to the matching suffix, or NULL if not found. Upon return, *STR points to terminating NUL. */ static const char * @@ -40,7 +40,7 @@ match_suffix (const char **str) if (read_alpha) { read_alpha = false; - if (!c_isalpha (**str)) + if (!c_isalpha (**str) && '~' != **str) match = NULL; } else if ('.' == **str) @@ -49,7 +49,7 @@ match_suffix (const char **str) if (!match) match = *str; } - else if (!c_isalnum (**str)) + else if (!c_isalnum (**str) && '~' != **str) match = NULL; (*str)++; } @@ -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++; }