The result of globbing is a vector of file names (strings). To return
glob uses a special data type,
is a structure. You pass
glob the address of the structure, and
it fills in the structure's fields to tell you about the results.
gl_pathvfield. Unlike the other fields, this is always an input to
glob, rather than an output from it. If you use a nonzero offset, then that many elements at the beginning of the vector are left empty. (The
globfunction fills them with null pointers.) The
gl_offsfield is meaningful only if you use the
GLOB_DOOFFSflag. Otherwise, the offset is always zero regardless of what is in this field, and the first real element comes at the beginning of the vector.
globdoes 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 section 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)
glob sorts the file names alphabetically before
returning them. You can turn this off with the flag
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.
glob succeeds, it returns 0. Otherwise, it returns one
of these error codes:
GLOB_ERRor your specified errfunc returned a nonzero value. See below for an explanation of the
GLOB_ERRflag and errfunc.
GLOB_NOCHECKflag, then you never get this error code, because that flag tells
globto pretend that the pattern matched at least one file.
In the event of an error,
glob stores information in
*vector-ptr about all the matches it has found so far.
Go to the first, previous, next, last section, table of contents.