diff options
Diffstat (limited to 'lib/filevercmp.c')
-rw-r--r-- | lib/filevercmp.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/filevercmp.c b/lib/filevercmp.c index d546e790548..7e54793e613 100644 --- a/lib/filevercmp.c +++ b/lib/filevercmp.c @@ -29,6 +29,8 @@ /* Return the length of a prefix of S that corresponds to the suffix defined by this extended regular expression in the C locale: (\.[A-Za-z~][A-Za-z0-9~]*)*$ + Use the longest suffix matching this regular expression, + except do not use all of S as a suffix if S is nonempty. If *LEN is -1, S is a string; set *LEN to S's length. Otherwise, *LEN should be nonnegative, S is a char array, and *LEN does not change. */ @@ -36,20 +38,22 @@ static idx_t file_prefixlen (char const *s, ptrdiff_t *len) { size_t n = *len; /* SIZE_MAX if N == -1. */ + idx_t prefixlen = 0; - for (idx_t i = 0; ; i++) + for (idx_t i = 0; ; ) { - idx_t prefixlen = i; - while (i + 1 < n && s[i] == '.' && (c_isalpha (s[i + 1]) - || s[i + 1] == '~')) - for (i += 2; i < n && (c_isalnum (s[i]) || s[i] == '~'); i++) - continue; - if (*len < 0 ? !s[i] : i == n) { *len = i; return prefixlen; } + + i++; + prefixlen = i; + while (i + 1 < n && s[i] == '.' && (c_isalpha (s[i + 1]) + || s[i + 1] == '~')) + for (i += 2; i < n && (c_isalnum (s[i]) || s[i] == '~'); i++) + continue; } } |