FNMATCH(3POSIX)
π FNMATCH(3POSIX) β the POSIX Programmer's Manual girlies π
okay bestie, so this whole page lives in the POSIX Programmer's Manual β¨. heads up tho: the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for details of Linux behavior, fr), or β plot twist β the interface might not even be implemented on Linux at all. π
π NAME π
fnmatch β match a filename string or a pathname. that's it, that's the whole job. π
β¨ SYNOPSIS β¨
#include <fnmatch.h>
int fnmatch(const char *pattern, const char *string, int flags);
π¦ DESCRIPTION π¦
so what fnmatch() does is match patterns exactly the way it's described in the Shell and Utilities volume of POSIX.1β2017, Section 2.13.1, Patterns Matching a Single Character, and Section 2.13.2, Patterns Matching Multiple Characters. it takes the string in the string argument and checks whether it matches the pattern in the pattern argument. vibe check passed or not, no in-between. π
the flags argument modifies how pattern and string get interpreted, and it's the bitwise-inclusive OR of zero or more of the flags defined in <fnmatch.h>. got it? iconic. now the deets:
- if the
FNM_PATHNAMEflag is set inflags, then a<slash>character ('/') instringshall be explicitly matched by a<slash>inpatternβ it shall not be matched by either the<asterisk>or<question-mark>special characters, and not by a bracket expression either. no shortcuts, no sneaky loopholes. π« - if
FNM_PATHNAMEis not set, the<slash>character is just treated as an ordinary character. no main character energy for the slash. β¨ - if
FNM_NOESCAPEis not set inflags, then a<backslash>character inpatternfollowed by any other character shall match that second character instring. in particular,"\\"shall match a<backslash>instring. but β and this is the messy part π β ifpatternends with an unescaped<backslash>, thenfnmatch()shall return a non-zero value (which means either no match or an error, and yeah it does not tell you which, sorry bestie). - if
FNM_NOESCAPEis set, a<backslash>character is treated as an ordinary character. plain. simple. at peace. π§ - if
FNM_PERIODis set inflags, then a leading<period>('.') instringshall match a<period>inpatternβ just like rule 2 in the Shell and Utilities volume of POSIX.1β2017, Section 2.13.3, Patterns Used for Filename Expansion describes, where the location of "leading" is indicated by the value ofFNM_PATHNAME:- if
FNM_PATHNAMEis set, a<period>counts as "leading" if it's the first character instring, or if it immediately follows a<slash>. - if
FNM_PATHNAMEis not set, a<period>counts as "leading" only if it's the first character ofstring.
- if
- if
FNM_PERIODis not set, then no special restrictions are placed on matching a period. free the period. ποΈ
π RETURN VALUE π
- if
stringmatches the pattern inpatternβfnmatch()shall return0. slay. π - if there's no match β
fnmatch()shall returnFNM_NOMATCH, which is defined in<fnmatch.h>. π - if an error occurs β
fnmatch()shall return another non-zero value. yes, a different non-zero value. keep your eyes peeled. π
π ERRORS π
No errors are defined. (not me having nothing to report π)
the following sections are informative. π«Ά
π EXAMPLES π
None. that's right, zero examples. we're on our own out here bestie. π
π APPLICATION USAGE π
the fnmatch() function has two major uses, and they're both lowkey iconic:
- it could be used by an application or utility that needs to read a directory and apply a pattern against each entry. the
findutility is an example of this. π₯ - it can also be used by the
paxutility to process its pattern operands, or by applications that need to match strings in a similar manner. π
the name fnmatch() is intended to imply filename match, rather than pathname match. the default action of this function is to match filename strings, not pathnames, since it gives no special significance to the <slash> character. but with the FNM_PATHNAME flag, fnmatch() does match pathnames β just without tilde expansion, without parameter expansion, and without any special treatment for a <period> at the beginning of a filename. so like, pathname mode but make it minimal. β¨
π RATIONALE π
this function replaced the REG_FILENAME flag of regcomp() in early proposals of this volume of POSIX.1β2017. it provides virtually the same functionality as the regcomp() and regexec() functions using the REG_FILENAME and REG_FSLASH flags β and btw, the REG_FSLASH flag was proposed for regcomp(), and would have had the opposite effect from FNM_PATHNAME β but with a simpler function and less system overhead. ate and left no crumbs. π
π§ FUTURE DIRECTIONS π§
None. the future is now, and it's the same as today. π¦
β SEE ALSO β
glob()- Section 2.6, Word Expansions
the Base Definitions volume of POSIX.1β2017, <fnmatch.h> π
πΈ COPYRIGHT πΈ
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html . π
fr fr, if something looks weird, it's probably a conversion oopsie, not a vibe. report it bestie. π«Ά
okay that's the whole thing, no cap. this page is from IEEE/The Open Group, 2017 (yeah, the FNMATCH(3POSIX) era β¨), and you just read the entire thing like a good little scholar. obsessed with you. mwah. πππ
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms