# fnmatch

## PROLOG



           This manual page is part of the POSIX Programmer's Manual.  The
           Linux implementation of this interface may differ (consult the
           corresponding Linux manual page for details of Linux behavior), or
           the interface may not be implemented on Linux.
    


## NAME



           fnmatch — match a filename string or a pathname
    


## SYNOPSIS



           #include <fnmatch.h>
    
           int fnmatch(const char *_pattern_ , const char *_string_ , int _flags_);
    


## DESCRIPTION



           The _fnmatch_() function shall match patterns as 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 checks the string specified by
           the _string_ argument to see if it matches the pattern specified by
           the _pattern_ argument.
    
           The _flags_ argument shall modify the interpretation of _pattern_ and
           _string_.  It is the bitwise-inclusive OR of zero or more of the
           flags defined in _< fnmatch.h>_.  If the FNM_PATHNAME flag is set in
           _flags_ , then a <slash> character (**'/'**) in _string_ shall be
           explicitly matched by a <slash> in _pattern_ ; it shall not be
           matched by either the <asterisk> or <question-mark> special
           characters, nor by a bracket expression. If the FNM_PATHNAME flag
           is not set, the <slash> character shall be treated as an ordinary
           character.
    
           If FNM_NOESCAPE is not set in _flags_ , a <backslash> character in
           _pattern_ followed by any other character shall match that second
           character in _string_.  In particular, **"\\"** shall match a
           <backslash> in _string_.  If _pattern_ ends with an unescaped
           <backslash>, _fnmatch_() shall return a non-zero value (indicating
           either no match or an error).  If FNM_NOESCAPE is set, a
           <backslash> character shall be treated as an ordinary character.
    
           If FNM_PERIOD is set in _flags_ , then a leading <period> (**'.'**)  in
           _string_ shall match a <period> in _pattern_ ; as described by rule 2
           in the Shell and Utilities volume of POSIX.1‐2017, _Section 2.13.3_ ,
           _Patterns Used for Filename Expansion_ where the location of
           ``leading'' is indicated by the value of FNM_PATHNAME:
    
            *  If FNM_PATHNAME is set, a <period> is ``leading'' if it is the
               first character in _string_ or if it immediately follows a
               <slash>.
    
            *  If FNM_PATHNAME is not set, a <period> is ``leading'' only if
               it is the first character of _string_.
    
           If FNM_PERIOD is not set, then no special restrictions are placed
           on matching a period.
    


## RETURN VALUE



           If _string_ matches the pattern specified by _pattern_ , then _fnmatch_()
           shall return 0. If there is no match, _fnmatch_() shall return
           FNM_NOMATCH, which is defined in _< fnmatch.h>_.  If an error occurs,
           _fnmatch_() shall return another non-zero value.
    


## ERRORS



           No errors are defined.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           The _fnmatch_() function has two major uses. It could be used by an
           application or utility that needs to read a directory and apply a
           pattern against each entry. The _find_ utility is an example of
           this. It can also be used by the _pax_ utility 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, rather than pathnames, since it gives no
           special significance to the <slash> character. With the
           FNM_PATHNAME flag, _fnmatch_() does match pathnames, but without
           tilde expansion, parameter expansion, or special treatment for a
           <period> at the beginning of a filename.
    


## 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 (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.
    


## FUTURE DIRECTIONS



           None.
    


* * *