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