Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
Typedefs | Functions
Ase::Path Namespace Reference

The Path namespace provides functions for file path manipulation and testing. More...

Typedefs

using StringStringM = std::map< String, String >
 

Functions

String dirname (const String &path)
 Retrieve the directory part of the filename path.
 
String basename (const String &path)
 Strips all directory components from path and returns the resulting file name.
 
String normalize (const String &path)
 Convert path to normal form.
 
String realpath (const String &path)
 Resolve links and directory references in path and provide a canonicalized absolute pathname.
 
String dir_terminate (const String &path)
 Append trailing slash to path, unless it's present.
 
String strip_slashes (const String &path)
 Strip trailing directory terminators.
 
String abspath (const String &path, const String &incwd)
 
bool isabs (const String &path)
 Return wether path is an absolute pathname.
 
bool isroot (const String &path, bool dos_drives)
 Return wether path is an absolute pathname which identifies the root directory.
 
bool isdirname (const String &path)
 Return wether path is pointing to a directory component.
 
bool mkdirs (const String &dirpath, uint mode)
 Create the directories in dirpath with mode, check errno on false returns.
 
bool dircontains (const String &dirpath, const String &descendant, String *relpath)
 Check if descendant belongs to the directory hierarchy under dirpath.
 
void rmrf (const String &dir)
 Recursively delete directory tree.
 
bool copy_file (const String &src, const String &dest)
 Copy a file to a new non-existing location, sets errno and returns false on error.
 
bool rename (const String &src, const String &dest)
 
String user_home (const String &username)
 Get a user's home directory, uses $HOME if no username is given.
 
String data_home ()
 Get the $XDG_DATA_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
 
String config_home ()
 Get the $XDG_CONFIG_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
 
String cache_home ()
 Get the $XDG_CACHE_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
 
String runtime_dir ()
 Get the $XDG_RUNTIME_DIR directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
 
String xdg_dir (const String &xdgdir)
 
String config_dirs ()
 Get the $XDG_CONFIG_DIRS directory list, see: https://specifications.freedesktop.org/basedir-spec/latest.
 
String data_dirs ()
 Get the $XDG_DATA_DIRS directory list, see: https://specifications.freedesktop.org/basedir-spec/latest.
 
String config_names ()
 Get config names as set with config_names(), if unset defaults to program_alias().
 
void config_names (const String &names)
 Set a colon separated list of names for this application to find configuration settings and files.
 
StringPair split_extension (const std::string &filepath, const bool lastdot)
 
String expand_tilde (const String &path)
 Expand a "~/" or "~user/" path which refers to user home directories.
 
String skip_root (const String &path)
 
size_t file_size (const String &path)
 Retrieve the on-disk size in bytes of path.
 
bool check (const String &file, const String &mode)
 
bool equals (const String &file1, const String &file2)
 
String cwd ()
 Return the current working directoy, including symlinks used in $PWD if available.
 
StringS searchpath_split (const String &searchpath)
 
bool searchpath_contains (const String &searchpath, const String &element)
 Check if searchpath contains element, a trailing slash searches for directories.
 
String searchpath_find (const String &searchpath, const String &file, const String &mode)
 Find the first file in searchpath which matches mode (see check()).
 
StringS searchpath_list (const String &searchpath, const String &mode)
 Find all searchpath entries matching mode (see check()).
 
String join_with (const String &head, char joiner, const String &tail)
 Construct head + joiner + tail avoiding duplicates of joiner.
 
String searchpath_multiply (const String &searchpath, const String &postfixes)
 Yield a new searchpath by combining each element of searchpath with each element of postfixes.
 
String searchpath_join (const StringS &string_vector)
 
String vpath_find (const String &file, const String &mode)
 
void glob (const String &pathpattern, StringS &dirs, StringS &files)
 Create list with directories and filenames matching pathpattern with shell wildcards.
 
void glob (const String &pathpattern, StringS &matches)
 Create list with filenames matching pathpattern with shell wildcards.
 
void rglob (const String &basedir, const String &pattern, StringS &matches)
 Recursively match files with glob pattern under basedir.
 
void unique_realpaths (StringS &pathnames)
 Convert all pathnames via realpath() and eliminate duplicates.
 
String simplify_abspath (const std::string &abspath_expression)
 Remove extra slashes, './' and '../' from abspath_expression.
 
charmemread (const String &filename, size_t *lengthp, ssize_t maxlength)
 
void memfree (char *memread_mem)
 
bool memwrite (const String &filename, size_t len, const uint8 *bytes, bool append, int perms)
 
String stringread (const String &filename, ssize_t maxlength)
 
bool stringwrite (const String &filename, const String &data, bool mkdirs_, int perms)
 
bool stringappend (const String &filename, const String &data, bool mkdirs_, int perms)
 
template<class ... S>
String join (String path, const S &...more)
 
template<class ... S>
String searchpath_join (String path, const S &...more)
 

Detailed Description

The Path namespace provides functions for file path manipulation and testing.

Typedef Documentation

◆ StringStringM

Definition at line 340 of file path.cc.

Function Documentation

◆ abspath()

String Ase::Path::abspath ( const String path,
const String incwd 
)
Parameters
patha filename path
incwdoptional current working directory

Complete path to become an absolute file path. If neccessary, incwd or the real current working directory is prepended.

Definition at line 134 of file path.cc.

References abspath(), cwd(), std::string::empty(), isabs(), and Ase::program_cwd().

Referenced by abspath().

◆ basename()

String Ase::Path::basename ( const String path)

Strips all directory components from path and returns the resulting file name.

Definition at line 68 of file path.cc.

References ASE_DIRSEP, ASE_DIRSEP2, basename(), std::string::c_str(), strrchr(), and std::string::substr().

◆ cache_home()

String Ase::Path::cache_home ( )

Get the $XDG_CACHE_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.

Definition at line 322 of file path.cc.

References expand_tilde(), getenv(), and isabs().

◆ check()

bool Ase::Path::check ( const String file,
const String mode 
)
Parameters
filepossibly relative filename
modefeature string
Returns
true if file adhears to mode

Perform various checks on file and return whether all checks passed. On failure, errno is set appropriately, and FALSE is returned. Available features to be checked for are:

  • e - file must exist
  • r - file must be readable
  • w - file must be writable
  • x - file must be executable
  • f - file must be a regular file
  • d - file must be a directory
  • l - file must be a symbolic link
  • c - file must be a character device
  • b - file must be a block device
  • p - file must be a named pipe
  • s - file must be a socket.

Definition at line 625 of file path.cc.

References std::string::c_str(), ENOENT, errno(), and std::string::size().

Referenced by Ase::anklang_cachedir_clean_stale(), Ase::anklang_cachedir_cleanup(), Ase::WebSocketConnection::http_request(), mkdirs(), searchpath_find(), and searchpath_list().

◆ config_dirs()

String Ase::Path::config_dirs ( )

Get the $XDG_CONFIG_DIRS directory list, see: https://specifications.freedesktop.org/basedir-spec/latest.

Definition at line 401 of file path.cc.

References getenv().

◆ config_home()

String Ase::Path::config_home ( )

Get the $XDG_CONFIG_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.

Definition at line 312 of file path.cc.

References expand_tilde(), getenv(), and isabs().

◆ config_names() [1/2]

String Ase::Path::config_names ( )

Get config names as set with config_names(), if unset defaults to program_alias().

Definition at line 442 of file path.cc.

◆ config_names() [2/2]

void Ase::Path::config_names ( const String names)

Set a colon separated list of names for this application to find configuration settings and files.

Definition at line 449 of file path.cc.

◆ copy_file()

bool Ase::Path::copy_file ( const String src,
const String dest 
)

Copy a file to a new non-existing location, sets errno and returns false on error.

Definition at line 244 of file path.cc.

References std::string::c_str(), close(), std::filesystem::copy_file(), errno(), ioctl(), open(), unlink(), and std::error_code::value().

◆ cwd()

String Ase::Path::cwd ( )

Return the current working directoy, including symlinks used in $PWD if available.

Definition at line 662 of file path.cc.

References ERANGE, errno(), free(), getcwd(), and malloc().

Referenced by abspath(), and Ase::program_cwd().

◆ data_dirs()

String Ase::Path::data_dirs ( )

Get the $XDG_DATA_DIRS directory list, see: https://specifications.freedesktop.org/basedir-spec/latest.

Definition at line 412 of file path.cc.

References getenv().

◆ data_home()

String Ase::Path::data_home ( )

Get the $XDG_DATA_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.

Definition at line 302 of file path.cc.

References expand_tilde(), getenv(), and isabs().

◆ dir_terminate()

String Ase::Path::dir_terminate ( const String path)

Append trailing slash to path, unless it's present.

Definition at line 109 of file path.cc.

References ASE_DIRSEP, std::string::back(), and std::string::empty().

◆ dircontains()

bool Ase::Path::dircontains ( const String dirpath,
const String descendant,
String relpath 
)

Check if descendant belongs to the directory hierarchy under dirpath.

Definition at line 221 of file path.cc.

References ASE_DIRSEP, std::string::compare(), realpath(), std::string::size(), and std::string::substr().

◆ dirname()

String Ase::Path::dirname ( const String path)

Retrieve the directory part of the filename path.

Definition at line 60 of file path.cc.

References dirname(), std::string::empty(), and std::filesystem::path::parent_path().

Referenced by Ase::anklang_runpath().

◆ equals()

bool Ase::Path::equals ( const String file1,
const String file2 
)
Parameters
file1possibly relative filename
file2possibly relative filename
Returns
TRUE if file1 and file2 are equal

Check whether file1 and file2 are pointing to the same inode in the same file system on the same device.

Definition at line 641 of file path.cc.

References std::string::c_str(), errno(), std::string::size(), and stat().

◆ expand_tilde()

String Ase::Path::expand_tilde ( const String path)

Expand a "~/" or "~user/" path which refers to user home directories.

Definition at line 468 of file path.cc.

References ASE_DIRSEP, ASE_DIRSEP2, std::string::empty(), std::string::find(), std::min(), std::string::substr(), and user_home().

Referenced by cache_home(), config_home(), and data_home().

◆ file_size()

size_t Ase::Path::file_size ( const String path)

Retrieve the on-disk size in bytes of path.

Definition at line 514 of file path.cc.

References std::filesystem::file_size().

◆ glob() [1/2]

void Ase::Path::glob ( const String pathpattern,
StringS dirs,
StringS files 
)

Create list with directories and filenames matching pathpattern with shell wildcards.

Definition at line 812 of file path.cc.

References std::string::c_str(), glob(), globfree(), std::vector::push_back(), and strlen().

◆ glob() [2/2]

void Ase::Path::glob ( const String pathpattern,
StringS matches 
)

Create list with filenames matching pathpattern with shell wildcards.

Definition at line 831 of file path.cc.

References std::string::c_str(), glob(), globfree(), and std::vector::push_back().

◆ isabs()

bool Ase::Path::isabs ( const String path)

Return wether path is an absolute pathname.

Definition at line 148 of file path.cc.

References return_unless, and std::string::size().

Referenced by abspath(), cache_home(), config_home(), data_home(), runtime_dir(), searchpath_find(), and user_home().

◆ isdirname()

bool Ase::Path::isdirname ( const String path)

Return wether path is pointing to a directory component.

Definition at line 181 of file path.cc.

References std::string::size().

◆ isroot()

bool Ase::Path::isroot ( const String path,
bool  dos_drives 
)

Return wether path is an absolute pathname which identifies the root directory.

Definition at line 160 of file path.cc.

References std::string::data().

◆ join()

template<class ... S>
String Ase::Path::join ( String  path,
const S &...  more 
)

Definition at line 90 of file path.hh.

◆ join_with()

String Ase::Path::join_with ( const String head,
char  joiner,
const String tail 
)

Construct head + joiner + tail avoiding duplicates of joiner.

Definition at line 761 of file path.cc.

References std::string::back(), return_unless, std::string::size(), and std::string::substr().

Referenced by searchpath_multiply().

◆ memfree()

void Ase::Path::memfree ( char memread_mem)

Definition at line 967 of file path.cc.

◆ memread()

char * Ase::Path::memread ( const String filename,
size_t lengthp,
ssize_t  maxlength 
)

Definition at line 950 of file path.cc.

◆ memwrite()

bool Ase::Path::memwrite ( const String filename,
size_t  len,
const uint8 bytes,
bool  append,
int  perms 
)

Definition at line 974 of file path.cc.

◆ mkdirs()

bool Ase::Path::mkdirs ( const String dirpath,
uint  mode 
)

Create the directories in dirpath with mode, check errno on false returns.

Definition at line 197 of file path.cc.

References check(), ENOTDIR, errno(), std::filesystem::path::has_relative_path(), mkdir(), mkdirs(), std::filesystem::path::native(), and std::filesystem::path::parent_path().

Referenced by Ase::log_setup(), and mkdirs().

◆ normalize()

String Ase::Path::normalize ( const String path)

Convert path to normal form.

Definition at line 86 of file path.cc.

References std::filesystem::path::lexically_normal().

◆ realpath()

String Ase::Path::realpath ( const String path)

Resolve links and directory references in path and provide a canonicalized absolute pathname.

Definition at line 93 of file path.cc.

References std::string::c_str(), errno(), free(), and realpath().

◆ rename()

bool Ase::Path::rename ( const String src,
const String dest 
)

Definition at line 277 of file path.cc.

◆ rglob()

void Ase::Path::rglob ( const String basedir,
const String pattern,
StringS matches 
)

Recursively match files with glob pattern under basedir.

Definition at line 844 of file path.cc.

References ASE_DIRSEP, ASE_DIRSEP2, std::string::c_str(), globfree(), std::vector::push_back(), rglob(), and std::string::size().

Referenced by rglob().

◆ rmrf()

void Ase::Path::rmrf ( const String dir)

Recursively delete directory tree.

Definition at line 236 of file path.cc.

References std::filesystem::remove_all().

Referenced by Ase::anklang_cachedir_clean_stale(), Ase::anklang_cachedir_cleanup(), and Ase::anklang_cachedir_create().

◆ runtime_dir()

String Ase::Path::runtime_dir ( )

Get the $XDG_RUNTIME_DIR directory, see: https://specifications.freedesktop.org/basedir-spec/latest.

Definition at line 332 of file path.cc.

References getenv(), getuid(), isabs(), and Ase::string_format().

◆ searchpath_contains()

bool Ase::Path::searchpath_contains ( const String searchpath,
const String element 
)

Check if searchpath contains element, a trailing slash searches for directories.

Definition at line 715 of file path.cc.

References std::string::find(), std::string::size(), and std::string::substr().

◆ searchpath_find()

String Ase::Path::searchpath_find ( const String searchpath,
const String file,
const String mode 
)

Find the first file in searchpath which matches mode (see check()).

Definition at line 737 of file path.cc.

References check(), isabs(), and std::vector::size().

◆ searchpath_join() [1/2]

String Ase::Path::searchpath_join ( const StringS string_vector)

Definition at line 788 of file path.cc.

◆ searchpath_join() [2/2]

template<class ... S>
String Ase::Path::searchpath_join ( String  path,
const S &...  more 
)

Definition at line 97 of file path.hh.

◆ searchpath_list()

StringS Ase::Path::searchpath_list ( const String searchpath,
const String mode 
)

Find all searchpath entries matching mode (see check()).

Definition at line 750 of file path.cc.

References check(), and std::vector::push_back().

◆ searchpath_multiply()

String Ase::Path::searchpath_multiply ( const String searchpath,
const String postfixes 
)

Yield a new searchpath by combining each element of searchpath with each element of postfixes.

Definition at line 778 of file path.cc.

References ASE_SEARCHPATH_SEPARATOR, and join_with().

◆ searchpath_split()

StringS Ase::Path::searchpath_split ( const String searchpath)

Definition at line 697 of file path.cc.

◆ simplify_abspath()

String Ase::Path::simplify_abspath ( const std::string abspath_expression)

Remove extra slashes, './' and '../' from abspath_expression.

Definition at line 886 of file path.cc.

References ssize_t, Ase::string_join(), and Ase::string_split().

◆ skip_root()

String Ase::Path::skip_root ( const String path)

Definition at line 487 of file path.cc.

◆ split_extension()

StringPair Ase::Path::split_extension ( const std::string filepath,
const bool  lastdot 
)

Definition at line 455 of file path.cc.

◆ stringappend()

bool Ase::Path::stringappend ( const String filename,
const String data,
bool  mkdirs_,
int  perms 
)

Definition at line 1024 of file path.cc.

◆ stringread()

String Ase::Path::stringread ( const String filename,
ssize_t  maxlength 
)

Definition at line 999 of file path.cc.

◆ stringwrite()

bool Ase::Path::stringwrite ( const String filename,
const String data,
bool  mkdirs_,
int  perms 
)

Definition at line 1016 of file path.cc.

◆ strip_slashes()

String Ase::Path::strip_slashes ( const String path)

Strip trailing directory terminators.

Definition at line 118 of file path.cc.

References std::string::back(), std::string::resize(), and std::string::size().

◆ unique_realpaths()

void Ase::Path::unique_realpaths ( StringS pathnames)

Convert all pathnames via realpath() and eliminate duplicates.

Definition at line 869 of file path.cc.

References std::vector::begin(), std::vector::end(), std::vector::erase(), free(), std::vector::resize(), std::vector::size(), ssize_t, and std::unique().

◆ user_home()

String Ase::Path::user_home ( const String username)

Get a user's home directory, uses $HOME if no username is given.

Definition at line 287 of file path.cc.

References std::string::empty(), getenv(), and isabs().

Referenced by expand_tilde().

◆ vpath_find()

String Ase::Path::vpath_find ( const String file,
const String mode 
)

Definition at line 795 of file path.cc.

◆ xdg_dir()

String Ase::Path::xdg_dir ( const String xdgdir)

Definition at line 379 of file path.cc.