pattern.c File Reference
#include <winpr/config.h>
#include <winpr/crt.h>
#include <winpr/handle.h>
#include <winpr/file.h>
#include "../log.h"


#define TAG   WINPR_TAG("file")


LPSTR FilePatternFindNextWildcardA (LPCSTR lpPattern, DWORD *pFlags)
static BOOL FilePatternMatchSubExpressionA (LPCSTR lpFileName, size_t cchFileName, LPCSTR lpX, size_t cchX, LPCSTR lpY, size_t cchY, LPCSTR lpWildcard, LPCSTR *ppMatchEnd)
BOOL FilePatternMatchA (LPCSTR lpFileName, LPCSTR lpPattern)

Macro Definition Documentation


#define TAG   WINPR_TAG("file")

WinPR: Windows Portable Runtime File Functions

Copyright 2012 Marc-Andre Moreau

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ FilePatternFindNextWildcardA()

LPSTR FilePatternFindNextWildcardA ( LPCSTR  lpPattern,
DWORD *  pFlags 

File System Behavior in the Microsoft Windows Environment:

Here is the caller graph for this function:

◆ FilePatternMatchA()

BOOL FilePatternMatchA ( LPCSTR  lpFileName,
LPCSTR  lpPattern 

Wild Card Matching

'*' matches 0 or more characters '?' matches exactly one character

'~*' DOS_STAR - matches 0 or more characters until encountering and matching final '.'

'~?' DOS_QM - matches any single character, or upon encountering a period or end of name string, advances the expresssion to the end of the set of contiguous DOS_QMs.

'~.' DOS_DOT - matches either a '.' or zero characters beyond name string.

First and foremost the file system starts off name matching with the expression “*”. If the expression contains a single wild card character ‘*’ all matches are satisfied immediately. This is the most common wild card character used in Windows and expression evaluation is optimized by looking for this character first.

Subsequently evaluation of the “*X” expression is performed. This is a case where the expression starts off with a wild card character and contains some non-wild card characters towards the tail end of the name. This is evaluated by making sure the expression starts off with the character ‘*’ and does not contain any wildcards in the latter part of the expression. The tail part of the expression beyond the first character ‘*’ is matched against the file name at the end uppercasing each character if necessary during the comparison.

The remaining expressions are evaluated in a non deterministic finite order as listed below, where:

'S' is any single character 'S-.' is any single character except the final '.' 'e' is a null character transition 'EOF' is the end of the name string

                 X  |     |  e       Y

X * Y == (0)--—>-(1)->--—(2)--—(3)

                 X  |     |  e       Y

X ~* Y == (0)--—>-(1)->--—(2)--—(3)

                X     S     S     Y

X ?? Y == (0)—(1)—(2)—(3)—(4)

                X     S-.     S-.     Y

X ~?~? == (0)—(1)--—(2)--—(3)—(4) | |_______| | ^ | |_______________| ^EOF of .^

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FilePatternMatchSubExpressionA()

static BOOL FilePatternMatchSubExpressionA ( LPCSTR  lpFileName,
size_t  cchFileName,
size_t  cchX,
size_t  cchY,
LPCSTR  lpWildcard,
LPCSTR *  ppMatchEnd 

State 2: match Y

State 3: final state

                X     S     Y

X ? Y == (0)—(1)—(2)—(3)

State 2: match Y

State 3: final state

Here is the call graph for this function:
Here is the caller graph for this function: