O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The glob(3) Function

The glob(3) function represents another way that a process can gather a list of file and directory name objects. Unlike the fnmatch(3) function, the glob(3) function actually performs directory searches. The function synopsis for glob(3) and globfree(3) is as follows:

#include <glob.h>

int glob(
    const char *pattern,
    int flags,
    int (*errfunc)(const char *, int),
    glob_t *pglob);

void globfree(glob_t *pglob);

typedef struct {
    int    gl_pathc;       /* count of total paths so far */
    int    gl_matchc;      /* count of paths matching pattern */
    int    gl_offs;        /* reserved at beginning of gl_pathv */
    int    gl_flags;       /* returned flags */
    char   **gl_pathv;     /* list of paths matching pattern */
} glob_t;

The first argument pattern for glob(3) is a shell ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required