GLOB

Section: C Library Functions (3)
Updated: June 28, 1986
Index Return to Main Contents
 

NAME

glob - expand meta-characters in file names  

SYNOPSIS

int glob(pattern, buffer, size)
char *pattern;
char *buffer;
unsigned int size;
 

DESCRIPTION

Glob expands the meta-characters *, ? and [...] in pattern and copies the file name(s) that match the pattern to buffer , whose length is given by size .

Before expansion is attempted, the pattern is processed as follows: an initial ~user is replaced by user's home directory, an initial ~ is replaced by the contents of $HOME, and an initial $variable is replaced by the contents of the environment variable by that name. The universal quoting character \ can be prefixed to *, ? and [, to initial ~ or $, and to itself to prevent the special meaning.

The expansion algorithm used is believed to give exactly the same results as the expansion of meta-characters by the Bourne shell sh (1), except for the different quoting mechanism and the expansion of ~ and $. The files are sorted.  

RETURN VALUE

Glob returns the number of files matching the pattern that could be transferred to the buffer. If no files match, the return value is 0 but the pattern is copied to the buffer after expansion of ~, $ and \-quotes.  

SEE ALSO

sh(1)  

AUTHOR

Guido van Rossum, CWI, Amsterdam <guido@mcvax.uucp>  

DIAGNOSTICS

There are no explicit diagnostics. If there is not enough memory to hold the internal lists of partially-matching files, not all matching files may be found. If the buffer has not enough space to hold all matching files, as many as will fit are transferred to it. If $variable has no value, the empty string is substituted. If no expansion can be found for ~ or ~user , it is left in the pattern unchanged. If  

BUGS

There should be an interface to the ``raw'' globbing algorithm, which can return an arbitrary number of files in a ``malloced'' structure and does not do ~ or $ expansion or \-quoting.

The code uses the Berkeley directory-reading package, so in order to port it to v7 or sys5 you'll need to get hold of a public domain re-implementation of that package.

The name is a relict from ancient times.


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE
SEE ALSO
AUTHOR
DIAGNOSTICS
BUGS

This document was created by man2html, using the manual pages.
Time: 09:06:59 GMT, February 14, 2025