Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fnmatch - match a filename string or a pathname

&pagelevel(4)&pagelevel

Syntax

#include <fnmatch.h>

int fnmatch(const char *pattern, const char *string, int flags);

Description

The fnmatch() function matches patterns as described in XCU Patterns Matching a Single Character and Patterns Matching Multiple Characters . It checks the string specified by the string argument to see if it matches the pattern specified by the pattern argument.

The flags argument modifies the interpretation of pattern and string. It is the bitwise-inclusive OR of zero or more of the flags , which are defined in the header regex.h:

FNM_NOESCAPE

Disable backslash escaping.

FNM_PATHNAME

'/' in string only matches '/' in pattern.

FNM_PERIOD

Leading '.' in string must be exactly matched by period in pattern.

Extension

FNM_RANGEOK

[m-n-r] matches range m-r.

FNM_RANGE_ERR

[m-n-r] returns error.

FNM_CLRANGE_ERR

[[=m=]-r] causes error; otherwise, '-' is an ordinary character (End)

If the FNM_PATHNAME flag is set in flags, '/'  character in string is only matched explicitly by one or more '/' in pattern; it is not be matched by either the '*' or '?' special characters, nor by a bracket expression.
If a '/' character is found following an unescaped '[' character before a corresponding ']' is found, the open bracket is treated as an ordinary character. For example, the pattern "a[b/c]d" does not match strings as "abd" or "a/d". It only matches a pathname of literally "a[b/c]d".
If the FNM_PATHNAME flag is not set, the '/' character is treated as an ordinary character.

If FNM_NOESCAPE is not set in flags, a '\' character in pattern followed by any other character matches that second character in string. In particular, "\\" in pattern matches '\' in string. If pattern ends with an unescaped '\', fnmatch() returns FNM_BADPAT.
If FNM_NOESCAPE is set in flags, a '\' character is treated as an ordinary character.

If FNM_PERIOD is set in flags, then a leading '.'  in string is explicitly matched by a leading '.' in patternit is not be matched by either the '*' or '?' special characters, nor by a bracket expression.

The location of "leading" is indicated by the value of FNM_PATHNAME:

  • If FNM_PATHNAME is set, '.' is "leading" if it is the first character in string or pattern or if it immediately follows a '/'.

  • If FNM_PATHNAME is not set, '.' is "leading" only if it is the first character of string or pattern.

If FNM_PERIOD is not set, then no special restrictions are placed on matching a period.

Return val.

0

if successful.


value indicating an error as described in fnmatch.h:


FNM_NOMATCH

if no match has been found


FNM_BADPAT

flag or pattern invalid.

Errors

fnmatch() will fail if:

Extension


EINVAL

invalid flag specified (End)

See also

glob().