Say I have a command line C program which is currently executing, and I want to read a file or execute another binary in the same directory - how can I find out what directory that is?
Note that I'm not looking for the current working directory. The user may have invoked my original program in any of the following ways (and possibly others I don't know about).
- ../../program
- /home/matt/program
- PATH=$PATH:/home/matt program
Ideally I'm looking for something which will work on a unix system and windows via MinGW.