|
|
Warp <war### [at] tagpovrayorg> wrote:
> Raffaele <nos### [at] nospamit> wrote:
> > i was sure argv[0] contained the path to the
> > current executable.
>
> Actually it's very rare for it to contain it.
>
> > What does you suggest to get the path to the current
> > executable? is there a c standard function to do so?
>
> There's no standard C or C++ function to do that. I'm not even sure
> there's a POSIX function to do that (although there might be, as POSIX
> as tons of things). I'm not even sure the OS is in any way required to
> keep/provide this information to the application.
>
> --
> - Warp
There are some ways you can still find it out.
Windows GetModuleFileName or something like that should return the path to the
executable file. On Linux I think there is either an environment variable or
symbolic link, something like /proc/self or _SELF or something. I've read
about it it's supposed to contain the path to the executable. I don't think it
is a POSIX standard but just used on Linux.
User supplied by environment variables or command-line options. If both are
used, a command-line option should probably take priority over the environment
variable.
Also a simple 'generic' auto detection can work reasonably well most of the time
If argv[0] is an absolute path, the use it.
If argv[0] is a relative path with path components, get the current working
directory and append argv[0].
If argv[0] is only a program name with no path components, on Windows use the
above method first. On Linux and after the above on Windows search the PATH
environment variable and for each item append argv[0] to see if it is found.
boost::filesystem may have something that already solves this
Post a reply to this message
|
|