diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-08-04 20:59:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-04 20:59:51 -0400 |
commit | fe6ec757257dccee88f03deb767bc3a1d86c2351 (patch) | |
tree | 2fe2320671d74367fb1f1951f836cd457278472e /src/nvim/os/stdpaths.c | |
parent | d622e9c41635d9c0a65b8725e49ce476838d1aa2 (diff) | |
parent | 56fcabbd05b85388f2f5188fd1284bcff1ba67a2 (diff) | |
download | rneovim-fe6ec757257dccee88f03deb767bc3a1d86c2351.tar.gz rneovim-fe6ec757257dccee88f03deb767bc3a1d86c2351.tar.bz2 rneovim-fe6ec757257dccee88f03deb767bc3a1d86c2351.zip |
Merge #4964 from ZyX-I/no-xdg-expand
option: Do not expand options, obtained from XDG vars
Diffstat (limited to 'src/nvim/os/stdpaths.c')
-rw-r--r-- | src/nvim/os/stdpaths.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 81ceb919c4..10b3f4c091 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -100,18 +100,30 @@ char *stdpaths_user_conf_subpath(const char *fname) /// /// @param[in] fname New component of the path. /// @param[in] trailing_pathseps Amount of trailing path separators to add. +/// @param[in] escape_commas If true, all commas will be escaped. /// -/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}` +/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}`. char *stdpaths_user_data_subpath(const char *fname, - const size_t trailing_pathseps) + const size_t trailing_pathseps, + const bool escape_commas) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { char *ret = concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true); - if (trailing_pathseps) { - const size_t len = strlen(ret); - ret = xrealloc(ret, len + trailing_pathseps + 1); - memset(ret + len, PATHSEP, trailing_pathseps); - ret[len + trailing_pathseps] = NUL; + const size_t len = strlen(ret); + const size_t numcommas = (escape_commas ? memcnt(ret, ',', len) : 0); + if (numcommas || trailing_pathseps) { + ret = xrealloc(ret, len + trailing_pathseps + numcommas + 1); + for (size_t i = 0 ; i < len + numcommas ; i++) { + if (ret[i] == ',') { + memmove(ret + i + 1, ret + i, len - i + numcommas); + ret[i] = '\\'; + i++; + } + } + if (trailing_pathseps) { + memset(ret + len + numcommas, PATHSEP, trailing_pathseps); + } + ret[len + trailing_pathseps + numcommas] = NUL; } return ret; } |