1FNMATCH(P)                 POSIX Programmer's Manual                FNMATCH(P)
2
3
4

NAME

6       fnmatch - match a filename or a pathname
7

SYNOPSIS

9       #include <fnmatch.h>
10
11       int fnmatch(const char *pattern, const char *string, int flags);
12
13

DESCRIPTION

15       The  fnmatch()  function shall match patterns as described in the Shell
16       and Utilities volume of IEEE Std 1003.1-2001, Section 2.13.1,  Patterns
17       Matching a Single Character, and Section 2.13.2, Patterns Matching Mul‐
18       tiple Characters.  It checks the string specified by the  string  argu‐
19       ment  to  see  if it matches the pattern specified by the pattern argu‐
20       ment.
21
22       The flags argument shall  modify  the  interpretation  of  pattern  and
23       string.  It  is  the  bitwise-inclusive OR of zero or more of the flags
24       defined in <fnmatch.h>. If the FNM_PATHNAME flag is set in flags,  then
25       a  slash  character  ( '/' ) in string shall be explicitly matched by a
26       slash in pattern; it shall not be matched by  either  the  asterisk  or
27       question-mark  special  characters, nor by a bracket expression. If the
28       FNM_PATHNAME flag is not set, the slash character shall be  treated  as
29       an ordinary character.
30
31       If  FNM_NOESCAPE  is not set in flags, a backslash character ( '\' ) in
32       pattern followed by any other character shall match that second charac‐
33       ter  in  string. In particular, "\\" shall match a backslash in string.
34       If FNM_NOESCAPE is set, a backslash character shall be  treated  as  an
35       ordinary character.
36
37       If FNM_PERIOD is set in flags, then a leading period ( '.'  ) in string
38       shall match a period in pattern; as described by rule 2  in  the  Shell
39       and  Utilities volume of IEEE Std 1003.1-2001, Section 2.13.3, Patterns
40       Used for Filename Expansion where the location of  "leading"  is  indi‐
41       cated by the value of FNM_PATHNAME:
42
43        * If  FNM_PATHNAME  is  set,  a period is "leading" if it is the first
44          character in string or if it immediately follows a slash.
45
46        * If FNM_PATHNAME is not set, a period is "leading" only if it is  the
47          first character of string.
48
49       If  FNM_PERIOD  is  not set, then no special restrictions are placed on
50       matching a period.
51

RETURN VALUE

53       If string matches the pattern  specified  by  pattern,  then  fnmatch()
54       shall   return  0.  If  there  is  no  match,  fnmatch()  shall  return
55       FNM_NOMATCH, which is defined in  <fnmatch.h>.   If  an  error  occurs,
56       fnmatch() shall return another non-zero value.
57

ERRORS

59       No errors are defined.
60
61       The following sections are informative.
62

EXAMPLES

64       None.
65

APPLICATION USAGE

67       The  fnmatch()  function  has  two  major  uses. It could be used by an
68       application or utility that needs to read a directory and apply a  pat‐
69       tern against each entry. The find utility is an example of this. It can
70       also be used by the pax utility to process its pattern operands, or  by
71       applications that need to match strings in a similar manner.
72
73       The  name  fnmatch()  is  intended to imply filename match, rather than
74       pathname match. The default action of this function is to  match  file‐
75       names, rather than pathnames, since it gives no special significance to
76       the slash character. With the FNM_PATHNAME flag, fnmatch()  does  match
77       pathnames, but without tilde expansion, parameter expansion, or special
78       treatment for a period at the beginning of a filename.
79

RATIONALE

81       This function replaced the REG_FILENAME flag of regcomp() in early pro‐
82       posals  of  this  volume of IEEE Std 1003.1-2001. It provides virtually
83       the same functionality as the regcomp() and regexec()  functions  using
84       the REG_FILENAME and REG_FSLASH flags (the REG_FSLASH flag was proposed
85       for regcomp(), and would have had the opposite  effect  from  FNM_PATH‐
86       NAME), but with a simpler function and less system overhead.
87

FUTURE DIRECTIONS

89       None.
90

SEE ALSO

92       glob()    ,    wordexp()    ,    the   Base   Definitions   volume   of
93       IEEE Std 1003.1-2001, <fnmatch.h>, the Shell and  Utilities  volume  of
94       IEEE Std 1003.1-2001
95
97       Portions  of  this text are reprinted and reproduced in electronic form
98       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
99       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
100       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
101       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
102       event of any discrepancy between this version and the original IEEE and
103       The  Open Group Standard, the original IEEE and The Open Group Standard
104       is the referee document. The original Standard can be  obtained  online
105       at http://www.opengroup.org/unix/online.html .
106
107
108
109IEEE/The Open Group                  2003                           FNMATCH(P)
Impressum