mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
refactor: Windows tilde expansion followup (#29380)
Followup to #28515: Rename the static os_homedir() to os_uv_homedir() to emphasize that it is a wrapper around a libuv function. Add the function os_get_homedir() to os/env.c to return the cached homedir value as a const. Must be called after homedir is initialized or it fails. The difference between this function and the static os_uv_homedir() is that the latter gets the homedir from libuv and is used to initialize homedir in init_homedir(), while os_get_homedir() just returns homedir as a const if it's initialized and is public. Use the os_get_homedir() accessor for ~/ expansion on Windows to make the code more concise. Add a Windows section to main_spec.lua with tests for expanding ~/ and ~\ prefixes for files passed in on the command-line. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
@@ -1437,12 +1437,10 @@ scripterror:
|
||||
// On Windows expand "~\" or "~/" prefix in file names to profile directory.
|
||||
#ifdef MSWIN
|
||||
if (*p == '~' && (p[1] == '\\' || p[1] == '/')) {
|
||||
char *profile_dir = vim_getenv("HOME");
|
||||
size_t size = strlen(profile_dir) + strlen(p);
|
||||
size_t size = strlen(os_get_homedir()) + strlen(p);
|
||||
char *tilde_expanded = xmalloc(size);
|
||||
snprintf(tilde_expanded, size, "%s%s", profile_dir, p + 1);
|
||||
snprintf(tilde_expanded, size, "%s%s", os_get_homedir(), p + 1);
|
||||
xfree(p);
|
||||
xfree(profile_dir);
|
||||
p = tilde_expanded;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user