NAME

readdir - list file names

SYNOPSIS

char **genfilnam(pattern)
char *pattern;

char **dirfiles(dir, pattern)
char *dir, *pattern;

DESCRIPTION

These functions return a list of strings which match the pattern given by the null-terminated string pattern.  The list and each of its component strings are allocated with malloc(3) and are null-terminated.  Pattern may contain shell file name generation meta-characters (see sh(1)):

*
Matches any sequence of zero or more characters. 

?
Matches any single character. 

[ . . . ]
Matches any single character which is a member of this character class.  If the first character within the brackets is !, then this pattern matches any single character which is not a member of this character class.  The class is composed of the characters listed within the brackets.  Furthermore, if two characters are listed separated by -, the class includes all the characters lexically between the two, inclusively. 

A / may not be matched with a meta-character; nor may a dot at the beginning of the pattern or a dot immediately following a /

Genfilnam searches directories for file names which match patternPattern is interpreted as a full file name specification which may contain /’s.  If pattern does not contain meta-characters or if it does but no match is found, pattern is returned as the only element of the list. 

Dirfiles searches a single directory, dir, for files which match patternPattern is interpreted as a specification for files within this directory only.  /’s are interpreted as ordinary characters. 

These functions support files(misc). 

SEE ALSO

files(misc)
sh(1), malloc(3) in the UNIX Programmer’s Manual

DIAGNOSTICS

Dirfiles returns zero if no match is found. 

DISCLAIMER

Although the author believes these functions represent a faithful implementation of the behavior of the shell meta-characters, there is hardly a consensus amongst systems tested regarding the manner in which the more bizarre patterns are interpreted.  Indeed, we have seen sh(1) dump core attempting to interpret some patterns. 

BUGS

If genfilnum is given a pattern such as /*/*/*/*/* on a large file system, it will likely go away for a long time and finally run out of memory. 

from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber