2016-05-03 04:15:43 +00:00
|
|
|
// Directory utilities. This library contains functions for locating configuration directories, for
|
|
|
|
// testing if a command with a given name can be found in the PATH, and various other path-related
|
|
|
|
// issues.
|
2006-10-19 11:50:23 +00:00
|
|
|
#ifndef FISH_PATH_H
|
|
|
|
#define FISH_PATH_H
|
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
#include <stddef.h>
|
2016-04-21 06:00:54 +00:00
|
|
|
|
2015-07-25 15:14:25 +00:00
|
|
|
#include "common.h"
|
2012-07-21 05:11:05 +00:00
|
|
|
#include "env.h"
|
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// Return value for path_cdpath_get when locatied a rotten symlink.
|
2007-09-20 17:52:43 +00:00
|
|
|
#define EROTTEN 1
|
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// Returns the user configuration directory for fish. If the directory or one of its parents
|
|
|
|
/// doesn't exist, they are first created.
|
|
|
|
///
|
|
|
|
/// \param path The directory as an out param
|
|
|
|
/// \return whether the directory was returned successfully
|
2012-02-06 00:42:24 +00:00
|
|
|
bool path_get_config(wcstring &path);
|
2006-10-19 11:50:23 +00:00
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// Returns the user data directory for fish. If the directory or one of its parents doesn't exist,
|
|
|
|
/// they are first created.
|
|
|
|
///
|
|
|
|
/// Volatile files presumed to be local to the machine, such as the fish_history and all the
|
|
|
|
/// generated_completions, will be stored in this directory.
|
|
|
|
///
|
|
|
|
/// \param path The directory as an out param
|
|
|
|
/// \return whether the directory was returned successfully
|
2015-09-17 04:31:08 +00:00
|
|
|
bool path_get_data(wcstring &path);
|
|
|
|
|
2017-06-23 22:42:38 +00:00
|
|
|
/// Finds the full path of an executable.
|
2016-05-03 04:15:43 +00:00
|
|
|
///
|
2017-06-23 22:42:38 +00:00
|
|
|
/// Args:
|
|
|
|
/// cmd - The name of the executable.
|
|
|
|
/// output_or_NULL - If non-NULL, store the full path.
|
|
|
|
/// vars - The environment variables snapshot to use
|
|
|
|
///
|
|
|
|
/// Returns:
|
|
|
|
/// false if the command can not be found else true. The result
|
|
|
|
/// should be freed with free().
|
2016-05-03 04:15:43 +00:00
|
|
|
bool path_get_path(const wcstring &cmd, wcstring *output_or_NULL,
|
2012-07-21 05:11:05 +00:00
|
|
|
const env_vars_snapshot_t &vars = env_vars_snapshot_t::current());
|
2012-06-02 21:04:25 +00:00
|
|
|
|
2017-06-23 22:42:38 +00:00
|
|
|
/// Return all the paths that match the given command.
|
|
|
|
wcstring_list_t path_get_paths(const wcstring &cmd);
|
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// Returns the full path of the specified directory, using the CDPATH variable as a list of base
|
|
|
|
/// directories for relative paths. The returned string is allocated using halloc and the specified
|
|
|
|
/// context.
|
|
|
|
///
|
|
|
|
/// If no valid path is found, null is returned and errno is set to ENOTDIR if at least one such
|
|
|
|
/// path was found, but it did not point to a directory, EROTTEN if a arotten symbolic link was
|
|
|
|
/// found, or ENOENT if no file of the specified name was found. If both a rotten symlink and a file
|
|
|
|
/// are found, it is undefined which error status will be returned.
|
|
|
|
///
|
|
|
|
/// \param dir The name of the directory.
|
|
|
|
/// \param out_or_NULL If non-NULL, return the path to the resolved directory
|
|
|
|
/// \param wd The working directory, or NULL to use the default. The working directory should have a
|
|
|
|
/// slash appended at the end.
|
|
|
|
/// \param vars The environment variable snapshot to use (for the CDPATH variable)
|
|
|
|
/// \return 0 if the command can not be found, the path of the command otherwise. The path should be
|
|
|
|
/// free'd with free().
|
2017-08-06 01:22:49 +00:00
|
|
|
bool path_get_cdpath(const env_var_t &dir, wcstring *out_or_NULL, const wchar_t *wd = NULL,
|
2012-07-21 05:11:05 +00:00
|
|
|
const env_vars_snapshot_t &vars = env_vars_snapshot_t::current());
|
2012-02-08 19:48:51 +00:00
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// Returns whether the path can be used for an implicit cd command; if so, also returns the path by
|
|
|
|
/// reference (if desired). This requires it to start with one of the allowed prefixes (., .., ~)
|
|
|
|
/// and resolve to a directory.
|
|
|
|
bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path = NULL,
|
2012-07-21 05:11:05 +00:00
|
|
|
const wchar_t *wd = NULL,
|
|
|
|
const env_vars_snapshot_t &vars = env_vars_snapshot_t::current());
|
2006-10-19 11:50:23 +00:00
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// Remove double slashes and trailing slashes from a path, e.g. transform foo//bar/ into foo/bar.
|
|
|
|
/// The string is modified in-place.
|
2012-11-19 00:30:30 +00:00
|
|
|
void path_make_canonical(wcstring &path);
|
2007-05-10 19:11:28 +00:00
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// Check if two paths are equivalent, which means to ignore runs of multiple slashes (or trailing
|
|
|
|
/// slashes).
|
2013-08-28 01:26:22 +00:00
|
|
|
bool paths_are_equivalent(const wcstring &p1, const wcstring &p2);
|
|
|
|
|
2012-02-19 02:54:36 +00:00
|
|
|
bool path_is_valid(const wcstring &path, const wcstring &working_directory);
|
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// Returns whether the two paths refer to the same file.
|
2012-02-19 05:56:30 +00:00
|
|
|
bool paths_are_same_file(const wcstring &path1, const wcstring &path2);
|
|
|
|
|
2016-05-03 04:15:43 +00:00
|
|
|
/// If the given path looks like it's relative to the working directory, then prepend that working
|
|
|
|
/// directory. This operates on unescaped paths only (so a ~ means a literal ~).
|
2016-02-06 22:39:47 +00:00
|
|
|
wcstring path_apply_working_directory(const wcstring &path, const wcstring &working_directory);
|
|
|
|
|
2006-10-19 11:50:23 +00:00
|
|
|
#endif
|