xref: /freebsd/lib/libc/gen/fnmatch.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
1.\" Copyright (c) 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Guido van Rossum.
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.Dd April 2, 2022
31.Dt FNMATCH 3
32.Os
33.Sh NAME
34.Nm fnmatch
35.Nd test whether a filename or pathname matches a shell-style pattern
36.Sh LIBRARY
37.Lb libc
38.Sh SYNOPSIS
39.In fnmatch.h
40.Ft int
41.Fn fnmatch "const char *pattern" "const char *string" "int flags"
42.Sh DESCRIPTION
43The
44.Fn fnmatch
45function
46matches patterns according to the rules used by the shell.
47It checks the string specified by the
48.Fa string
49argument to see if it matches the pattern specified by the
50.Fa pattern
51argument.
52.Pp
53The
54.Fa flags
55argument modifies the interpretation of
56.Fa pattern
57and
58.Fa string .
59The value of
60.Fa flags
61is the bitwise inclusive
62.Tn OR
63of any of the following
64constants, which are defined in the include file
65.In fnmatch.h .
66.Bl -tag -width FNM_PATHNAME
67.It Dv FNM_NOESCAPE
68Normally, every occurrence of a backslash
69.Pq Ql \e
70followed by a character in
71.Fa pattern
72is replaced by that character.
73This is done to negate any special meaning for the character.
74If the
75.Dv FNM_NOESCAPE
76flag is set, a backslash character is treated as an ordinary character.
77.It Dv FNM_PATHNAME
78Slash characters in
79.Fa string
80must be explicitly matched by slashes in
81.Fa pattern .
82If this flag is not set, then slashes are treated as regular characters.
83.It Dv FNM_PERIOD
84Leading periods in
85.Fa string
86must be explicitly matched by periods in
87.Fa pattern .
88If this flag is not set, then leading periods are treated as regular
89characters.
90The definition of
91.Dq leading
92is related to the specification of
93.Dv FNM_PATHNAME .
94A period is always
95.Dq leading
96if it is the first character in
97.Fa string .
98Additionally, if
99.Dv FNM_PATHNAME
100is set,
101a period is
102leading
103if it immediately follows a slash.
104.It Dv FNM_LEADING_DIR
105Ignore
106.Dq Li /*
107rest after successful
108.Fa pattern
109matching.
110.It Dv FNM_CASEFOLD
111Ignore case distinctions in both the
112.Fa pattern
113and the
114.Fa string .
115.El
116.Sh RETURN VALUES
117The
118.Fn fnmatch
119function returns zero if
120.Fa string
121matches the pattern specified by
122.Fa pattern ,
123otherwise, it returns the value
124.Dv FNM_NOMATCH .
125.Sh SEE ALSO
126.Xr sh 1 ,
127.Xr glob 3 ,
128.Xr regex 3
129.Sh STANDARDS
130The current implementation of the
131.Fn fnmatch
132function
133.Em does not
134conform to
135.St -p1003.2 .
136Collating symbol expressions, equivalence class expressions and
137character class expressions are not supported.
138.Sh HISTORY
139A predecessor to
140.Fn fnmatch ,
141.Fn gmatch ,
142first appeared in the Programmer's Workbench (PWB/UNIX).
143The
144.Fn fnmatch
145function first appeared in
146.Bx 4.4 .
147.Sh BUGS
148The pattern
149.Ql *
150matches the empty string, even if
151.Dv FNM_PATHNAME
152is specified.
153