xref: /original-bsd/lib/libc/gen/fnmatch.3 (revision e58c8952)
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.\" %sccs.include.redist.man%
7.\"
8.\"     @(#)fnmatch.3	8.2 (Berkeley) 04/16/94
9.\"
10.Dd
11.Dt FNMATCH 3
12.Os
13.Sh NAME
14.Nm fnmatch
15.Nd match filename or pathname
16.Sh SYNOPSIS
17.Fd #include <fnmatch.h>
18.Ft int
19.Fn fnmatch "const char *pattern" "const char *string" "int flags"
20.Sh DESCRIPTION
21The
22.Fn fnmatch
23function
24matches patterns according to the rules used by the shell.
25It checks the string specified by the
26.Fa string
27argument to see if it matches the pattern specified by the
28.Fa pattern
29argument.
30.Pp
31The
32.Fa flags
33argument modifies the interpretation of
34.Fa pattern
35and
36.Fa string .
37The value of
38.Fa flags
39is the bitwise inclusive
40.Tn OR
41of any of the following
42constants, which are defined in the include file
43.Pa fnmatch.h .
44.Bl -tag -width FNM_PATHNAME
45.It Dv FNM_NOESCAPE
46Normally, every occurrence of a backslash
47.Pq Ql \e
48followed by a character in
49.Fa pattern
50is replaced by that character.
51This is done to negate any special meaning for the character.
52If the
53.Dv FNM_NOESCAPE
54flag is set, a backslash character is treated as an ordinary character.
55.It Dv FNM_PATHNAME
56Slash characters in
57.Fa string
58must be explicitly matched by slashes in
59.Fa pattern .
60If this flag is not set, then slashes are treated as regular characters.
61.It Dv FNM_PERIOD
62Leading periods in strings match periods in patterns.
63The definition of ``leading'' is related to the specification of
64.Dv FNM_PATHNAME.
65A period is always ``leading'' if it is the first character in
66.Ar string .
67Additionally, if
68.Dv FNM_PATHNAME
69is set,
70a period is ``leading'' if it immediately follows a slash.
71.El
72.Sh RETURN VALUES
73The
74.Fn fnmatch
75function returns zero if
76.Fa string
77matches the pattern specified by
78.Fa pattern ,
79otherwise, it returns the value
80.Dv FNM_NOMATCH .
81.Sh SEE ALSO
82.Xr sh 1 ,
83.Xr glob 3 ,
84.Xr regex 3 ,
85.Xr wordexp 3
86.Sh STANDARDS
87The
88.Fn fnmatch
89function conforms to
90.St -p1003.2 .
91.Sh HISTORY
92The
93.Fn fnmatch
94function first appeared in
95.Bx 4.4 .
96.Sh BUGS
97The pattern
98.Ql *
99matches the empty string, even if
100.Dv FNM_PATHNAME
101is specified.
102