Go to the first, previous, next, last section, table of contents.


fnmatch

Syntax

#include <fnmatch.h>

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

Description

This function indicates if string matches the pattern. The pattern may include the following special characters:

*
Matches zero of more characters.
?
Matches exactly one character
[...]
Matches one character if it's in a range of characters. If the first character is !, matches if the character is not in the range. Between the brackets, the range is specified by listing the characters that are in the range, or two characters separated by - to indicate all characters in that range. For example, [a-d] matches a, b, c, or d.
\
Causes the next character to not be treated as a wildcard. For example, \* matches an asterisk. This is only available if flags includes FNM_QUOTE.

The value of flags is a combination of zero of more of the following:

FNM_PATHNAME
This means that the string should be treated as a pathname, in that the slash character / never matches any of the wildcards.
FNM_QUOTE
This means that the backslash \\ may be used for quoting special characters in the pattern.

Return Value

Zero if the string matches, FNM_NOMATCH if it does not.

Portability

not ANSI, POSIX

Example

if (fnmatch("*.[ch]", filename, FNM_PATH|FNM_QUOTE))
  do_source_file(filename);


Go to the first, previous, next, last section, table of contents.