fnmatch




 fnmatch(3C)                                                     fnmatch(3C)




NAME

fnmatch() - match filename patterns

SYNOPSIS

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

DESCRIPTION

fnmatch() performs pattern matching as described in regexp(5) under PATTERN MATCHING NOTATION. 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 , 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 (\) in pattern followed by any other character 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 */ Hewlett-Packard Company - 1 - HP-UX Release 10.20: July 1996 fnmatch(3C) fnmatch(3C) ... } }

AUTHOR

fnmatch() was developed by OSF and HP.

SEE ALSO

sh(1), glob(3c). STANDARDS CONFORMANCE fnmatch(): XPG4, POSIX.2 Hewlett-Packard Company - 2 - HP-UX Release 10.20: July 1996