Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > F

fnmatch(3C)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

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 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 <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 (\) 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 */ ... } }

AUTHOR

fnmatch() was developed by OSF and HP.

STANDARDS CONFORMANCE

fnmatch(): XPG4, POSIX.2

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.