Debian Codegraph @

upstream/debian-unstable/man3/fnmatch.3

raw
1 '\" t
2 .\" Copyright 1993, Thomas Koenig <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH fnmatch 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 fnmatch \- match filename or pathname
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <fnmatch.h>
16 .P
17 .BI "int fnmatch(const char *" "pattern" ", const char *" string ", int " flags );
18 .fi
19 .SH DESCRIPTION
20 The
21 .BR fnmatch ()
22 function checks whether the
23 .I string
24 argument matches the
25 .I pattern
26 argument, which is a shell wildcard pattern (see
27 .BR glob (7)).
28 .P
29 The
30 .I flags
31 argument modifies the behavior;
32 it is the bitwise OR of zero or more
33 of the following flags:
34 .TP
35 .B FNM_NOESCAPE
36 If this flag is set, treat backslash as an ordinary character,
37 instead of an escape character.
38 .TP
39 .B FNM_PATHNAME
40 If this flag is set, match a slash in
41 .I string
42 only with a slash in
43 .I pattern
44 and not by an asterisk (*) or a question mark (?) metacharacter,
45 nor by a bracket expression ([]) containing a slash.
46 .TP
47 .B FNM_PERIOD
48 If this flag is set, a leading period in
49 .I string
50 has to be matched exactly by a period in
51 .IR pattern .
52 A period is considered to be leading if it is the first character in
53 .IR string ,
54 or if both
55 .B FNM_PATHNAME
56 is set and the period immediately follows a slash.
57 .TP
58 .B FNM_FILE_NAME
59 This is a GNU synonym for
60 .BR FNM_PATHNAME .
61 .TP
62 .B FNM_LEADING_DIR
63 If this flag (a GNU extension) is set, the pattern is considered to be
64 matched if it matches an initial segment of
65 .I string
66 which is followed by a slash.
67 This flag is mainly for the internal
68 use of glibc and is implemented only in certain cases.
69 .TP
70 .B FNM_CASEFOLD
71 .TQ
72 .BR FNM_IGNORECASE " (same as " FNM_CASEFOLD )
73 If this flag is set, the pattern is matched
74 case-insensitively.
75 .TP
76 .B FNM_EXTMATCH
77 If this flag (a GNU extension) is set, extended patterns are
78 supported, as introduced by \&'ksh' and now supported by other shells.
79 The extended format is as follows, with
80 .I pattern\-list
81 being a \&'|' separated list of patterns.
82 .TP
83 .RI \&'?( pattern\-list )'
84 The pattern matches if zero or one occurrences of any of the
85 patterns in the
86 .I pattern\-list
87 match the input
88 .IR string .
89 .TP
90 .RI \&'*( pattern\-list )'
91 The pattern matches if zero or more occurrences of any of the
92 patterns in the
93 .I pattern\-list
94 match the input
95 .IR string .
96 .TP
97 .RI \&'+( pattern\-list )'
98 The pattern matches if one or more occurrences of any of the
99 patterns in the
100 .I pattern\-list
101 match the input
102 .IR string .
103 .TP
104 .RI \&'@( pattern\-list )'
105 The pattern matches if exactly one occurrence of any of the
106 patterns in the
107 .I pattern\-list
108 match the input
109 .IR string .
110 .TP
111 .RI \&'!( pattern\-list )'
112 The pattern matches if the input
113 .I string
114 cannot be matched with
115 any of the patterns in the
116 .IR pattern\-list .
117 .SH RETURN VALUE
118 Zero if
119 .I string
120 matches
121 .IR pattern ,
122 .B FNM_NOMATCH
123 if there is no match or another nonzero value if there is an error.
124 .SH ATTRIBUTES
125 For an explanation of the terms used in this section, see
126 .BR attributes (7).
127 .TS
128 allbox;
129 lbx lb lb
130 l l l.
131 Interface Attribute Value
132 T{
133 .na
134 .nh
135 .BR fnmatch ()
136 T} Thread safety MT-Safe env locale
137 .TE
138 .SH STANDARDS
139 .TP
140 .BR fnmatch ()
141 POSIX.1-2008.
142 .TP
143 .B FNM_CASEFOLD
144 .TQ
145 .B FNM_IGNORECASE
146 POSIX.1-2024.
147 .TP
148 .B FNM_FILE_NAME
149 .TQ
150 .B FNM_LEADING_DIR
151 GNU.
152 .SH HISTORY
153 .TP
154 .BR fnmatch ()
155 POSIX.1-2001, POSIX.2.
156 .TP
157 .B FNM_CASEFOLD
158 has been available on many systems even before POSIX.1-2024.
159 .SH SEE ALSO
160 .BR sh (1),
161 .BR glob (3),
162 .BR scandir (3),
163 .BR wordexp (3),
164 .BR glob (7)