Is there an equivalent of GetModuleFileName() for Linux and how would I use it?

338 views Asked by At

I have a function on Windows to get the address of the module in buf:

GetModuleFileName(0, buf, buf_size);

I want to do the same on Linux (which I do not know much about). I found the function dladdr(X, &dlInfo) which seems to do the right thing. As I understand I get the name and other details (dli_sname, dli_saddr, dli_fname, ..) of X in dlInfo with this function.

But what is X? I know it it an address. But which one? How would I use this to obtain the same result as on Windows?

1

There are 1 answers

0
273K On

X is any interesting address, usually the address of an interesting module function. If you want to get the current module name, X can be an address of the caller

void X() {
  // ... 
  dladdr(X, &dlInfo);
  // or dladdr(&X, &dlInfo);
}