fnmatch.3c (2010 09)

f
fnmatch(3C) fnmatch(3C)
NAME
fnmatch( ) - match filename patterns
SYNOPSIS
#include <fnmatch.h>
int fnmatch(const char *pattern, const char *string, int flags);
DESCRIPTION
fnmatch() performs pattern matching as described in regexp (5) under PATTERN MATCHING NOTA-
TION. By default, the rule qualifications for filename expansion do not apply; i.e., periods (dots) and
slashes are matched as ordinary characters. This default behavior can be modified by using the flags
described below.
The flag argument modifies the interpretation of pattern and string .If
FNM_PATHNAME, which is
defined in <
fnmatch.h>, is set in flag, a slash character in string must be explicitly matched by a slash
in pattern; it cannot be matched by either the asterisk or question mark special characters or by a
bracket expression.
If
FNM_PERIOD is set in flag, a leading period (
.) must be explicitly matched. It will not be matched by
a bracket expression, question mark or asterisk. By default, a period is leading if it is the first character
in string. If
FNM_PATHNAME is set in flag, a period is leading if it is the first character in string or
immediately follows a slash.
If
FNM_NOESCAPE is not set in flag, a backslash character (\)inpattern followed by any other charac-
ter matches that second character in string . In particular,
\\ matches a backslash in string .If
FNM_NOESCAPE is set, a backslash character is treated as an ordinary character.
If flag is zero, the slash character and the period are treated as regular characters. If flag has any other
value, the result is undefined.
RETURN VALUE
If string matches the pattern specified by pattern ,
fnmatch() returns zero. Otherwise, fnmatch()
returns non-zero.
EXAMPLE
The following excerpt uses
fnmatch() to check each file in a directory against the pattern
*.c:
pattern = "*.c";
while(dp = readdir(dirp)){
if((fnmatch(pattern, dp->d_name,0)) == 0){
/* do processing for match */
...
}
}
AUTHOR
fnmatch() was developed by OSF and HP.
SEE ALSO
sh(1), glob(3C), thread_safety(5).
STANDARDS CONFORMANCE
fnmatch(): XPG4, POSIX.2
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (2 pages)