Mail Archives: djgpp/1997/09/07/12:02:27
Karl Garrison (karlos AT eznet DOT net) wrote:
: Does anyone know how I can find out what directory a program was invoked
: from? I would perfer an ANSI-C method, but, failing that, a
: DJGPP-specific method would be acceptable. Specifically:
: I am making a HTML editor that will look for configuration files and the
: like in the same directory as the executable. I don't want to force the
: user to install in a particular directory, or make them add enviroment
: variables to their autoexec.bat.
This question seems to come up something like monthly in one news group
or another. Unfortunately, the short answer is that there IS no portable
way to do this. In fact depending on your platform there may be no
guaranteed correct way to do it at all even if you leave portability
out of the picture.
On MSDOS >= 3.x, argv[0] is generally the full pathname of the program
being run, which is either what you typed when you ran it, or based
on a PATH search if you did not specify the absolute location. On
earlier systems argv[0] may be empty (I'm not sure). When run on
Windoze I've no idea what argv[0] is. Unix platforms generally do
not put the full pathname in argv[0], so you've got to make assumptions.
One thing you can do is to search the PATH environment, but that for
sure is not robust (what if you have a program named FOO in the path,
but you instead ran a different program, from a different directory,
of the same name??)
Fred
--
---- Fred Smith -- fredex AT fcshome DOT stoneham DOT ma DOT us -- fred AT computrition DOT com ----
The eyes of the Lord are everywhere,
keeping watch on the wicked and the good.
----------------------------- Proverbs 15:3 (niv) -----------------------------
- Raw text -