mathieu said:
I'd like to be able to get the path to the current working executable
(from inside it).
Technically this is easy, I simply have to collapse: getcwd and
argv[0]
Note that getcwd() is not defined by the C standard. It is defined by
POSIX, which suggests that comp.unix.programmer might be a better
place for your question. <OT>And in Unix systems, argv[0] doesn't
*necessarily* hold valid information; it can be set by the
caller. said:
Well argv[0] comes in a little late, I'd like to have access to this
information before the 'main' function is called. Is there a way to
get the path to an executable (from inside it) ?
Let me guess, you want to do something like:
const char *const executable_name = <something>;
outside any function. There's certainly no standard C way to do that
(unless you use a macro whose value is specified when you compile,
but then the value won't change if the executable is moved somewhere
else). And I don't think you'll find any system-specific way to do
it either, particularly since a static initializer must be constant
-- but you'll have to ask in a system-specific forum to be sure.
(Strictly speaking, specifying a macro value at compilation time,
such as with a "-DFOO=BAR" compiler option, is also non-standard,
but you could do the same thing by updating a header file containing
a #define just before compiling.)
If you want this in a static variable at file scope (a "global"),
then your best bet is probably to declare the variable and assign
a value to it at the beginning of main().