fnmatch

Matches a filename or a pathname.

Library:LibC
Classification:Single UNIX
Service:File and Directory I/O

Syntax

  #include <fnmatch.h> 
   
  int fnmatch (
     const char   *pattern,
     const char   *string,
     int           flags);
  

Parameters

pattern

(IN) Points to a string with the wildcard pattern to match.

string

(IN) Points to the string to see if it matches the specified pattern.

flags

(IN) Specifies how to perform the match, using the following flags which can be ORed:

Flag

Value

Description

FNM_NOSYS

0x01

Not currently used.

FNM_PATHNAME FNM_FILE_NAME

0x02

Indicates that the slash in the string must match an explicit slash in the pattern. It will not be matched by either the asterisk or the question mark.

FNM_PERIOD

0x04

Indicates whether a leading period in string matches a period in pattern. The meaning of leading period depends on whether FNM_PATHNAME is also set:

  • When FNM_PATHNAME is set, a period is leading if it is the first character in the string or if it immediately follows a slash.

  • When FNM_PATHNAME is not set, a period is leading only if it is the first character in the string.

FNM_NOESCAPE

0x08

Indicates that the backslash (\) should not be treated as an escape sequence, but as an ordinary character. For example,

  • When set, \? is matched as backslash and wildcard for a single character.

  • When not set, \? is matched as a question mark.

FNM_CASEFOLD

0x10

Indicates that the match should ignore case. This is the default mode for the function.

FNM_LEADING_DIR

0x20

Indicates that the match should ignore the /... after a match.

Return Values

If the string matches the specified pattern, returns 0. If the string and pattern do not match, returns FNM_NOMATCH (-1). If an error occurs, returns a nonzero value.

Remarks

The pattern parameter can use the following wildcards:

Wildcard

Description

*

Matches zero, one, or more characters.

?

Matches any single character, but does not match zero characters.

[ ]

Matches any single character specified within the brackets. For example, the pattern string "gr[ae]y" would match either spelling: gray or grey.

The fnmatch function is not fully POSIX compliant because fnmatch ignores case when performing matches. To make it POSIX compliant, you must link your code with the LD_WANT_POSIX_SEMANTICS (0x00400000) flag. The fnmatch function then performs case-sensitive matches unless the flags parameter is set to FNM_CASEFOLD, which allows it to ignore case.

IMPORTANT:The LD_WANT_POSIX_SEMANTICS flag is experimental and not fully supported until NetWare 5.1 SP8, NetWare 6.1 SP5, and NetWare 6.5 SP2. For more information about linker flags, see Section 1.6, Using a Linker Definition File.