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 ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.