On Sunday, July 7, 2024 1:19:14 AM GMT+2 Andrew Randrianasulu wrote:
> Another part of our unportability related to way we use /proc for getting
> our own executable name/path. Is there more portable way to do so?
The first question is always, why would you want to know that. At least
in pkgsrc we believe in actually encoding the correct prefix and not
depending on magic "where am I" logic, which fails surprisingly often.
If you really need to, there is the hierarchy of:
- platform specific magic like /proc/self/exe
- check if argv[0] is a full path and use it (it most likely is)
- if it isn't: resolve argv[0] via PATH
If it fails, you lost.
Joerg