2006-10-19 11:50:23 +00:00
|
|
|
/** \file path.h
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FISH_PATH_H
|
|
|
|
#define FISH_PATH_H
|
|
|
|
|
2008-01-13 16:47:47 +00:00
|
|
|
/**
|
|
|
|
Return value for path_cdpath_get when locatied a rotten symlink
|
|
|
|
*/
|
2007-09-20 17:52:43 +00:00
|
|
|
#define EROTTEN 1
|
|
|
|
|
2006-10-19 11:50:23 +00:00
|
|
|
/**
|
|
|
|
Returns the user configuration directory for fish. If the directory
|
|
|
|
or one of it's parents doesn't exist, they are first created.
|
|
|
|
|
2012-02-10 02:43:36 +00:00
|
|
|
\param path The directory as an out param
|
|
|
|
\return whether the directory was returned successfully
|
2006-10-19 11:50:23 +00:00
|
|
|
*/
|
2012-02-06 00:42:24 +00:00
|
|
|
bool path_get_config(wcstring &path);
|
2006-10-19 11:50:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Finds the full path of an executable in a newly allocated string.
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2006-10-19 11:50:23 +00:00
|
|
|
\param cmd The name of the executable.
|
2012-01-30 07:22:42 +00:00
|
|
|
\return 0 if the command can not be found, the path of the command otherwise. The result should be freed with free().
|
2006-10-19 11:50:23 +00:00
|
|
|
*/
|
2012-01-30 07:22:42 +00:00
|
|
|
wchar_t *path_get_path( const wchar_t *cmd );
|
2006-10-19 11:50:23 +00:00
|
|
|
|
2011-12-27 03:18:46 +00:00
|
|
|
class env_vars;
|
2012-02-08 06:44:10 +00:00
|
|
|
bool path_get_path_string(const wcstring &cmd, wcstring &output);
|
2011-12-27 03:18:46 +00:00
|
|
|
bool path_get_path_string(const wcstring &cmd, wcstring &output, const env_vars &vars);
|
|
|
|
|
2006-10-19 11:50:23 +00:00
|
|
|
/**
|
2007-09-20 17:52: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.
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2007-09-20 17:52:43 +00:00
|
|
|
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.
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2006-10-19 11:50:23 +00:00
|
|
|
\param in The name of the directory.
|
2012-02-19 02:54:36 +00:00
|
|
|
\param wd The working directory, or NULL to use the default. The working directory should have a slash appended at the end.
|
2012-02-01 00:50:03 +00:00
|
|
|
\return 0 if the command can not be found, the path of the command otherwise. The path should be free'd with free().
|
2006-10-19 11:50:23 +00:00
|
|
|
*/
|
2012-02-08 19:48:51 +00:00
|
|
|
|
2012-02-19 02:54:36 +00:00
|
|
|
wchar_t *path_allocate_cdpath( const wchar_t *in, const wchar_t *wd = NULL);
|
|
|
|
bool path_can_get_cdpath(const wcstring &in, const wchar_t *wd = NULL);
|
2011-12-27 03:18:46 +00:00
|
|
|
bool path_get_cdpath_string(const wcstring &in, wcstring &out, const env_vars &vars);
|
2006-10-19 11:50:23 +00:00
|
|
|
|
2008-01-13 16:47:47 +00:00
|
|
|
/**
|
2012-02-08 05:23:12 +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.
|
2008-01-13 16:47:47 +00:00
|
|
|
*/
|
2012-02-08 05:23:12 +00:00
|
|
|
void path_make_canonical( wcstring &path );
|
2007-05-10 19:11:28 +00:00
|
|
|
|
2012-02-19 02:54:36 +00:00
|
|
|
bool path_is_valid(const wcstring &path, const wcstring &working_directory);
|
|
|
|
|
2012-02-19 05:56:30 +00:00
|
|
|
/** Returns whether the two paths refer to the same file */
|
|
|
|
bool paths_are_same_file(const wcstring &path1, const wcstring &path2);
|
|
|
|
|
2012-02-19 02:54:36 +00:00
|
|
|
wcstring get_working_directory(void);
|
2007-05-10 19:11:28 +00:00
|
|
|
|
2006-10-19 11:50:23 +00:00
|
|
|
#endif
|