xref: /original-bsd/lib/libc/gen/fnmatch.3 (revision 3705696b)
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.1 (Berkeley) 06/09/93
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.Em "This flag is not currently implemented."
72.El
73.Sh RETURN VALUES
74The
75.Fn fnmatch
76function returns zero if
77.Fa string
78matches the pattern specified by
79.Fa pattern ,
80otherwise, it returns the value
81.Dv FNM_NOMATCH .
82.Sh SEE ALSO
83.Xr sh 1 ,
84.Xr glob 3 ,
85.Xr wordexp 3 ,
86.Xr regexp 3
87.Sh HISTORY
88The
89.Fn fnmatch
90function first appeared in 4.4BSD.
91.Sh BUGS
92Quotes and slashes in range patterns are not handled correctly by
93this implementation.
94.Pp
95The
96.Dv FNM_PERIOD
97flag is not implemented.
98.Pp
99The pattern
100.Ql *
101matches the empty string, even if
102.Dv FNM_PATHNAME
103is specified.
104