1f52b16c6SYuri Pankov.\" 266492cf0SYuri Pankov.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for 366492cf0SYuri Pankov.\" permission to reproduce portions of its copyrighted documentation. 4f52b16c6SYuri Pankov.\" Original documentation from The Open Group can be obtained online at 5c10c16deSRichard Lowe.\" http://www.opengroup.org/bookstore/. 6f52b16c6SYuri Pankov.\" 766492cf0SYuri Pankov.\" The Institute of Electrical and Electronics Engineers and The Open 866492cf0SYuri Pankov.\" Group, have given us permission to reprint portions of their 9f52b16c6SYuri Pankov.\" documentation. 10f52b16c6SYuri Pankov.\" 1166492cf0SYuri Pankov.\" In the following statement, the phrase ``this text'' refers to portions 1266492cf0SYuri Pankov.\" of the system documentation. 13f52b16c6SYuri Pankov.\" 1466492cf0SYuri Pankov.\" Portions of this text are reprinted and reproduced in electronic form 1566492cf0SYuri Pankov.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, 1666492cf0SYuri Pankov.\" Standard for Information Technology -- Portable Operating System 1766492cf0SYuri Pankov.\" Interface (POSIX), The Open Group Base Specifications Issue 6, 1866492cf0SYuri Pankov.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics 1966492cf0SYuri Pankov.\" Engineers, Inc and The Open Group. In the event of any discrepancy 2066492cf0SYuri Pankov.\" between these versions and the original IEEE and The Open Group 2166492cf0SYuri Pankov.\" Standard, the original IEEE and The Open Group Standard is the referee 2266492cf0SYuri Pankov.\" document. The original Standard can be obtained online at 23f52b16c6SYuri Pankov.\" http://www.opengroup.org/unix/online.html. 24f52b16c6SYuri Pankov.\" 25c10c16deSRichard Lowe.\" This notice shall appear on any product containing this material. 26f52b16c6SYuri Pankov.\" 27f52b16c6SYuri Pankov.\" The contents of this file are subject to the terms of the 28f52b16c6SYuri Pankov.\" Common Development and Distribution License (the "License"). 29f52b16c6SYuri Pankov.\" You may not use this file except in compliance with the License. 30f52b16c6SYuri Pankov.\" 31f52b16c6SYuri Pankov.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 32f52b16c6SYuri Pankov.\" or http://www.opensolaris.org/os/licensing. 33f52b16c6SYuri Pankov.\" See the License for the specific language governing permissions 34f52b16c6SYuri Pankov.\" and limitations under the License. 35f52b16c6SYuri Pankov.\" 36f52b16c6SYuri Pankov.\" When distributing Covered Code, include this CDDL HEADER in each 37f52b16c6SYuri Pankov.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 38f52b16c6SYuri Pankov.\" If applicable, add the following below this CDDL HEADER, with the 39f52b16c6SYuri Pankov.\" fields enclosed by brackets "[]" replaced with your own identifying 40f52b16c6SYuri Pankov.\" information: Portions Copyright [yyyy] [name of copyright owner] 41f52b16c6SYuri Pankov.\" 42f52b16c6SYuri Pankov.\" 43f52b16c6SYuri Pankov.\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved 44f52b16c6SYuri Pankov.\" Portions Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved 45f52b16c6SYuri Pankov.\" Copyright 2017 Nexenta Systems, Inc. 46f52b16c6SYuri Pankov.\" 47*63f43743SAhelenia Ziemiańska.Dd July 12, 2024 48f52b16c6SYuri Pankov.Dt FNMATCH 3C 49f52b16c6SYuri Pankov.Os 50f52b16c6SYuri Pankov.Sh NAME 51f52b16c6SYuri Pankov.Nm fnmatch 52f52b16c6SYuri Pankov.Nd match filename or path name 53f52b16c6SYuri Pankov.Sh LIBRARY 54f52b16c6SYuri Pankov.Lb libc 55f52b16c6SYuri Pankov.Sh SYNOPSIS 56f52b16c6SYuri Pankov.In fnmatch.h 57f52b16c6SYuri Pankov.Ft int 58f52b16c6SYuri Pankov.Fo fnmatch 59f52b16c6SYuri Pankov.Fa "const char *pattern" 60f52b16c6SYuri Pankov.Fa "const char *string" 61f52b16c6SYuri Pankov.Fa "int flags" 62f52b16c6SYuri Pankov.Fc 63f52b16c6SYuri Pankov.Sh DESCRIPTION 64f52b16c6SYuri PankovThe 65f52b16c6SYuri Pankov.Fn fnmatch 66f52b16c6SYuri Pankovfunction matches patterns as described on the 67bbf21555SRichard Lowe.Xr fnmatch 7 68f52b16c6SYuri Pankovmanual page 69f52b16c6SYuri Pankov.Po with the exceptions noted in the 70f52b16c6SYuri Pankov.Sx STANDARDS 71f52b16c6SYuri Pankov.Pc . 72f52b16c6SYuri PankovIt checks the 73f52b16c6SYuri Pankov.Fa string 74f52b16c6SYuri Pankovargument to see if it matches the 75f52b16c6SYuri Pankov.Fa pattern 76f52b16c6SYuri Pankovargument. 77f52b16c6SYuri Pankov.Pp 78f52b16c6SYuri PankovThe 79f52b16c6SYuri Pankov.Fa flags 80f52b16c6SYuri Pankovargument modifies the interpretation of 81f52b16c6SYuri Pankov.Fa pattern 82f52b16c6SYuri Pankovand 83f52b16c6SYuri Pankov.Fa string . 84f52b16c6SYuri PankovIt is the bitwise inclusive OR of zero or more of the following flags defined in 85f52b16c6SYuri Pankovthe header 86f52b16c6SYuri Pankov.In fnmatch.h . 87f52b16c6SYuri Pankov.Bl -tag -width "FNM_LEADING_DIR" 88f52b16c6SYuri Pankov.It Dv FNM_PATHNAME 89f52b16c6SYuri PankovIf set, a slash 90f52b16c6SYuri Pankov.Pq Qq / 91f52b16c6SYuri Pankovcharacter in 92f52b16c6SYuri Pankov.Fa string 93f52b16c6SYuri Pankovwill be explicitly matched by a slash in 94f52b16c6SYuri Pankov.Fa pattern ; 95f52b16c6SYuri Pankovit will not be matched by either the asterisk 96f52b16c6SYuri Pankov.Pq Qq * 97f52b16c6SYuri Pankovor question-mark 98f52b16c6SYuri Pankov.Pq Qq \&? 99f52b16c6SYuri Pankovspecial characters, nor by a bracket 100f52b16c6SYuri Pankov.Pq Qq [] 101f52b16c6SYuri Pankovexpression. 102c10c16deSRichard Lowe.sp 103c10c16deSRichard LoweIf not set, the slash character is treated as an ordinary character. 104f52b16c6SYuri Pankov.It Dv FNM_IGNORECASE 105f52b16c6SYuri PankovIf set, the 106f52b16c6SYuri Pankov.Fa string 107f52b16c6SYuri Pankovwill be transliterated to lower case before doing the actual match. 108f52b16c6SYuri PankovThis transliteration is done using 109f52b16c6SYuri Pankov.Xr towlower_l 3C , 110f52b16c6SYuri Pankovusing the locale of the current thread. 111f52b16c6SYuri PankovIf no locale is set, then the global locale is used instead. 112f52b16c6SYuri Pankov.Pp 113f52b16c6SYuri PankovIf not set, the match will use 114f52b16c6SYuri Pankov.Fa string 115f52b16c6SYuri Pankovwith no changes, making the match case-sensitive. 116f52b16c6SYuri Pankov.Pp 117f52b16c6SYuri PankovFor compatibility with 118f52b16c6SYuri Pankov.Fx 119f52b16c6SYuri Pankovimplementation of 120f52b16c6SYuri Pankov.Fn fnmatch , 121f52b16c6SYuri Pankovheader 122f52b16c6SYuri Pankov.In fnmatch.h 123f52b16c6SYuri Pankovprovides the 124*63f43743SAhelenia Ziemiańska.Dv FNM_CASEFOLD 125f52b16c6SYuri Pankovflag having the same meaning. 126f52b16c6SYuri Pankov.It Dv FNM_NOESCAPE 127f52b16c6SYuri PankovIf not set, a backslash character 128f52b16c6SYuri Pankov.Pq Qq \e 129f52b16c6SYuri Pankovin 130f52b16c6SYuri Pankov.Fa pattern 131f52b16c6SYuri Pankovfollowed by any other character will match that second character in 132f52b16c6SYuri Pankov.Fa string . 133f52b16c6SYuri PankovIn particular, 134f52b16c6SYuri Pankov.Qq \e\e 135f52b16c6SYuri Pankovwill match a backslash in 136f52b16c6SYuri Pankov.Fa string . 137f52b16c6SYuri Pankov.Pp 138c10c16deSRichard LoweIf set, a backslash character will be treated as an ordinary character. 139f52b16c6SYuri Pankov.It Dv FNM_PERIOD 140f52b16c6SYuri PankovIf set, a leading period in 141f52b16c6SYuri Pankov.Fa string 142f52b16c6SYuri Pankovwill match a period in 143f52b16c6SYuri Pankov.Fa pattern ; 144f52b16c6SYuri Pankovwhere the location of 145f52b16c6SYuri Pankov.Qq leading 146f52b16c6SYuri Pankovis indicated by the value of 147f52b16c6SYuri Pankov.Dv FNM_PATHNAME : 148f52b16c6SYuri Pankov.Bl -bullet 149f52b16c6SYuri Pankov.It 150f52b16c6SYuri PankovIf 151f52b16c6SYuri Pankov.Dv FNM_PATHNAME 152f52b16c6SYuri Pankovis set, a period is 153f52b16c6SYuri Pankov.Qq leading 154f52b16c6SYuri Pankovif it is the first character in 155f52b16c6SYuri Pankov.Fa string 156f52b16c6SYuri Pankovor if it immediately follows a slash. 157f52b16c6SYuri Pankov.It 158f52b16c6SYuri PankovIf 159f52b16c6SYuri Pankov.Dv FNM_PATHNAME 160f52b16c6SYuri Pankovis not set, a period is 161f52b16c6SYuri Pankov.Qq leading 162f52b16c6SYuri Pankovonly if it is the first character of 163f52b16c6SYuri Pankov.Fa string . 164f52b16c6SYuri Pankov.El 165f52b16c6SYuri Pankov.Pp 166c10c16deSRichard LoweIf not set, no special restrictions are placed on matching a period. 167f52b16c6SYuri Pankov.It Dv FNM_LEADING_DIR 168f52b16c6SYuri PankovMatch if 169f52b16c6SYuri Pankov.Fa pattern 170f52b16c6SYuri Pankovmatches initial segment of 171f52b16c6SYuri Pankov.Fa string 172f52b16c6SYuri Pankovwhich is followed by a slash. 173f52b16c6SYuri Pankov.El 174f52b16c6SYuri Pankov.Sh RETURN VALUES 175f52b16c6SYuri PankovIf 176f52b16c6SYuri Pankov.Fa string 177f52b16c6SYuri Pankovmatches the pattern specified by 178f52b16c6SYuri Pankov.Fa pattern , 179f52b16c6SYuri Pankovthen 180f52b16c6SYuri Pankov.Fn fnmatch 181f52b16c6SYuri Pankovreturns 0. 182f52b16c6SYuri PankovIf there is no match, 183f52b16c6SYuri Pankov.Fn fnmatch 184f52b16c6SYuri Pankovreturns 185f52b16c6SYuri Pankov.Dv FNM_NOMATCH , 186f52b16c6SYuri Pankovwhich is defined in the header 187f52b16c6SYuri Pankov.In fnmatch.h . 188f52b16c6SYuri PankovIf an error occurs, 189f52b16c6SYuri Pankov.Fn fnmatch 190f52b16c6SYuri Pankovreturns another non-zero value. 191f52b16c6SYuri Pankov.Sh USAGE 192f52b16c6SYuri PankovThe 193f52b16c6SYuri Pankov.Fn fnmatch 194f52b16c6SYuri Pankovfunction has two major uses. 195f52b16c6SYuri PankovIt could be used by an application or utility that needs to read a directory and 196f52b16c6SYuri Pankovapply a pattern against each entry. 197f52b16c6SYuri PankovThe 198f52b16c6SYuri Pankov.Xr find 1 199f52b16c6SYuri Pankovutility is an example of this. 200f52b16c6SYuri PankovIt can also be used by the 201f52b16c6SYuri Pankov.Xr pax 1 202f52b16c6SYuri Pankovutility to process its 203f52b16c6SYuri Pankov.Fa pattern 204f52b16c6SYuri Pankovoperands, or by applications that need to match strings in a similar manner. 205f52b16c6SYuri Pankov.Pp 206f52b16c6SYuri PankovThe name 207f52b16c6SYuri Pankov.Fn fnmatch 208f52b16c6SYuri Pankovis intended to imply 209f52b16c6SYuri Pankov.Sy filename 210f52b16c6SYuri Pankovmatch, rather than 211f52b16c6SYuri Pankov.Sy pathname 212f52b16c6SYuri Pankovmatch. 213f52b16c6SYuri PankovThe default action of this function is to match filenames, rather than path 214f52b16c6SYuri Pankovnames, since it gives no special significance to the slash character. 215f52b16c6SYuri PankovWith the 216f52b16c6SYuri Pankov.Dv FNM_PATHNAME 217f52b16c6SYuri Pankovflag, 218f52b16c6SYuri Pankov.Fn fnmatch 219f52b16c6SYuri Pankovdoes match path names, but without tilde expansion, parameter expansion, or 220f52b16c6SYuri Pankovspecial treatment for period at the beginning of a filename. 221f52b16c6SYuri Pankov.Sh CODE SET INDEPENDENCE 222f52b16c6SYuri Pankov.Sy Enabled 223f52b16c6SYuri Pankov.Sh INTERFACE STABILITY 224f52b16c6SYuri Pankov.Sy Standard 225f52b16c6SYuri Pankov.Sh MT-LEVEL 226f52b16c6SYuri Pankov.Sy MT-Safe with exceptions 227f52b16c6SYuri Pankov.Pp 228f52b16c6SYuri PankovThe 229f52b16c6SYuri Pankov.Fn fnmatch 230f52b16c6SYuri Pankovfunction can be used safely in multithreaded applications, as long as 231f52b16c6SYuri Pankov.Xr setlocale 3C 232f52b16c6SYuri Pankovis not being called to change the locale. 233f52b16c6SYuri Pankov.Sh SEE ALSO 234f52b16c6SYuri Pankov.Xr find 1 , 235f52b16c6SYuri Pankov.Xr pax 1 , 236f52b16c6SYuri Pankov.Xr glob 3C , 237f52b16c6SYuri Pankov.Xr setlocale 3C , 238f52b16c6SYuri Pankov.Xr wordexp 3C , 239bbf21555SRichard Lowe.Xr attributes 7 , 240bbf21555SRichard Lowe.Xr fnmatch 7 , 241bbf21555SRichard Lowe.Xr standards 7 242f52b16c6SYuri Pankov.Sh STANDARDS 243f52b16c6SYuri PankovThe current implementation of the 244f52b16c6SYuri Pankov.Fn fnmatch 245f52b16c6SYuri Pankovfunction 246f52b16c6SYuri Pankov.Em does not 247f52b16c6SYuri Pankovconform to 248f52b16c6SYuri Pankov.St -p1003.2 . 249f52b16c6SYuri PankovCollating symbol expressions, equivalence class expressions and 250f52b16c6SYuri Pankovcharacter class expressions are not supported. 251f52b16c6SYuri Pankov.Sh BUGS 252f52b16c6SYuri PankovThe pattern 253f52b16c6SYuri Pankov.Qq * 254f52b16c6SYuri Pankovmatches the empty string, even if 255f52b16c6SYuri Pankov.Dv FNM_PATHNAME 256f52b16c6SYuri Pankovis specified. 257