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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       fnmatch — match a filename string or a pathname
14

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

58       If string matches the pattern  specified  by  pattern,  then  fnmatch()
59       shall   return  0.  If  there  is  no  match,  fnmatch()  shall  return
60       FNM_NOMATCH, which is defined in  <fnmatch.h>.   If  an  error  occurs,
61       fnmatch() shall return another non-zero value.
62

ERRORS

64       No errors are defined.
65
66       The following sections are informative.
67

EXAMPLES

69       None.
70

APPLICATION USAGE

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

RATIONALE

86       This function replaced the REG_FILENAME flag of regcomp() in early pro‐
87       posals  of  this volume of POSIX.1‐2008. It provides virtually the same
88       functionality as  the  regcomp()  and  regexec()  functions  using  the
89       REG_FILENAME and REG_FSLASH flags (the REG_FSLASH flag was proposed for
90       regcomp(), and would have had the opposite effect  from  FNM_PATHNAME),
91       but with a simpler function and less system overhead.
92

FUTURE DIRECTIONS

94       None.
95

SEE ALSO

97       glob(), Section 2.6, Word Expansions
98
99       The Base Definitions volume of POSIX.1‐2008, <fnmatch.h>
100
102       Portions  of  this text are reprinted and reproduced in electronic form
103       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
104       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
105       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
106       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
107       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
108       event of any discrepancy between this version and the original IEEE and
109       The Open Group Standard, the original IEEE and The Open Group  Standard
110       is  the  referee document. The original Standard can be obtained online
111       at http://www.unix.org/online.html .
112
113       Any typographical or formatting errors that appear  in  this  page  are
114       most likely to have been introduced during the conversion of the source
115       files to man page format. To report such errors,  see  https://www.ker
116       nel.org/doc/man-pages/reporting_bugs.html .
117
118
119
120IEEE/The Open Group                  2013                          FNMATCH(3P)
Impressum