1.\" $OpenBSD: fnmatch.3,v 1.16 2014/01/21 03:15:45 schwarze 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 $Mdocdate: January 21 2014 $ 35.Dt FNMATCH 3 36.Os 37.Sh NAME 38.Nm fnmatch 39.Nd match filename or pathname using shell globbing rules 40.Sh SYNOPSIS 41.In fnmatch.h 42.Ft int 43.Fn fnmatch "const char *pattern" "const char *string" "int flags" 44.Sh DESCRIPTION 45The 46.Fn fnmatch 47function matches patterns according to the globbing rules used by the shell. 48It checks the string specified by the 49.Fa string 50argument to see if it matches the pattern specified by the 51.Fa pattern 52argument. 53.Pp 54The 55.Fa flags 56argument modifies the interpretation of 57.Fa pattern 58and 59.Fa string . 60The value of 61.Fa flags 62is the bitwise inclusive 63.Tn OR 64of any of the following 65constants, which are defined in the include file 66.In fnmatch.h . 67.Bl -tag -width FNM_PATHNAME 68.It Dv FNM_NOESCAPE 69Normally, every occurrence of a backslash 70.Pq Sq \e 71followed by a character in 72.Fa pattern 73is replaced by that character. 74This is done to negate any special meaning for the character. 75If the 76.Dv FNM_NOESCAPE 77flag is set, a backslash character is treated as an ordinary character. 78.It Dv FNM_PATHNAME 79Slash characters in 80.Fa string 81must be explicitly matched by slashes in 82.Fa pattern . 83If this flag is not set, then slashes are treated as regular characters. 84.It Dv FNM_PERIOD 85Leading periods in 86.Fa string 87must be explicitly matched by periods in 88.Fa pattern . 89If this flag is not set, then leading periods are treated as regular 90characters. 91The definition of 92.Dq leading 93is related to the specification of 94.Dv FNM_PATHNAME . 95A period is always leading 96if it is the first character in 97.Fa string . 98Additionally, if 99.Dv FNM_PATHNAME 100is set, 101a period is leading 102if it immediately follows a slash. 103.It Dv FNM_LEADING_DIR 104Ignore 105.Sq /* 106rest after successful 107.Fa pattern 108matching. 109.It Dv FNM_CASEFOLD 110Ignore case distinctions in both the 111.Fa pattern 112and the 113.Fa string . 114.El 115.Sh RETURN VALUES 116The 117.Fn fnmatch 118function returns zero if 119.Fa string 120matches the pattern specified by 121.Fa pattern , 122otherwise, it returns the value 123.Dv FNM_NOMATCH . 124.Sh SEE ALSO 125.Xr sh 1 , 126.Xr glob 3 , 127.Xr regex 3 , 128.Xr glob 7 129.Sh STANDARDS 130The 131.Fn fnmatch 132function conforms to 133.St -p1003.2-92 134and 135.St -xpg4.2 . 136.Pp 137Note, however, that the flags 138.Dv FNM_LEADING_DIR 139and 140.Dv FNM_CASEFOLD 141are extensions and should not be used by applications striving for 142strict standards conformance. 143.Sh HISTORY 144A predecessor to 145.Fn fnmatch , 146.Fn gmatch , 147first appeared in the Programmer's Workbench (PWB/UNIX). 148The 149.Fn fnmatch 150function first appeared in 151.Bx 4.4 . 152.Sh BUGS 153The pattern 154.Ql * 155matches the empty string, even if 156.Dv FNM_PATHNAME 157is specified. 158