Path manipulation functions. More...
#include <stdbool.h>
#include <stdio.h>
Go to the source code of this file.
Functions | |
bool | mutt_path_abbr_folder (struct Buffer *path, const char *folder) |
Create a folder abbreviation. | |
const char * | mutt_path_basename (const char *path) |
Find the last component for a pathname. | |
bool | mutt_path_canon (struct Buffer *path, const char *homedir, bool is_dir) |
Create the canonical version of a path. | |
char * | mutt_path_concat (char *dest, const char *dir, const char *file, size_t dlen) |
Join a directory name and a filename. | |
char * | mutt_path_dirname (const char *path) |
Return a path up to, but not including, the final '/'. | |
char * | mutt_path_escape (const char *src) |
Escapes single quotes in a path for a command string. | |
const char * | mutt_path_getcwd (struct Buffer *cwd) |
Get the current working directory. | |
bool | mutt_path_parent (struct Buffer *path) |
Find the parent of a path. | |
bool | mutt_path_pretty (struct Buffer *path, const char *homedir, bool is_dir) |
Tidy a filesystem path. | |
size_t | mutt_path_realpath (struct Buffer *path) |
Resolve path, unraveling symlinks. | |
bool | mutt_path_tidy (struct Buffer *path, bool is_dir) |
Remove unnecessary parts of a path. | |
bool | mutt_path_tidy_dotdot (char *buf) |
Remove dot-dot-slash from a path. | |
bool | mutt_path_tidy_slash (char *buf, bool is_dir) |
Remove unnecessary slashes and dots. | |
bool | mutt_path_tilde (struct Buffer *path, const char *homedir) |
Expand '~' in a path. | |
bool | mutt_path_to_absolute (char *path, const char *reference) |
Convert relative filepath to an absolute path. | |
Path manipulation functions.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file path.h.
bool mutt_path_abbr_folder | ( | struct Buffer * | path, |
const char * | folder | ||
) |
Create a folder abbreviation.
path | Path to modify |
folder | Base path for '=' substitution |
true | Path was abbreviated |
Abbreviate a path using '=' to represent the 'folder'. If the folder path is passed, it won't be abbreviated to just '='
Definition at line 494 of file path.c.
const char * mutt_path_basename | ( | const char * | path | ) |
Find the last component for a pathname.
path | String to be examined |
ptr | Part of pathname after last '/' character |
Definition at line 314 of file path.c.
bool mutt_path_canon | ( | struct Buffer * | path, |
const char * | homedir, | ||
bool | is_dir | ||
) |
Create the canonical version of a path.
path | Path to modify |
homedir | Home directory for '~' substitution |
is_dir | Is the path a directory? |
true | Success |
Remove unnecessary dots and slashes from a path and expand '~'.
Definition at line 280 of file path.c.
char * mutt_path_concat | ( | char * | dest, |
const char * | dir, | ||
const char * | file, | ||
size_t | dlen | ||
) |
Join a directory name and a filename.
dest | Buffer for the result |
dir | Directory name |
file | File name |
dlen | Length of buffer |
ptr | Destination buffer |
If both dir and file are supplied, they are separated with '/'. If either is missing, then the other will be copied exactly.
Definition at line 342 of file path.c.
char * mutt_path_dirname | ( | const char * | path | ) |
Return a path up to, but not including, the final '/'.
path | Path |
ptr | The directory containing p |
Unlike the IEEE Std 1003.1-2001 specification of dirname(3), this implementation does not modify its parameter, so callers need not manually copy their paths into a modifiable buffer prior to calling this function.
Definition at line 381 of file path.c.
char * mutt_path_escape | ( | const char * | src | ) |
Escapes single quotes in a path for a command string.
src | the path to escape |
ptr | The escaped string |
Definition at line 528 of file path.c.
const char * mutt_path_getcwd | ( | struct Buffer * | cwd | ) |
Get the current working directory.
cwd | Buffer for the result |
ptr | String of current working directory |
Definition at line 571 of file path.c.
bool mutt_path_parent | ( | struct Buffer * | path | ) |
Find the parent of a path.
path | Buffer for the result |
true | Success |
Definition at line 461 of file path.c.
bool mutt_path_pretty | ( | struct Buffer * | path, |
const char * | homedir, | ||
bool | is_dir | ||
) |
Tidy a filesystem path.
path | Path to modify |
homedir | Home directory for '~' substitution |
is_dir | Is the path a directory? |
true | Success |
Tidy a path and replace a home directory with '~'
Definition at line 188 of file path.c.
size_t mutt_path_realpath | ( | struct Buffer * | path | ) |
Resolve path, unraveling symlinks.
path | Buffer containing path |
num | String length of resolved path |
0 | Error, buf is not overwritten |
Resolve and overwrite the path in buf.
Definition at line 443 of file path.c.
bool mutt_path_tidy | ( | struct Buffer * | path, |
bool | is_dir | ||
) |
Remove unnecessary parts of a path.
[in,out] | path | Path to modify |
[in] | is_dir | Is the path a directory? |
true | Success |
Remove unnecessary dots and slashes from a path
Definition at line 165 of file path.c.
bool mutt_path_tidy_dotdot | ( | char * | buf | ) |
Remove dot-dot-slash from a path.
[in,out] | buf | Path to modify |
true | Success |
Collapse dot-dot patterns, like '/dir/../'
Definition at line 105 of file path.c.
bool mutt_path_tidy_slash | ( | char * | buf, |
bool | is_dir | ||
) |
Remove unnecessary slashes and dots.
[in,out] | buf | Path to modify |
[in] | is_dir | Should a trailing / be removed? |
true | Success |
Collapse repeated '//' and '/./'
Definition at line 54 of file path.c.
bool mutt_path_tilde | ( | struct Buffer * | path, |
const char * | homedir | ||
) |
Expand '~' in a path.
path | Path to modify |
homedir | Home directory for '~' substitution |
true | Success |
Behaviour:
~/dir
(~ expanded)~realuser/dir
(~realuser expanded)~nonuser/dir
(~nonuser not changed) Definition at line 226 of file path.c.
bool mutt_path_to_absolute | ( | char * | path, |
const char * | reference | ||
) |
Convert relative filepath to an absolute path.
path | Relative path |
reference | Absolute path that path is relative to |
true | Success |
false | Failure |
Use POSIX functions to convert a path to absolute, relatively to another path
Definition at line 402 of file path.c.