Macros | Functions
path.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/path.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/file_search.h"
#include "nvim/garray.h"
#include "nvim/memfile.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
#include "nvim/os_unix.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/tag.h"
#include "nvim/types.h"
#include "nvim/os/input.h"
#include "nvim/window.h"

Macros

#define URL_SLASH   1 /* path_is_url() has found "://" */
 
#define URL_BACKSLASH   2 /* path_is_url() has found ":\\" */
 
#define MAXSUFLEN   30
 

Functions

FileComparison path_full_compare (char_u *const s1, char_u *const s2, const bool checkname)
 
char_upath_tail (const char_u *fname) FUNC_ATTR_NONNULL_RET
 
char_upath_tail_with_sep (char_u *fname)
 
const char_uinvocation_path_tail (const char_u *invocation, size_t *len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_ARG(1)
 
const char * path_next_component (const char *fname)
 
char_uget_past_head (const char_u *path)
 
int vim_ispathsep (int c)
 
int vim_ispathsep_nocolon (int c)
 
int vim_ispathlistsep (int c)
 
char_ushorten_dir (char_u *str)
 
bool dir_of_file_exists (char_u *fname)
 
int path_fnamecmp (const char *fname1, const char *fname2) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
int path_fnamencmp (const char *const fname1, const char *const fname2, size_t len) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
 
char * concat_fnames (const char *fname1, const char *fname2, bool sep) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
 
char * concat_fnames_realloc (char *fname1, const char *fname2, bool sep) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
 
bool add_pathsep (char *p) FUNC_ATTR_NONNULL_ALL
 
char * FullName_save (const char *fname, bool force) FUNC_ATTR_MALLOC
 
char_usave_abs_path (const char_u *name) FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
 
bool path_has_wildcard (const char_u *p) FUNC_ATTR_NONNULL_ALL
 
bool path_has_exp_wildcard (const char_u *p) FUNC_ATTR_NONNULL_ALL
 
const char * gettail_dir (const char *const fname) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
 
int gen_expand_wildcards (int num_pat, char_u **pat, int *num_file, char_u ***file, int flags)
 
void addfile (garray_T *gap, char_u *f, int flags)
 
void simplify_filename (char_u *filename)
 
char_ufind_file_name_in_path (char_u *ptr, size_t len, int options, long count, char_u *rel_fname)
 
int path_is_url (const char *p)
 
int path_with_url (const char *fname)
 
bool vim_isAbsName (char_u *name)
 
int vim_FullName (const char *fname, char *buf, size_t len, bool force) FUNC_ATTR_NONNULL_ARG(2)
 
char * fix_fname (const char *fname)
 
void path_fix_case (char_u *name) FUNC_ATTR_NONNULL_ALL
 
int after_pathsep (const char *b, const char *p)
 
bool same_directory (char_u *f1, char_u *f2)
 
int pathcmp (const char *p, const char *q, int maxlen)
 
char_upath_try_shorten_fname (char_u *full_path)
 
char_upath_shorten_fname (char_u *full_path, char_u *dir_name)
 
int expand_wildcards_eval (char_u **pat, int *num_file, char_u ***file, int flags)
 
int expand_wildcards (int num_pat, char_u **pat, int *num_files, char_u ***files, int flags)
 
int match_suffix (char_u *fname)
 
int path_full_dir_name (char *directory, char *buffer, size_t len)
 
int append_path (char *path, const char *to_append, size_t max_len)
 
int path_is_absolute (const char_u *fname)
 
void path_guess_exepath (const char *argv0, char *buf, size_t bufsize) FUNC_ATTR_NONNULL_ALL
 

Macro Definition Documentation

#define MAXSUFLEN   30
#define URL_BACKSLASH   2 /* path_is_url() has found ":\\" */
#define URL_SLASH   1 /* path_is_url() has found "://" */

Function Documentation

bool add_pathsep ( char *  p)

Adds a path separator to a filename, unless it already ends in one.

Returns
true if the path separator was added or already existed. false if the filename is too long.
void addfile ( garray_T gap,
char_u f,
int  flags 
)
int after_pathsep ( const char *  b,
const char *  p 
)
int append_path ( char *  path,
const char *  to_append,
size_t  max_len 
)
char* concat_fnames ( const char *  fname1,
const char *  fname2,
bool  sep 
)

Concatenate file names fname1 and fname2 into allocated memory.

Only add a '/' or '\' when 'sep' is true and it is necessary.

Parameters
fname1is the first part of the path or filename
fname2is the second half of the path or filename
sepis a flag to indicate a path separator should be added if necessary
Returns
[allocated] Concatenation of fname1 and fname2.
char* concat_fnames_realloc ( char *  fname1,
const char *  fname2,
bool  sep 
)

Concatenate file names fname1 and fname2

Like concat_fnames(), but in place of allocating new memory it reallocates fname1. For this reason fname1 must be allocated with xmalloc, and can no longer be used after running concat_fnames_realloc.

Parameters
fname1is the first part of the path or filename
fname2is the second half of the path or filename
sepis a flag to indicate a path separator should be added if necessary
Returns
[allocated] Concatenation of fname1 and fname2.
bool dir_of_file_exists ( char_u fname)
int expand_wildcards ( int  num_pat,
char_u **  pat,
int *  num_files,
char_u ***  files,
int  flags 
)

Expand wildcards. Calls gen_expand_wildcards() and removes files matching 'wildignore'.

Parameters
num_patis number of input patterns.
patis an array of pointers to input patterns.
[out]num_fileis pointer to number of matched file names.
[out]fileis pointer to array of pointers to matched file names.
flagsis a combination of EW_* flags.
Returns
OK when *file is set to allocated array of matches and *num_file (can be zero) to the number of matches. If FAIL is returned, *num_file and *file are either unchanged or *num_file is set to 0 and *file is set to NULL or points to "".
int expand_wildcards_eval ( char_u **  pat,
int *  num_file,
char_u ***  file,
int  flags 
)

Invoke expand_wildcards() for one pattern

One should expand items like "%:h" before the expansion.

Parameters
[in]patPointer to the input pattern.
[out]num_fileResulting number of files.
[out]fileArray of resulting files.
[in]flagsFlags passed to expand_wildcards().
Returns
OK when *file is set to allocated array of matches and *num_file(can be zero) to the number of matches. If FAIL is returned, *num_file and *file are either unchanged or *num_file is set to 0 and *file is set to NULL or points to "".
char_u* find_file_name_in_path ( char_u ptr,
size_t  len,
int  options,
long  count,
char_u rel_fname 
)
char* fix_fname ( const char *  fname)

Get the full resolved path for fname

Even filenames that appear to be absolute based on starting from the root may have relative paths (like dir/../subdir) or symlinks embedded, or even extra separators (//). This function addresses those possibilities, returning a resolved absolute path. For MS-Windows, this also expands names like "longna~1".

Parameters
fnameis the filename to expand
Returns
[allocated] Full path (NULL for failure).
char* FullName_save ( const char *  fname,
bool  force 
)

Get an allocated copy of the full path to a file.

Parameters
fnameis the filename to save
forceis a flag to expand fname even if it looks absolute
Returns
[allocated] Copy of absolute path to fname or NULL when fname is NULL.
int gen_expand_wildcards ( int  num_pat,
char_u **  pat,
int *  num_file,
char_u ***  file,
int  flags 
)

Generic wildcard expansion code.

Characters in pat that should not be expanded must be preceded with a backslash. E.g., "/path\ with\ spaces/my\*star*".

Parameters
num_patis number of input patterns.
patis an array of pointers to input patterns.
[out]num_fileis pointer to number of matched file names.
[out]fileis pointer to array of pointers to matched file names.
flagsis a combination of EW_* flags used in expand_wildcards().
Returns
OK when some files were found. *num_file is set to the number of matches, *file to the allocated array of matches. Call FreeWild() later. If FAIL is returned, *num_file and *file are either unchanged or *num_file is set to 0 and *file is set to NULL or points to "".
char_u* get_past_head ( const char_u path)

Get a pointer to one character past the head of a path name. Unix: after "/"; Win: after "c:\" If there is no head, path is returned.

const char* gettail_dir ( const char *const  fname)

Find end of the directory name

Parameters
[in]fnameFile name to process.
Returns
end of the directory name, on the first path separator:
       "/path/file", "/path/dir/", "/path//dir", "/file"
             ^             ^             ^        ^  
const char_u* invocation_path_tail ( const char_u invocation,
size_t *  len 
)

Finds the path tail (or executable) in an invocation.

Parameters
[in]invocationA program invocation in the form: "path/to/exe [args]".
[out]lenStores the length of the executable name.
Postcondition
if len is not null, stores the length of the executable name.
Returns
The position of the last path separator + 1.
int match_suffix ( char_u fname)
void path_fix_case ( char_u name)

Set the case of the file name, if it already exists. This will cause the file name to remain exactly the same. Only required for file systems where case is ignored and preserved.

int path_fnamecmp ( const char *  fname1,
const char *  fname2 
)

Compare two file names

Handles '/' and '\' correctly and deals with &fileignorecase option.

Parameters
[in]fname1First file name.
[in]fname2Second file name.
Returns
0 if they are equal, non-zero otherwise.
int path_fnamencmp ( const char *const  fname1,
const char *const  fname2,
size_t  len 
)

Compare two file names

Handles '/' and '\' correctly and deals with &fileignorecase option.

Parameters
[in]fname1First file name.
[in]fname2Second file name.
[in]lenCompare at most len bytes.
Returns
0 if they are equal, non-zero otherwise.
FileComparison path_full_compare ( char_u *const  s1,
char_u *const  s2,
const bool  checkname 
)

Compare two file names.

Parameters
s1First file name. Environment variables in this name will be expanded.
s2Second file name.
checknameWhen both files don't exist, only compare their names.
Returns
Enum of type FileComparison.
See also
FileComparison.
int path_full_dir_name ( char *  directory,
char *  buffer,
size_t  len 
)

Get the absolute name of the given relative directory.

Parameters
directoryDirectory name, relative to current directory.
Returns
FAIL for failure, OK for success.
void path_guess_exepath ( const char *  argv0,
char *  buf,
size_t  bufsize 
)

Builds a full path from an invocation name argv0, based on heuristics.

Parameters
[in]argv0Name by which Nvim was invoked.
[out]bufGuessed full path to argv0.
[in]bufsizeSize of buf.
See also
os_exepath
bool path_has_exp_wildcard ( const char_u p)

Checks if a path has a character path_expand can expand.

Parameters
pThe path to expand.
Returns
Unix: True if it contains one of *?[{.
Windows: True if it contains one of *?[.
bool path_has_wildcard ( const char_u p)

Checks if a path has a wildcard character including '~', unless at the end.

Parameters
pThe path to expand.
Returns
Unix: True if it contains one of "?[{`'$".
Windows: True if it contains one of "*?$[".
int path_is_absolute ( const char_u fname)

Check if file fname is a full (absolute) path.

Returns
TRUE if "fname" is absolute.
int path_is_url ( const char *  p)
const char* path_next_component ( const char *  fname)

Get the next path component of a path name.

Parameters
fnameA file path. (Must be != NULL.)
Returns
Pointer to first found path separator + 1. An empty string, if fname doesn't contain a path separator,
char_u* path_shorten_fname ( char_u full_path,
char_u dir_name 
)

Try to find a shortname by comparing the fullname with dir_name.

Parameters
full_pathThe full path of the file.
dir_nameThe directory to shorten relative to.
Returns
  • Pointer into full_path if shortened.
  • NULL if no shorter name is possible.
char_u* path_tail ( const char_u fname)

Gets the tail (i.e., the filename segment) of a path fname.

Returns
pointer just past the last path separator (empty string, if fname ends in a slash), or empty string if fname is NULL.
char_u* path_tail_with_sep ( char_u fname)

Get pointer to tail of "fname", including path separators.

Takes care of "c:/" and "//". That means path_tail_with_sep("dir///file.txt") will return a pointer to "///file.txt".

Parameters
fnameA file path. (Must be != NULL.)
Returns
  • Pointer to the last path separator of fname, if there is any.
  • fname if it contains no path separator.
  • Never NULL.
char_u* path_try_shorten_fname ( char_u full_path)

Try to find a shortname by comparing the fullname with the current directory.

Parameters
full_pathThe full path of the file.
Returns
  • Pointer into full_path if shortened.
  • full_path unchanged if no shorter name is possible.
  • NULL if full_path is NULL.
int path_with_url ( const char *  fname)

Check if "fname" starts with "name://". Return URL_SLASH if it does.

Parameters
fnameis the filename to test
Returns
URL_BACKSLASH for "name:\\", zero otherwise.
int pathcmp ( const char *  p,
const char *  q,
int  maxlen 
)
bool same_directory ( char_u f1,
char_u f2 
)
char_u* save_abs_path ( const char_u name)

Saves the absolute path.

Parameters
nameAn absolute or relative path.
Returns
The absolute path of name.
char_u* shorten_dir ( char_u str)
void simplify_filename ( char_u filename)
int vim_FullName ( const char *  fname,
char *  buf,
size_t  len,
bool  force 
)

Save absolute file name to "buf[len]".

Parameters
fnamefilename to evaluate
[out]bufcontains fname absolute path, or:
  • truncated fname if longer than len
  • unmodified fname if absolute path fails or is a URL
lenlength of buf
forceflag to force expanding even if the path is absolute
Returns
FAIL for failure, OK otherwise
bool vim_isAbsName ( char_u name)
int vim_ispathlistsep ( int  c)
int vim_ispathsep ( int  c)
int vim_ispathsep_nocolon ( int  c)