17.7.2 Interface to fnmatch()

This extension provides an interface to the C library fnmatch() function. The usage is:

@load "fnmatch"

This is how you load the extension.

result = fnmatch(pattern, string, flags)

The return value is zero on success, FNM_NOMATCH if the string did not match the pattern, or a different nonzero value if an error occurred.

In addition to the fnmatch() function, the fnmatch extension adds one constant (FNM_NOMATCH), and an array of flag values named FNM.

The arguments to fnmatch() are:

pattern

The file name wildcard to match

string

The file name string

flag

Either zero, or the bitwise OR of one or more of the flags in the FNM array

The flags are as follows:

Array elementCorresponding flag defined by fnmatch()
FNM["CASEFOLD"]FNM_CASEFOLD
FNM["FILE_NAME"]FNM_FILE_NAME
FNM["LEADING_DIR"]FNM_LEADING_DIR
FNM["NOESCAPE"]FNM_NOESCAPE
FNM["PATHNAME"]FNM_PATHNAME
FNM["PERIOD"]FNM_PERIOD

Here is an example:

@load "fnmatch"
...
flags = or(FNM["PERIOD"], FNM["NOESCAPE"])
if (fnmatch("*.a", "foo.c", flags) == FNM_NOMATCH)
    print "no match"