Alex Rivera | Logout

Finding current executable's path without /proc/self/exe

Asked 2009-06-21T06:12:48.177
244

It seems to me that Linux has it easy with /proc/self/exe. But I'd like to know if there is a convenient way to find the current application's directory in C/C++ with cross-platform interfaces. I've seen some projects mucking around with argv[0], but it doesn't seem entirely reliable.

If you ever had to support, say, Mac OS X, which doesn't have /proc/, what would you have done? Use #ifdefs to isolate the platform-specific code (NSBundle, for example)? Or try to deduce the executable's path from argv[0], $PATH and whatnot, risking finding bugs in edge cases?

Edit
Report

1 Answer

0

You can use argv[0] and analyze the PATH environment variable. Look at : A sample of a program that can find itself

answered 2009-06-21T07:30:51.170

Your Answer