From a8dae2e4869837ced185b7890a390c10992901d0 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 26 Jan 2000 03:47:33 +0000 Subject: [PATCH] Fix problem with FNM_LEADING_DIR. --- posix/fnmatch.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/posix/fnmatch.c b/posix/fnmatch.c index dc4021ef0de..82e2c2cd44c 100644 --- a/posix/fnmatch.c +++ b/posix/fnmatch.c @@ -204,9 +204,31 @@ internal_fnmatch (const char *pattern, const char *string, if (c == '\0') /* The wildcard(s) is/are the last element of the pattern. If the name is a file name and contains another slash - this does mean it cannot match. */ - return ((flags & FNM_FILE_NAME) && strchr (n, '/') != NULL - ? FNM_NOMATCH : 0); + this does mean it cannot match. If the FNM_LEADING_DIR + flag is set and exactly one slash is following, we have + a match. */ + { + int result = (flags & FNM_FILE_NAME) == 0 ? 0 : FNM_NOMATCH; + + if (flags & FNM_FILE_NAME) + { + const CHAR *slashp = STRCHR (n, L('/')); + + if (flags & FNM_LEADING_DIR) + { + if (slashp != NULL + && STRCHR (slashp + 1, L('/')) == NULL) + result = 0; + } + else + { + if (slashp == NULL) + result = 0; + } + } + + return result; + } else { const char *endp; -- 2.47.2