Advertisement

getexename(): Get the actual name of current executable

Started by April 30, 2003 10:34 AM
-1 comments, last by Prefect 21 years, 6 months ago
When I distribute a game, I want it to be simple for the user: just untar an archive into a single directory, run the executable inside that directory. The thing that troubled me was how to find out where the game data files are once the game is running, and I thought I''d share my findings. The two obious, well-known possibilities are: Use paths relative to the current working directory. Unfortunately, the user has to set the CWD explicitly, and this usually fails when the game is started from a GUI. Second possibility is to use argv[0] as a basis, but that might now work, especially when symlinks are involved. I searched around a bit and noticed /proc//exe, a link that points to the actual executable filename of the program running in process . This link cannot be fooled by symlinks, scripts or messing with the args array when calling execve(). So I''ve written a small function to read out that link, you can find it here. Unfortunately, I don''t think it''s too portable to anything that''s not Linux, but it can serve as a nice fallback when the other two methods fail. cu, Prefect
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement