@c ---------------------------------------------------------------------- @node fnmatch, file system @subheading Syntax @example #include int fnmatch(const char *pattern, const char *string, int flags); @end example @subheading Description This function indicates if @var{string} matches the @var{pattern}. The @var{pattern} may include the following special characters: @table @code @item * Matches zero of more characters. @item ? Matches exactly one character. @item [...] Matches one character if it's in a range of characters. If the first character is @samp{!}, 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 @samp{-} to indicate all characters in that range. For example, @samp{[a-d]} matches @samp{a}, @samp{b}, @samp{c}, or @samp{d}. If you want to include the literal @samp{-} in the range, make it the first character, like in @samp{[-afz]}. @item \ Causes the next character to not be treated as a wildcard. For example, @samp{\*} matches an asterisk. This feature is not available if @var{flags} includes @code{FNM_NOESCAPE}, in which case @samp{\} is treated as a directory separator. @end table The value of @var{flags} is a combination of zero of more of the following: @table @code @item FNM_PATHNAME This means that the @var{string} should be treated as a pathname, in that the slash characters @samp{/} and @samp{\} in @var{string} never match any of the wildcards in @var{pattern}. @item FNM_NOESCAPE If this flag is @strong{not} set, the backslash @samp{\} may be used in @var{pattern} for quoting special characters. If this flag @strong{is} set, @samp{\} is treated as a directory separator. @item FNM_NOCASE If this flag is set, @code{fnmatch} matches characters case-insensitively, including in character ranges like @code{[a-f]}. Note that the case-folding is done by calling @code{toupper} (@pxref{toupper}), and thus might be sensitive to the current locale. @item FNM_PERIOD This flag is accepted and ignored in the current implementation. (This is the right thing to do on non-LFN platforms, where leading dots in file names are forbidden.) In the Posix specification, if this flag is set, leading dots in file names will not match any wildcards. If @code{FNM_PATHNAME} is set, a dot after a slash also doesn't match any wildcards. @end table The DJGPP implementation treats forward slashes and backslashes as equal when @code{FNM_NOESCAPE} is set, since on DOS/Windows these two characters are both used as directory separators in file names. @subheading Return Value Zero if the string matches, @code{FNM_NOMATCH} if it does not. Posix defines an additional @code{FNM_ERROR} code that's returned in case of an error, but the current implementation never returns it. @subheading Portability @port-note posix The equal handling of @samp{\} and @samp{/} is DJGPP-specific. @portability !ansi, posix @subheading Example @example if (fnmatch("*.[ch]", filename, FNM_PATHNAME|FNM_NOCASE)) do_source_file(filename); @end example