POV-Ray : Newsgroups : povray.tools.general : all2pov released : Re: all2pov released Server Time
18 May 2024 06:59:11 EDT (-0400)
  Re: all2pov released  
From: Allen
Date: 13 Sep 2008 23:40:00
Message: <web.48cc86585ba87e918f162dfb0@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.