The function glob does globbing using the pattern pattern
in the current directory. It puts the result in a newly allocated
vector, and stores the size and address of this vector into
*vector-ptr . The argument flags is a combination of
bit flags; see Flags for Globbing, for details of the flags.
The result of globbing is a sequence of file names. The function
glob allocates a string for each resulting word, then
allocates a vector of type char ** to store the addresses of
these strings. The last element of the vector is a null pointer.
This vector is called the word vector.
To return this vector, glob stores both its address and its
length (number of elements, not counting the terminating null pointer)
into *vector-ptr .
Normally, glob sorts the file names alphabetically before
returning them. You can turn this off with the flag GLOB_NOSORT
if you want to get the information as fast as possible. Usually it's
a good idea to let glob sort them--if you process the files in
alphabetical order, the users will have a feel for the rate of progress
that your application is making.
If glob succeeds, it returns 0. Otherwise, it returns one
of these error codes:
GLOB_ABORTED
- There was an error opening a directory, and you used the flag
GLOB_ERR or your specified errfunc returned a nonzero
value.
for an explanation of the GLOB_ERR flag and errfunc.
GLOB_NOMATCH
- The pattern didn't match any existing files. If you use the
GLOB_NOCHECK flag, then you never get this error code, because
that flag tells glob to pretend that the pattern matched
at least one file.
GLOB_NOSPACE
- It was impossible to allocate memory to hold the result.
In the event of an error, glob stores information in
*vector-ptr about all the matches it has found so far.
It is important to notive that the glob function will not fail if
it encounters directories or files which cannot be handled without the
LFS interfaces. The implementation of glob is supposed to use
these functions internally. This at least is the assumptions made by
the Unix standard. The GNU extension of allowing the user to provide
own directory handling and stat functions complicates things a
bit. If these callback functions are used and a large file or directory
is encountered glob can fail.
|