1FNMATCH(3P) POSIX Programmer's Manual FNMATCH(3P)
2
3
4
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
12 fnmatch - match a filename or a pathname
13
15 #include <fnmatch.h>
16
17 int fnmatch(const char *pattern, const char *string, int flags);
18
19
21 The fnmatch() function shall match patterns as described in the Shell
22 and Utilities volume of IEEE Std 1003.1-2001, Section 2.13.1, Patterns
23 Matching a Single Character, and Section 2.13.2, Patterns Matching Mul‐
24 tiple Characters. It checks the string specified by the string argu‐
25 ment to see if it matches the pattern specified by the pattern argu‐
26 ment.
27
28 The flags argument shall modify the interpretation of pattern and
29 string. It is the bitwise-inclusive OR of zero or more of the flags
30 defined in <fnmatch.h>. If the FNM_PATHNAME flag is set in flags, then
31 a slash character ( '/' ) in string shall be explicitly matched by a
32 slash in pattern; it shall not be matched by either the asterisk or
33 question-mark special characters, nor by a bracket expression. If the
34 FNM_PATHNAME flag is not set, the slash character shall be treated as
35 an ordinary character.
36
37 If FNM_NOESCAPE is not set in flags, a backslash character ( '\' ) in
38 pattern followed by any other character shall match that second charac‐
39 ter in string. In particular, "\\" shall match a backslash in string.
40 If FNM_NOESCAPE is set, a backslash character shall be treated as an
41 ordinary character.
42
43 If FNM_PERIOD is set in flags, then a leading period ( '.' ) in string
44 shall match a period in pattern; as described by rule 2 in the Shell
45 and Utilities volume of IEEE Std 1003.1-2001, Section 2.13.3, Patterns
46 Used for Filename Expansion where the location of "leading" is indi‐
47 cated by the value of FNM_PATHNAME:
48
49 * If FNM_PATHNAME is set, a period is "leading" if it is the first
50 character in string or if it immediately follows a slash.
51
52 * If FNM_PATHNAME is not set, a period is "leading" only if it is the
53 first character of string.
54
55 If FNM_PERIOD is not set, then no special restrictions are placed on
56 matching a period.
57
59 If string matches the pattern specified by pattern, then fnmatch()
60 shall return 0. If there is no match, fnmatch() shall return
61 FNM_NOMATCH, which is defined in <fnmatch.h>. If an error occurs,
62 fnmatch() shall return another non-zero value.
63
65 No errors are defined.
66
67 The following sections are informative.
68
70 None.
71
73 The fnmatch() function has two major uses. It could be used by an
74 application or utility that needs to read a directory and apply a pat‐
75 tern against each entry. The find utility is an example of this. It can
76 also be used by the pax utility to process its pattern operands, or by
77 applications that need to match strings in a similar manner.
78
79 The name fnmatch() is intended to imply filename match, rather than
80 pathname match. The default action of this function is to match file‐
81 names, rather than pathnames, since it gives no special significance to
82 the slash character. With the FNM_PATHNAME flag, fnmatch() does match
83 pathnames, but without tilde expansion, parameter expansion, or special
84 treatment for a period at the beginning of a filename.
85
87 This function replaced the REG_FILENAME flag of regcomp() in early pro‐
88 posals of this volume of IEEE Std 1003.1-2001. It provides virtually
89 the same functionality as the regcomp() and regexec() functions using
90 the REG_FILENAME and REG_FSLASH flags (the REG_FSLASH flag was proposed
91 for regcomp(), and would have had the opposite effect from FNM_PATH‐
92 NAME), but with a simpler function and less system overhead.
93
95 None.
96
98 glob(), wordexp(), the Base Definitions volume of IEEE Std 1003.1-2001,
99 <fnmatch.h>, the Shell and Utilities volume of IEEE Std 1003.1-2001
100
102 Portions of this text are reprinted and reproduced in electronic form
103 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
104 -- Portable Operating System Interface (POSIX), The Open Group Base
105 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
106 Electrical and Electronics Engineers, Inc and The Open Group. In the
107 event of any discrepancy between this version and the original IEEE and
108 The Open Group Standard, the original IEEE and The Open Group Standard
109 is the referee document. The original Standard can be obtained online
110 at http://www.opengroup.org/unix/online.html .
111
112
113
114IEEE/The Open Group 2003 FNMATCH(3P)