Implementation status: partially implemented

Synopsis

#include <fnmatch.h>

int fnmatch(const char *pattern, const char *string, int flags);

Description

The fnmatch function checks the string specified by the string argument to see if it matches the pattern specified by the pattern argument..

Arguments:

pattern - the pattern to be matched.
string - the string to check.
flags - the way to check compatibility of string and pattern.

The flags argument modifes the interpretation of pattern and string. It is the bitwise-inclusive OR of zero or more of the flags defined in <fnmatch.h>. These are:

  • FNM_NOMATCH the string does not match the pattern.

  • FNM_PATHNAME the interpretation of the character ( '/' ) in string. If it is set then it should be explicitly matched by a in pattern; it is not matched by either the or special characters, nor by a bracket expression. If the FNM_PATHNAME flag is not set, the character is treated as an ordinary character.

  • FNM_NOESCAPE if it is not set in flags, a character in pattern followed by any other character matches that second character in string. In particular, "\" matches a in string. If pattern ends with an unescaped , fnmatch() returns a non-zero value (indicating either no match or an error). If FNM_NOESCAPE is set, a character is treated as an ordinary character.

  • FNM_PERIOD if it is set in flags, then a leading ( '.' ) in string matches a in pattern; by the value of FNM_PATHNAME:

    • If FNM_PATHNAME is set, a is "leading" if it is the first character in string or if it immediately follows a .

    • If FNM_PATHNAME is not set, a 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

  • 0 if string matches the pattern specified by pattern.

  • FNM_NOMATCH if there is no match.

  • -1 if an error occurs.

Errors

No errors are defined.

Implementation tasks

  • Implement fnmatch.h file containing constants mentioned above.
  • Implement the fnmatch() function.