Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)
« « « Anklang Documentation |
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 . | |
char * | memread (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) |
The Path namespace provides functions for file path manipulation and testing.
using Ase::Path::StringStringM = typedef std::map<String,String> |
path | a filename path |
incwd | optional 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().
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().
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().
file | possibly relative filename |
mode | feature string |
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().
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().
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().
String Ase::Path::config_names | ( | ) |
Get config names as set with config_names(), if unset defaults to program_alias().
void Ase::Path::config_names | ( | const String & | names | ) |
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().
String Ase::Path::cwd | ( | ) |
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().
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().
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().
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().
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().
file1 | possibly relative filename |
file2 | possibly relative filename |
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 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().
Retrieve the on-disk size in bytes of path
.
Definition at line 514 of file path.cc.
References std::filesystem::file_size().
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().
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().
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().
Return wether path is pointing to a directory component.
Definition at line 181 of file path.cc.
References std::string::size().
Return wether path is an absolute pathname which identifies the root directory.
Definition at line 160 of file path.cc.
References std::string::data().
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().
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().
Convert path
to normal form.
Definition at line 86 of file path.cc.
References std::filesystem::path::lexically_normal().
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().
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().
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().
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().
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().
Find all searchpath entries matching mode (see check()).
Definition at line 750 of file path.cc.
References check(), and std::vector::push_back().
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().
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().
StringPair Ase::Path::split_extension | ( | const std::string & | filepath, |
const bool | lastdot | ||
) |
Strip trailing directory terminators.
Definition at line 118 of file path.cc.
References std::string::back(), std::string::resize(), and std::string::size().
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().
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().