libfossil
fsl_pathfinder Struct Reference

The "Path Finder" class is a utility class for searching the filesystem for files matching a set of common prefixes and/or suffixes (i.e. More...

#include "util.h"

Collaboration diagram for fsl_pathfinder:

Data Fields

fsl_buffer buf
 Used to build up a path string during fsl_pathfinder_search(), and holds the result of a successful search.
fsl_list dirs
 Holds the list of search directories.
fsl_list ext
 Holds the list of search extensions.

Detailed Description

The "Path Finder" class is a utility class for searching the filesystem for files matching a set of common prefixes and/or suffixes (i.e.

directories and file extensions).

Example usage:

int rc;
char const * found = NULL;
rc = fsl_pathfinder_ext_add( &pf, ".doc" );
if(rc) { ...error... }
// The following error checks are elided for readability:
rc = fsl_pathfinder_ext_add( &pf, ".txt" );
rc = fsl_pathfinder_ext_add( &pf, ".wri" );
rc = fsl_pathfinder_dir_add( &pf, "." );
rc = fsl_pathfinder_dir_add( &pf, "/my/doc/dir" );
rc = fsl_pathfinder_dir_add( &pf, "/other/doc/dir" );
rc = fsl_pathfinder_search( &pf, "MyDoc", &found, NULL);
if(0==rc){ assert(NULL!=found); }
// Eventually clean up:
The "Path Finder" class is a utility class for searching the filesystem for files matching a set of c...
Definition util.h:4936
FSL_EXPORT void fsl_pathfinder_clear(fsl_pathfinder *pf)
Frees all memory associated with pf, but does not free pf.
FSL_EXPORT int fsl_pathfinder_dir_add(fsl_pathfinder *pf, char const *dir)
Equivalent to fsl_pathfinder_dir_add2() with -1 as a final argument.
FSL_EXPORT int fsl_pathfinder_search(fsl_pathfinder *pf, char const *base, char const **pOut, fsl_size_t *outLen)
Searches for a file whose name can be constructed by some combination of pf's directory/extension lis...
FSL_EXPORT const fsl_pathfinder fsl_pathfinder_empty
Initialized-with-defaults fsl_pathfinder instance, intended for copy initialization.
Definition util.h:4972
FSL_EXPORT int fsl_pathfinder_ext_add(fsl_pathfinder *pf, char const *ext)
Equivalent to fsl_pathfinder_ext_add2() with -1 as a final argument.
See also
fsl_pathfinder_dir_add()
fsl_pathfinder_ext_add()
fsl_pathfinder_clear()
fsl_pathfinder_search()

Definition at line 4936 of file util.h.

Field Documentation

◆ buf

fsl_buffer fsl_pathfinder::buf

Used to build up a path string during fsl_pathfinder_search(), and holds the result of a successful search.

We use a buffer, as opposed to a simple string, because (A) it simplifies the search implementation and (B) reduces allocations (it gets reused for each search).

Definition at line 4954 of file util.h.

◆ dirs

fsl_list fsl_pathfinder::dirs

Holds the list of search directories.

Each entry is a (char *) owned by this object.

Definition at line 4946 of file util.h.

◆ ext

fsl_list fsl_pathfinder::ext

Holds the list of search extensions.

Each entry is a (char *) owned by this object.

Definition at line 4941 of file util.h.


The documentation for this struct was generated from the following file: