www.delorie.com/djgpp/doc/libc/libc_334.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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'. If you want to include the literal `-' in the range, make it the first character, like in `[-afz]'.

\

Causes the next character to not be treated as a wildcard. For example, `\*' matches an asterisk. This feature is not available if flags includes FNM_NOESCAPE, in which case `\' is treated as a directory separator.

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 characters `/' and `\' in string never match any of the wildcards in pattern.

FNM_NOESCAPE

If this flag is not set, the backslash `\' may be used in pattern for quoting special characters. If this flag is set, `\' is treated as a directory separator.

FNM_NOCASE

If this flag is set, fnmatch matches characters case-insensitively, including in character ranges like [a-f]. Note that the case-folding is done by calling toupper (see section toupper), and thus might be sensitive to the current locale.

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 FNM_PATHNAME is set, a dot after a slash also doesn't match any wildcards.

The DJGPP implementation treats forward slashes and backslashes as equal when FNM_NOESCAPE is set, since on DOS/Windows these two characters are both used as directory separators in file names.

Return Value

Zero if the string matches, FNM_NOMATCH if it does not. Posix defines an additional FNM_ERROR code that's returned in case of an error, but the current implementation never returns it.

Portability

ANSI/ISO C No
POSIX 1003.2-1992; 1003.1-2001 (see note 1)

Notes:

  1. The equal handling of `\' and `/' is DJGPP-specific.

Example

 
if (fnmatch("*.[ch]", filename, FNM_PATHNAME|FNM_NOCASE))
  do_source_file(filename);


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2004   by DJ Delorie     Updated Apr 2004