LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to find the directory of a binary (in C) (https://www.linuxquestions.org/questions/programming-9/how-to-find-the-directory-of-a-binary-in-c-15928/)

DiscoStoo 03-09-2002 10:01 PM

How to find the directory of a binary (in C)
 
I've been working on this game, and I need to know exactly what directory the binary is in so I know where to find the graphics directory (which is relative to the binary). I figure there must be a function or something to do this, it's such a common thing. I can't just use argv[0] (which was suggested to me elsewhere) because if the user makes a SymLink argv[0] will give me the name and path of the SymLink, not the actual binary. Just let me know if I'm not making sense and I'll try to be more clear.

kervin 03-22-2002 03:29 PM

there's probably an easier way to do this, but have you tried using the stat(3) commands.

Read the stat man page for more info. You can test for a symlink, but I do not know how a hard link will affect you.

The simple option is to have the graphics library configured by the user or detected at build time or detected at run tim even.


All times are GMT -5. The time now is 03:21 AM.