diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-05-17 03:23:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-17 03:23:34 +0200 |
commit | 060ce0e0bc0e5b332f296246e389a4292a0f1d9b (patch) | |
tree | 5d0d65447ada2ccb26b0a4140ccbfb1325c5efbc | |
parent | 96ede7c5679bf3ef9e318c663965978a87842402 (diff) | |
download | rneovim-060ce0e0bc0e5b332f296246e389a4292a0f1d9b.tar.gz rneovim-060ce0e0bc0e5b332f296246e389a4292a0f1d9b.tar.bz2 rneovim-060ce0e0bc0e5b332f296246e389a4292a0f1d9b.zip |
startup: init v:progpath before calling vim_getenv (#6755)
-rw-r--r-- | src/nvim/main.c | 21 | ||||
-rw-r--r-- | src/nvim/os/env.c | 4 |
2 files changed, 14 insertions, 11 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 3831f0ac6b..a37fefc648 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -124,7 +124,7 @@ typedef struct { Loop main_loop; -static char *argv0; +static char *argv0 = NULL; // Error messages static const char *err_arg_missing = N_("Argument missing after"); @@ -179,11 +179,9 @@ void early_init(void) log_init(); fs_init(); handle_init(); - eval_init(); // init global variables - - // Init the table of Normal mode commands. - init_normal_cmds(); + init_path(argv0 ? argv0 : "nvim"); + init_normal_cmds(); // Init the table of Normal mode commands. #if defined(HAVE_LOCALE_H) // Setup to use the current locale (for ctype() and many other things). @@ -221,7 +219,7 @@ int nvim_main(int argc, char **argv) int main(int argc, char **argv) #endif { - argv0 = (char *)path_tail((char_u *)argv[0]); + argv0 = argv[0]; char_u *fname = NULL; // file name from command line mparm_T params; // various parameters passed between @@ -241,8 +239,6 @@ int main(int argc, char **argv) // Check if we have an interactive window. check_and_set_isatty(¶ms); - init_path(argv[0]); - event_init(); /* * Process the command line arguments. File names are put in the global @@ -1217,7 +1213,8 @@ static void check_and_set_isatty(mparm_T *paramp) } // Sets v:progname and v:progpath. Also modifies $PATH on Windows. -static void init_path(char *exename) +static void init_path(const char *exename) + FUNC_ATTR_NONNULL_ALL { char exepath[MAXPATHL] = { 0 }; size_t exepathlen = MAXPATHL; @@ -1834,9 +1831,11 @@ static bool file_owned(const char *fname) /// @param str string to append to the primary error message, or NULL static void mainerr(const char *errstr, const char *str) { + char *prgname = (char *)path_tail((char_u *)argv0); + signal_stop(); // kill us with CTRL-C here, if you like - mch_errmsg(argv0); + mch_errmsg(prgname); mch_errmsg(": "); mch_errmsg(_(errstr)); if (str != NULL) { @@ -1845,7 +1844,7 @@ static void mainerr(const char *errstr, const char *str) mch_errmsg("\""); } mch_errmsg(_("\nMore info with \"")); - mch_errmsg(argv0); + mch_errmsg(prgname); mch_errmsg(" -h\"\n"); mch_exit(1); diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index a7d1037cfc..713fa5ea96 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -600,6 +600,10 @@ const void *vim_env_iter_rev(const char delim, /// @param name Environment variable to expand char *vim_getenv(const char *name) { + // init_path() should have been called before now. + assert(get_vim_var_str(VV_PROGPATH) + && get_vim_var_str(VV_PROGPATH)[0] != NUL); + const char *kos_env_path = os_getenv(name); if (kos_env_path != NULL) { return xstrdup(kos_env_path); |