From 47ffb905f363571072faefbd417938e7ff351a9f Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 12 Mar 2017 18:38:02 +0100 Subject: patch 8.0.0450: v:progpath is not reliably set Problem: v:progpath is not reliably set. Solution: Read /proc/self/exe if possible. (idea by Michal Grochmal) Also fixes missing #if. --- src/main.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index f96bca99d..aa5a1a20c 100644 --- a/src/main.c +++ b/src/main.c @@ -3539,16 +3539,27 @@ set_progpath(char_u *argv0) { char_u *val = argv0; +# ifdef HAVE_PROC_SELF_EXE + char buf[PATH_MAX + 1]; + ssize_t len; + + len = readlink("/proc/self/exe", buf, PATH_MAX); + if (len > 0) + { + buf[len] = NUL; + val = (char_u *)buf; + } +# else /* A relative path containing a "/" will become invalid when using ":cd", * turn it into a full path. * On MS-Windows "vim" should be expanded to "vim.exe", thus always do * this. */ -# ifdef WIN32 +# ifdef WIN32 char_u *path = NULL; if (mch_can_exe(argv0, &path, FALSE) && path != NULL) val = path; -# else +# else char_u buf[MAXPATHL]; if (!mch_isFullName(argv0)) -- cgit v1.2.1