Jump to content
  • Advertisement
Sign in to follow this  
quaker

The Magic Function!

This topic is 4436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi What's the system function that returns the direcotry/path of the running process image file, not the current location where the process started? In both Windows and Linux? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
There is no standard way, but this works on current versions of Linux (not portable to other unixes as fas as I know):

char buf[4096];
retval = readlink("/proc/self/exe", buf, sizeof(buf)));
if (retval != -1)
buf[retval] = '\0';
else
my_error_handler();

See the manual entry for readlink if you want details on possible return values, etc. (the man page says the buffer is not nul-terminated on return, which seems kind of odd, that's why it's added manually in the code above, if you were wondering).

As for Windows, I have no idea.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry, for got to mention - that will return the name and path of the executable image itself, you will have to strip the last component off if you want the path.

Also, theree is one closing parenthesis too much in the example code above.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!