bglibs
Macros | Functions
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(), and path_match().

Function Documentation

◆ fnmatch()

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

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)

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 
)

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 
)

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, obuf_putc(), obuf_puti(), obuf_putiter, obuf_puts, obuf_putu(), outbuf, PATH_MATCH_DOTFILES, str_copyb(), str_copys(), str_free(), str_sort(), striter_advance(), striter_start(), and striter_valid().

◆ path_merge()

int path_merge ( str path,
const char *  start 
)

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 obuf_putstr, outbuf, and str_copys().

◆ path_mkdirs()

int path_mkdirs ( const char *  path,
unsigned  mode 
)

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.

◆ path_mktemp()

int path_mktemp ( const char *  prefix,
str filename 
)

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