diff options
author | John Schmidt <john.schmidt.h@gmail.com> | 2014-03-31 00:27:50 +0200 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-01 08:08:07 -0300 |
commit | 2cb026c65c489743b3c5a4955dc9f276a18bd530 (patch) | |
tree | 6756dd52ed96413bb30abe3593faf3396edcf502 /src/path.c | |
parent | 7052b85192645086cdffd3baca56881f24cffe3f (diff) | |
download | rneovim-2cb026c65c489743b3c5a4955dc9f276a18bd530.tar.gz rneovim-2cb026c65c489743b3c5a4955dc9f276a18bd530.tar.bz2 rneovim-2cb026c65c489743b3c5a4955dc9f276a18bd530.zip |
Move fix_fname from buffer.c
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c index f7d64fba45..a83f4f3fd9 100644 --- a/src/path.c +++ b/src/path.c @@ -1620,3 +1620,45 @@ vim_FullName ( return retval; } +/* + * If fname is not a full path, make it a full path. + * Returns pointer to allocated memory (NULL for failure). + */ +char_u *fix_fname(char_u *fname) +{ + /* + * Force expanding the path always for Unix, because symbolic links may + * mess up the full path name, even though it starts with a '/'. + * Also expand when there is ".." in the file name, try to remove it, + * because "c:/src/../README" is equal to "c:/README". + * Similarly "c:/src//file" is equal to "c:/src/file". + * For MS-Windows also expand names like "longna~1" to "longname". + */ +#ifdef UNIX + return FullName_save(fname, TRUE); +#else + if (!vim_isAbsName(fname) + || strstr((char *)fname, "..") != NULL + || strstr((char *)fname, "//") != NULL +# ifdef BACKSLASH_IN_FILENAME + || strstr((char *)fname, "\\\\") != NULL +# endif + ) + return FullName_save(fname, FALSE); + + fname = vim_strsave(fname); + +# ifdef USE_FNAME_CASE +# ifdef USE_LONG_FNAME + if (USE_LONG_FNAME) +# endif + { + if (fname != NULL) + fname_case(fname, 0); /* set correct case for file name */ + } +# endif + + return fname; +#endif +} + |