path: Filename manipulation functions

## Macros

#define | PATH_MATCH_DOTFILES 1

## Functions

int | path_merge (str *path, const char *start)
int | fnmatch (const char *filename, const char *pattern, unsigned options)
int | has_magic (const char *s)
int | path_match (const char *pattern, str *result, unsigned options)
int | path_contains (const char *path, const char *part)
int | path_mktemp (const char *prefix, str *filename)
int | path_mkdirs (const char *path, unsigned mode)

## Detailed Description

## Macro Definition Documentation

## PATH_MATCH_DOTFILES

#define PATH_MATCH_DOTFILES 1

Make path_match include files starting with dots.

Referenced by fnmatch().

## Function Documentation

## fnmatch()

int fnmatch | ( | const char * | filename,
|  | const char * | pattern,
|  | unsigned | options )

extern

Matches a path using glob patterns.

References str::len, PATH_MATCH_DOTFILES, str::s, and str::size.

## has_magic()

int has_magic | ( | const char * | s | ) |

extern

Does the string have glob characters in it.

Returns true if the given string contains at least one instance of either *, ?, or [.

## path_contains()

int path_contains | ( | const char * | path,
|  | const char * | part )

extern

Test if a path contains a component.

Returns true if the `path` contains `part` either at the start followed by a slash, at the end preceded by a slash, or elsewhere with a slash on either side.

## path_match()

int path_match | ( | const char * | pattern,
|  | str * | result,
|  | unsigned | options )

extern

Matches the pattern against existing files.

This function produces a list of existing files in `result` (in the current directory) that match the given pattern. If `options` has `PATH_MATCH_DOTFILES` set, the result may contain paths starting with ".".

References str::len, str_copyb(), str_copys(), str_free(), and str_sort().

## path_merge()

int path_merge | ( | str * | path,
|  | const char * | start )

extern

Merge two paths together.

This function takes a starting path, and merges the second path into it. If the second path starts with a "/", it replaces the existing path completely. If the second path contains any ".." components, the preceding directory component in the current path (if any) is removed. All "." components are removed.

The effects of this function are equivalent to changing directory to the first path and then using the second one.

References str_copys().

## path_mkdirs()

int path_mkdirs | ( | const char * | path,
|  | unsigned | mode )

extern

Create a directory, optionally creating any parent directories.

This function creates the named directory using mkdir. If any of the parent directories of the specified path do not exist, they are created as well (with the same mode).

Note
  Unlike the "<tt>mkdir -p</tt>" command, this function will result in an error if the path already exists.

References path_mkdirs().

Referenced by path_mkdirs().

## path_mktemp()

int path_mktemp | ( | const char * | prefix,
|  | str * | filename )

extern

Create a temporary file.

This function creates a temporary file by adding an difficult-to-predict suffix (using the PID and microsecond timestamp) to the given prefix. If this filename does not exist, it is opened in read/write mode.

References str::s, str_catc(), str_catu(), str_catuw(), and str_copys().