xref: /freebsd/lib/libc/gen/fnmatch.3 (revision 732a02b4e77866604a120a275c082bb6221bd2ff)
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.\"     @(#)fnmatch.3	8.3 (Berkeley) 4/28/95
31.\" $FreeBSD$
32.\"
33.Dd July 18, 2004
34.Dt FNMATCH 3
35.Os
36.Sh NAME
37.Nm fnmatch
38.Nd test whether a filename or pathname matches a shell-style pattern
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In fnmatch.h
43.Ft int
44.Fn fnmatch "const char *pattern" "const char *string" "int flags"
45.Sh DESCRIPTION
46The
47.Fn fnmatch
48function
49matches patterns according to the rules used by the shell.
50It checks the string specified by the
51.Fa string
52argument to see if it matches the pattern specified by the
53.Fa pattern
54argument.
55.Pp
56The
57.Fa flags
58argument modifies the interpretation of
59.Fa pattern
60and
61.Fa string .
62The value of
63.Fa flags
64is the bitwise inclusive
65.Tn OR
66of any of the following
67constants, which are defined in the include file
68.In fnmatch.h .
69.Bl -tag -width FNM_PATHNAME
70.It Dv FNM_NOESCAPE
71Normally, every occurrence of a backslash
72.Pq Ql \e
73followed by a character in
74.Fa pattern
75is replaced by that character.
76This is done to negate any special meaning for the character.
77If the
78.Dv FNM_NOESCAPE
79flag is set, a backslash character is treated as an ordinary character.
80.It Dv FNM_PATHNAME
81Slash characters in
82.Fa string
83must be explicitly matched by slashes in
84.Fa pattern .
85If this flag is not set, then slashes are treated as regular characters.
86.It Dv FNM_PERIOD
87Leading periods in
88.Fa string
89must be explicitly matched by periods in
90.Fa pattern .
91If this flag is not set, then leading periods are treated as regular
92characters.
93The definition of
94.Dq leading
95is related to the specification of
96.Dv FNM_PATHNAME .
97A period is always
98.Dq leading
99if it is the first character in
100.Fa string .
101Additionally, if
102.Dv FNM_PATHNAME
103is set,
104a period is
105leading
106if it immediately follows a slash.
107.It Dv FNM_LEADING_DIR
108Ignore
109.Dq Li /*
110rest after successful
111.Fa pattern
112matching.
113.It Dv FNM_CASEFOLD
114Ignore case distinctions in both the
115.Fa pattern
116and the
117.Fa string .
118.El
119.Sh RETURN VALUES
120The
121.Fn fnmatch
122function returns zero if
123.Fa string
124matches the pattern specified by
125.Fa pattern ,
126otherwise, it returns the value
127.Dv FNM_NOMATCH .
128.Sh SEE ALSO
129.Xr sh 1 ,
130.Xr glob 3 ,
131.Xr regex 3
132.Sh STANDARDS
133The current implementation of the
134.Fn fnmatch
135function
136.Em does not
137conform to
138.St -p1003.2 .
139Collating symbol expressions, equivalence class expressions and
140character class expressions are not supported.
141.Sh HISTORY
142The
143.Fn fnmatch
144function first appeared in
145.Bx 4.4 .
146.Sh BUGS
147The pattern
148.Ql *
149matches the empty string, even if
150.Dv FNM_PATHNAME
151is specified.
152