On Mon, Mar 06, 2017 at 11:02:34PM +0100, Bram Moolenaar wrote: > > Michal Grochmal wrote: > > > I may be doing a horrible misinterpretation of the subject, but here goes > > nothing. > > > > > > > > This just uses the existing logic in mch_can_exe to populate a > > > > > > buffer with the > > > > > > absolute path to the binary. The Windows code was already walking > > > > > > $PATH, so it seems pointless not to actually use the information. > > > > > > > > > > Quite a few years ago I was debugging a Vim that started up slowly. > > > > > It > > > > > turned out that walking through $PATH was the main cause for that. > > > > > So I > > > > > don't want to walk through $PATH when not really needed. > > > > > > > > Then it would be better to use platform-specific functionality to get > > > > the absolute path of the running binary instead of trying to re-use > > > > functionality that's intended for a different purpose. > > > > > > What platform-specific functionality is there? Perhaps Linux has a way > > > to get the actual path, instead of using argv[0]? > > > > Standard unix (as in SUSv3) does not have any specified way to determine the > > running binary. It really is a thing of comparing argv[0] whilst walking > > through PATH. And it has more sheanigans that you may at first think: > > there's > > the tilde (~) and all relative PATH. Just look at the GNU which source to > > see > > that madness: > > http://cvs.savannah.gnu.org/viewvc/which/which/which.c?revision=1.41&view=markup > > > > And then you can run `realpath(3)` to get the absolute path. > > > > On the other hand, on *Linux* you can use `readlink(3)` on `/proc/self/exe` > > and > > you get the absolute path of the running binary. FreeBSD (and a handful of > > other BSDs support the same interface too). > > > > i.e. > > > > #include <limits.h> > > #include <unistd.h> > > > > char buf[PATH_MAX+1]; > > ssize_t len; > > > > len = readlink("/proc/self/exe", buf, PATH_MAX); > > buf[len] = '\0' > > > > Should *always* work on Linux. > > Thanks, looks like that's what we need.
For what it's worth, I've started working on a PR to implement Windows, Linux, and FreeBSD/macOS support. The /proc trick only works on Linux, since that's a Linux-specific filesystem (although some of the BSDs may have an optional emulation layer). Cheers, -- James GPG Key: 4096R/91BF BF4D 6956 BD5D F7B7 2D23 DFE6 91AE 331B A3DB -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.